// To use it copy it in your scripts folder as wiki.bcs and then in the client // do $wiki Burglefloogah or what ever you want to look up. // If you encounter any problems with the script please tell me and it would be // nice to see more of the non eq mobs on batwiki. SCRIPT_NAME = "wiki"; import java.util.regex.*; Pattern title = Pattern.compile("\\s*\\[title\\] => (.*)$"); Pattern missing = Pattern.compile("\\s*\\[missing\\] => .*$"); print(String text) { clientGUI.printText("general","## ","41A317"); clientGUI.printText("general", text +"\n"); } run() { if (argument == null || ("".equals(argument))) return; String search = argument.replace(' ','_'); int state = 0; try { print("search for " + search); URL url = new URL("http://batwiki.wx.fi/w/api.php?action=query&titles=" + search +"&prop=revisions&rvprop=content&format=txt&redirects"); InputStream is = url.openStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String inputLine; while ((inputLine = in.readLine()) != null) { switch(state) { case 0: Matcher m = title.matcher(inputLine); if(m.matches()) { print(m.group(1)); state++; } break; case 1: if(inputLine.startsWith("|")) { print(inputLine); state++; } else if ((missing.matcher(inputLine)).matches()) { print("was sadly not found on the wiki"); } break; case 2: if(inputLine.startsWith("}}")) state++; else print(inputLine.replaceAll("\\[\\[","").replaceAll("\\]\\]","")); break; } //DEBUG //System.out.println(inputLine); } in.close(); } catch (Exception e) { print("and we fail.."); e.printStackTrace(); } }