# HG changeset patch # User defr@localhost.localdomain # Date 1179001785 -7200 # Node ID a2285ee1c687bcd31afc5c238e4259fd2e10cd07 # Parent 4f934dfaa45ad33d759ee5e41f532569077a1ff1 Transformation legere de la facon dont les commandes sont gerees au niveau de Rusard diff -r 4f934dfaa45a -r a2285ee1c687 org/defr/bots/Rusard.java --- a/org/defr/bots/Rusard.java Mon Apr 30 15:16:07 2007 +0200 +++ b/org/defr/bots/Rusard.java Sat May 12 22:29:45 2007 +0200 @@ -7,51 +7,61 @@ import java.util.Locale; public class Rusard extends PircBot { - - Random random; - public Rusard() { - this.setName("Rusard"); - random = new Random(); - } + Random random; - public static void main(String arg[]) throws Exception { - Locale.setDefault(Locale.FRANCE); - Rusard b = new Rusard(); - b.setVerbose(false); - b.setName("Rusard"); - b.setLogin("Rusard"); - b.setVersion("Rusard - MP Bot v0.0.1"); - b.setEncoding("iso8859-1"); - b.connect("hermes.local"); - b.joinChannel("#quidditch"); - } + public Rusard() { + this.setName("Rusard"); + random = new Random(); + } - public void onMessage(String ch, String s, String l, String h, String m) { - messageParser(m, s, ch); - } + public static void main(String arg[]) throws Exception { + Locale.setDefault(Locale.FRANCE); + Rusard b = new Rusard(); + b.setVerbose(false); + b.setName("Rusard"); + b.setLogin("Rusard"); + b.setVersion("Rusard - MP Bot v0.0.1"); + b.setEncoding("iso8859-1"); + b.connect("hermes.local"); + b.joinChannel("#quidditch"); + } - public void onPrivateMessage(String send, String login, String host, String m) { - messageParser("@" + m, send, send); - } - - public void messageParser(String message, String orig, String replyTo) { - if(message.equalsIgnoreCase("@time")) { + public void onMessage(String ch, String s, String l, String h, String m) { + if(m.startsWith("@") || m.startsWith(getNick() + ",")) { + String command; + if(m.startsWith("@")) { + command = m.substring(1); + } + else { + command = m.substring(getNick().length() + 1); + command = command.trim(); + } + commandParser(command, s, ch); + } + } + + public void onPrivateMessage(String send, String login, String host, String m) { + commandParser(m, send, send); + } + + public void commandParser(String message, String orig, String replyTo) { + if(message.equalsIgnoreCase("time")) { Calendar c = Calendar.getInstance(Locale.FRANCE); DateFormat df = DateFormat.getInstance(); String t = df.format(c.getTime()); sendMessage(replyTo, "Nous sommes le " + t); } - else if(message.equalsIgnoreCase("@de")) { + else if(message.equalsIgnoreCase("de")) { int v = random.nextInt(6) + 1; sendMessage(replyTo, "De : " + v); } - else if(message.matches("^@d\\d+")) { + else if(message.matches("d\\d+")) { int t = Integer.parseInt(message.substring(2)); int v = random.nextInt(t) + 1; sendMessage(replyTo, "d" + t + " : " + v); } - else if(message.matches("^@dd\\d")) { + else if(message.matches("dd\\d")) { int t = Integer.parseInt(message.substring(3)); int limite = 0, score = random.nextInt(100) + 1; switch(t) { @@ -80,9 +90,9 @@ sendMessage(replyTo, "Echec (" + score + "/" + limite + ")"); } } - } + } - public void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target) { - sendNotice(sourceNick, "Rusard - MP Bot v0.0.1"); - } + public void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target) { + sendNotice(sourceNick, "Rusard - MP Bot v0.0.1"); + } }