Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. import net.sourceforge.jwbf.mediawiki.bots.*;
  2. import net.sourceforge.jwbf.core.contentRep.Article;
  3. import com.mythicscape.batclient.interfaces.*;
  4. import java.text.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import javax.swing.*;
  8. import java.util.ArrayList;
  9.  
  10. public static final String charname = "Tugmeno";
  11. public static final String wiki_user = "Tugmeno";
  12. public static final String password = "use your own!";
  13.  
  14. /*
  15. * TODO: move login and maybe lookup/save in it's own thread
  16. * clean up the code a bit..
  17. *
  18. *
  19. */
  20.  
  21.  
  22. public static BatWindow win;
  23. public static JTextArea textArea;
  24. public static Article article;
  25.  
  26. public static String mob;
  27. public static int state;
  28. public static String desc = "";
  29. public static String eq = "";
  30. public static String area = "";
  31.  
  32. SCRIPT_NAME = "wiki2";
  33.  
  34. MediaWikiBot bot;
  35.  
  36. void bootup()
  37. {
  38. triggerManager.newTrigger(SCRIPT_NAME + "_scan",
  39. "^([a-zA-Z -]*) is in excellent shape \\(100%\\)\\.$",
  40. "$" + SCRIPT_NAME + ".scan",
  41. false,false,false,null,Font.PLAIN);
  42.  
  43. bot = new MediaWikiBot("http://batwiki.wx.fi/w/");
  44. bot.login(wiki_user, password);
  45.  
  46. win = clientGUI.createBatWindow("window",500,180,250,320);
  47. win.removeTabAt(0);
  48.  
  49. BatPanel panel = new BatPanel();
  50. panel.setLayout(new BorderLayout());
  51.  
  52. textArea = new JTextArea();
  53. JScrollPane scrollPane = new JScrollPane(textArea);
  54. panel.add(scrollPane,BorderLayout.CENTER);
  55.  
  56. win.newTab(SCRIPT_NAME, panel);
  57. JButton button = new JButton("save");
  58. button.addActionListener(new ActionListener() {
  59. public void actionPerformed(ActionEvent e)
  60. {
  61. save();
  62. }
  63. });
  64.  
  65.  
  66.  
  67. panel.add(button,BorderLayout.PAGE_END);
  68.  
  69. }
  70.  
  71. public void scan()
  72. {
  73. if(state == 1)
  74. {
  75. textArea.setText(textArea.getText().replaceFirst("\\| name = ","| name = " + vars.get(1)));
  76. state++;
  77. clientGUI.doCommand("emote scan..;l " + vars.get(1)+";emote ..end");
  78. }
  79. }
  80.  
  81.  
  82. public ParsedResult trigger() {
  83. String line = argument.getStrippedText();
  84. line = line.substring(0,line.length()-1);
  85.  
  86.  
  87. //removed state 1 check
  88. ArrayList/*<ParsedAttribute>*/ attrs = argument.getAttributes();
  89. //System.out.println(attrs.get(0).getAttribute().getName());
  90. //System.out.println(attrs.get(0).getAttribute().readResolve().getClass());
  91. //System.out.println(attrs.get(0).getValue().toString());
  92. if(!line.startsWith("'") && (attrs.get(0).getValue().equals(Color.GREEN) || attrs.get(0).getValue().equals(Color.RED)))
  93. {
  94. //System.out.println("greee!!!!");
  95. mob = line;
  96. }
  97. if (state == 2)
  98. {
  99. if(line.equals("*" + charname + " scan.."))
  100. {
  101. state++;
  102. }
  103. } else if (state == 3)
  104. {
  105. System.out.println(line);
  106.  
  107. if(line.endsWith("is in excellent shape."))
  108. {
  109. textArea.setText(textArea.getText().replaceFirst("\\| description = ","| description = " + desc));
  110. desc = "";
  111. state++;
  112. }
  113. else {
  114. if(desc.equals(""))
  115. desc = line;
  116. else
  117. desc += " " + line;
  118. }
  119. } else if (state == 4)
  120. {// eq check..
  121. if(line.equals("*" + charname + " ..end.")) //mob has no eq
  122. {
  123. state = 0;
  124. textArea.setText(textArea.getText().replaceFirst("\\| eqs = ","| eqs = none"));
  125. eq = "";
  126. } else if (line.endsWith("equipment:"))
  127. state++;
  128.  
  129. } else if (state == 5)
  130. {
  131. if(line.equals("*" + charname + " ..end."))
  132. {
  133. state = 0; //?? we finished?
  134. if(eq.equals(""))
  135. eq = "none";
  136. textArea.setText(textArea.getText().replaceFirst("\\| eqs = ","| eqs = " + eq));
  137. eq = "";
  138. } else {
  139. if(!eq.equals(""))
  140. eq += "\n\n";
  141. eq += line;
  142. }
  143. }
  144.  
  145. return argument;
  146. }
  147.  
  148. void run(){
  149. if(argument == null || ("".equals(argument))) argument = mob;
  150.  
  151. if(bot.isLoggedIn())
  152. System.out.println("logged in");
  153.  
  154. article = bot.readContent(argument);
  155.  
  156. textArea.setText(article.getText());
  157.  
  158. win.setVisible(true);
  159. }
  160.  
  161. void create(){
  162. if(mob == null) return;
  163.  
  164. clientGUI.printText("general","## active mob is:" + mob +"\n");
  165. article = bot.readContent(mob);
  166. if(article.getText().equals(""))
  167. {
  168. clientGUI.printText("general","## creating new..\n");
  169. textArea.setText(
  170. "{{ NPC \n"
  171. +"| name = \n"
  172. +"| description = \n"
  173. +"| eqs = \n"
  174. +"| race = \n"
  175. +"| undead = \n"
  176. +"| alignment = \n"
  177. +"| area = "+ area + "\n"
  178. +"| spell = \n"
  179. //+"| spell# = \n"
  180. +"| skill = \n"
  181. //+"| skill# = \n"
  182. +"| exp = \n"
  183. +"| GAP = \n"
  184. +"| PAP = \n"
  185. //+"| kerbholz = \n"
  186. +"| other = \n"
  187. +"}}"
  188. );
  189. //TODO: name scan
  190. state = 1;
  191. } else {
  192. textArea.setText(article.getText());
  193. }
  194. win.setVisible(true);
  195. }
  196.  
  197. void state()
  198. {
  199. if(argument != null)
  200. state = Integer.parseInt(argument);
  201.  
  202. clientGUI.printText("general","## we are in state: " + state + "\n");
  203. }
  204.  
  205. void area ()
  206. {
  207. area = argument;
  208. }
  209.  
  210. void save ()
  211. {
  212. System.out.println("save..");
  213. article.setText(textArea.getText());
  214. article.save("edit from batclient");
  215. System.out.println("done");
  216. clientGUI.printText("general","## saved\n");
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement