User:Cakemix/Minibot

Source
package Irc;

/** * * @author Cakemix */ public class BotMain {

public static void main(String[] args) throws Exception { Config config = new Config("Settings.cfg"); MyBot bot = new MyBot; // bot.setVerbose(true); bot.setAutoNickChange(true); bot.connect(config.getProperty("Server")); if (config.getProperty("Server").toLowerCase.equals("true")) { bot.identify(config.getProperty("identifyPassword")); }       bot.joinChannel(config.getProperty("Channel")); } }

package Irc;

import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jibble.pircbot.*;

/** * * @author Cakemix */ public class MyBot extends PircBot {

Config config = new Config("Settings.cfg");

public MyBot { this.setName(config.getProperty("Nick")); }

@Override public void onMessage(String channel, String sender, String login, String hostname, String message) { Matcher matcher = Pattern.compile("\\[\\[(([^\\]|]|\\](?=[^\\]]))*)(\\|(([^\\]]|\\](?=[^\\]]))*))?\\]\\]").matcher(message); String output = "[Wiki]: "; while (matcher.find) { if (!matcher.group(1).trim.isEmpty) { String str = matcher.group(1); str = str.replaceAll("\\s", "_"); try { str = URLEncoder.encode(str, "UTF-8"); } catch (Exception e) { }               str = config.getProperty("Format") + str; if (!matcher.hitEnd) { str = str + ", "; }               output = output + str; }       }        matcher.reset; if (matcher.find) { if (!output.equals("[\00310Wiki\003]: ")) { sendMessage(channel, output.substring(0, output.length - 2)); }       }    } }

package Irc;

import java.io.File; import java.io.FileInputStream; import java.util.Properties;

/* Not mine, but made it a bit better for the bot to use by adding the custom file use and making it a bit smaller */ public class Config {

Properties configFile; String File;

public Config(String File) { configFile = new java.util.Properties; try { configFile.load(new FileInputStream(new File("").getAbsolutePath.toString + "\\" + File)); } catch (Exception eta) { eta.printStackTrace; }   }

public String getProperty(String key) { return (String) this.configFile.getProperty(key); } }