Mercurial > defr > bots
changeset 0:4348c80b039a
Import initial
author | defr@localhost.localdomain |
---|---|
date | Sat, 31 Mar 2007 17:11:58 +0200 |
parents | |
children | 4f934dfaa45a |
files | .classpath .hgignore .project org/defr/bots/Configuration.java org/defr/bots/MissTeigne/MissTeigne.java |
diffstat | 5 files changed, 128 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Sat Mar 31 17:11:58 2007 +0200 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path=""/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="/home/defr/pircbot.jar"/> + <classpathentry kind="output" path=""/> +</classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Mar 31 17:11:58 2007 +0200 @@ -0,0 +1,2 @@ +.class$ +MissTeigne.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Sat Mar 31 17:11:58 2007 +0200 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>MissTeigne</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/defr/bots/Configuration.java Sat Mar 31 17:11:58 2007 +0200 @@ -0,0 +1,55 @@ +package org.defr.bots; + +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +public class Configuration { + protected String botName = "Foo"; + protected String botPassword = null; + protected String serverName; + protected String services; + + public Configuration(File configFile) { + try { + DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document document = db.parse(configFile); + botName = document.getElementsByTagName("name").item(0).getTextContent(); + botPassword = document.getElementsByTagName("password").item(0).getTextContent(); + serverName = document.getElementsByTagName("server").item(0).getTextContent(); + services = document.getElementsByTagName("services").item(0).getTextContent(); + } catch (ParserConfigurationException e) { + System.err.println("Erreur de configuration du DocumentBuilderFactory"); + } catch (SAXException e) { + System.err.println("Fichier de configuration mal-formé"); + } catch (IOException e) { + System.err.println("Fichier de configuration absent - " + configFile.getAbsolutePath()); + + } + } + + public Configuration(String uri) { + this(new File(uri)); + } + + public String getBotName() { + return botName; + } + public String getBotPassword() { + return botPassword; + } + public String getServerName() { + return serverName; + } + public String getServices() { + return services; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/defr/bots/MissTeigne/MissTeigne.java Sat Mar 31 17:11:58 2007 +0200 @@ -0,0 +1,47 @@ +package org.defr.bots.MissTeigne; + +import java.io.File; +import java.io.IOException; + +import org.defr.bots.Configuration; +import org.jibble.pircbot.IrcException; +import org.jibble.pircbot.NickAlreadyInUseException; + +public class MissTeigne extends org.jibble.pircbot.PircBot { + + Configuration conf; + + public MissTeigne() { + super(); + conf = new Configuration(new File("MissTeigne.xml")); + setName(conf.getBotName()); + } + + public void onNotice(String sourceNick, + String sourceLogin, + String sourceHostname, + String target, + String notice) { + if(target.equalsIgnoreCase(getNick()) && sourceHostname.equals(conf.getServices())) { + // We're re-actign on a notice sent by a service :-) + if(sourceLogin.equals("NickServ") && notice.indexOf("IDENTIFY") > -1) { + this.sendMessage(sourceLogin, "IDENTIFY " + conf.getBotPassword()); + } + } + } + + public static void main(String[] arg) { + MissTeigne mt = new MissTeigne(); + mt.setVerbose(true); + try { + mt.connect("home.defr.org"); + } catch (NickAlreadyInUseException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (IrcException e) { + e.printStackTrace(); + } + mt.joinChannel("#test"); + } +}