Skip to content

Commit

Permalink
Added a ::wiki command. (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
15rtrujillo authored Dec 24, 2023
1 parent 3f133f5 commit 96ebe1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/Client/WikiURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public static String getURL() throws IllegalArgumentException {
return url.append(utm_source).toString();
}

public static String getURL(String... query) throws IllegalArgumentException {
StringBuilder url = new StringBuilder(wikiPrefix);
for (String q : query) {
url.append(q);
url.append("+");
}
url.setLength(url.length() - 1);
return url.append(utm_source).toString();
}

public static boolean shouldConsume() {
return nextClickIsLookup && !MouseHandler.rightClick;
}
Expand Down
23 changes: 16 additions & 7 deletions src/Game/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import Client.Speedrun;
import Client.TwitchIRC;
import Client.Util;
import Client.WikiURL;
import Client.WorldMapWindow;
import Replay.game.constants.Game.ItemAction;
import java.applet.Applet;
Expand All @@ -52,13 +53,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JOptionPane;
Expand Down Expand Up @@ -2186,6 +2181,20 @@ private static String processClientChatCommand(String line) {
+ ".";
}
}
} else if (command.startsWith("wiki")) {
final String[] args = command.split(" ");
final String[] query = Arrays.copyOfRange(command.split(" "), 1, args.length);
if (System.currentTimeMillis() - WikiURL.lastLookupTime > WikiURL.cooldownTimer) {
String wikiURL = WikiURL.getURL(query);
WikiURL.lastLookupTime = System.currentTimeMillis();
Util.openLinkInBrowser(wikiURL);
} else {
Client.displayMessage(
String.format(
"@lre@Please wait %1d seconds between wiki queries",
WikiURL.cooldownTimer / 1000),
Client.CHAT_NONE);
}
}

for (int skill = 0; skill < NUM_SKILLS; skill++) {
Expand Down

0 comments on commit 96ebe1a

Please sign in to comment.