Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.sourceforge.jwbf.mediawiki.bots.*;
- import net.sourceforge.jwbf.core.contentRep.Article;
- import com.mythicscape.batclient.interfaces.*;
- import java.text.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.ArrayList;
- public static final String charname = "Tugmeno";
- public static final String wiki_user = "Tugmeno";
- public static final String password = "use your own!";
- /*
- * TODO: move login and maybe lookup/save in it's own thread
- * clean up the code a bit..
- *
- *
- */
- public static BatWindow win;
- public static JTextArea textArea;
- public static Article article;
- public static String mob;
- public static int state;
- public static String desc = "";
- public static String eq = "";
- public static String area = "";
- SCRIPT_NAME = "wiki2";
- MediaWikiBot bot;
- void bootup()
- {
- triggerManager.newTrigger(SCRIPT_NAME + "_scan",
- "^([a-zA-Z -]*) is in excellent shape \\(100%\\)\\.$",
- "$" + SCRIPT_NAME + ".scan",
- false,false,false,null,Font.PLAIN);
- bot = new MediaWikiBot("http://batwiki.wx.fi/w/");
- bot.login(wiki_user, password);
- win = clientGUI.createBatWindow("window",500,180,250,320);
- win.removeTabAt(0);
- BatPanel panel = new BatPanel();
- panel.setLayout(new BorderLayout());
- textArea = new JTextArea();
- JScrollPane scrollPane = new JScrollPane(textArea);
- panel.add(scrollPane,BorderLayout.CENTER);
- win.newTab(SCRIPT_NAME, panel);
- JButton button = new JButton("save");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- save();
- }
- });
- panel.add(button,BorderLayout.PAGE_END);
- }
- public void scan()
- {
- if(state == 1)
- {
- textArea.setText(textArea.getText().replaceFirst("\\| name = ","| name = " + vars.get(1)));
- state++;
- clientGUI.doCommand("emote scan..;l " + vars.get(1)+";emote ..end");
- }
- }
- public ParsedResult trigger() {
- String line = argument.getStrippedText();
- line = line.substring(0,line.length()-1);
- //removed state 1 check
- ArrayList/*<ParsedAttribute>*/ attrs = argument.getAttributes();
- //System.out.println(attrs.get(0).getAttribute().getName());
- //System.out.println(attrs.get(0).getAttribute().readResolve().getClass());
- //System.out.println(attrs.get(0).getValue().toString());
- if(!line.startsWith("'") && (attrs.get(0).getValue().equals(Color.GREEN) || attrs.get(0).getValue().equals(Color.RED)))
- {
- //System.out.println("greee!!!!");
- mob = line;
- }
- if (state == 2)
- {
- if(line.equals("*" + charname + " scan.."))
- {
- state++;
- }
- } else if (state == 3)
- {
- System.out.println(line);
- if(line.endsWith("is in excellent shape."))
- {
- textArea.setText(textArea.getText().replaceFirst("\\| description = ","| description = " + desc));
- desc = "";
- state++;
- }
- else {
- if(desc.equals(""))
- desc = line;
- else
- desc += " " + line;
- }
- } else if (state == 4)
- {// eq check..
- if(line.equals("*" + charname + " ..end.")) //mob has no eq
- {
- state = 0;
- textArea.setText(textArea.getText().replaceFirst("\\| eqs = ","| eqs = none"));
- eq = "";
- } else if (line.endsWith("equipment:"))
- state++;
- } else if (state == 5)
- {
- if(line.equals("*" + charname + " ..end."))
- {
- state = 0; //?? we finished?
- if(eq.equals(""))
- eq = "none";
- textArea.setText(textArea.getText().replaceFirst("\\| eqs = ","| eqs = " + eq));
- eq = "";
- } else {
- if(!eq.equals(""))
- eq += "\n\n";
- eq += line;
- }
- }
- return argument;
- }
- void run(){
- if(argument == null || ("".equals(argument))) argument = mob;
- if(bot.isLoggedIn())
- System.out.println("logged in");
- article = bot.readContent(argument);
- textArea.setText(article.getText());
- win.setVisible(true);
- }
- void create(){
- if(mob == null) return;
- clientGUI.printText("general","## active mob is:" + mob +"\n");
- article = bot.readContent(mob);
- if(article.getText().equals(""))
- {
- clientGUI.printText("general","## creating new..\n");
- textArea.setText(
- "{{ NPC \n"
- +"| name = \n"
- +"| description = \n"
- +"| eqs = \n"
- +"| race = \n"
- +"| undead = \n"
- +"| alignment = \n"
- +"| area = "+ area + "\n"
- +"| spell = \n"
- //+"| spell# = \n"
- +"| skill = \n"
- //+"| skill# = \n"
- +"| exp = \n"
- +"| GAP = \n"
- +"| PAP = \n"
- //+"| kerbholz = \n"
- +"| other = \n"
- +"}}"
- );
- //TODO: name scan
- state = 1;
- } else {
- textArea.setText(article.getText());
- }
- win.setVisible(true);
- }
- void state()
- {
- if(argument != null)
- state = Integer.parseInt(argument);
- clientGUI.printText("general","## we are in state: " + state + "\n");
- }
- void area ()
- {
- area = argument;
- }
- void save ()
- {
- System.out.println("save..");
- article.setText(textArea.getText());
- article.save("edit from batclient");
- System.out.println("done");
- clientGUI.printText("general","## saved\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement