# HG changeset patch # User defr@albus # Date 1177938967 -7200 # Node ID 4f934dfaa45ad33d759ee5e41f532569077a1ff1 # Parent 4348c80b039a00ed2c2fa1cb282e7e539bf3f9f9 Ajout de Rusard, pas forcement pircbot a cet endroit diff -r 4348c80b039a -r 4f934dfaa45a .classpath --- a/.classpath Sat Mar 31 17:11:58 2007 +0200 +++ b/.classpath Mon Apr 30 15:16:07 2007 +0200 @@ -2,6 +2,5 @@ - diff -r 4348c80b039a -r 4f934dfaa45a org/defr/bots/Rusard.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/defr/bots/Rusard.java Mon Apr 30 15:16:07 2007 +0200 @@ -0,0 +1,88 @@ +package org.defr.bots; + +import org.jibble.pircbot.*; +import java.util.Random; +import java.util.Calendar; +import java.text.DateFormat; +import java.util.Locale; + +public class Rusard extends PircBot { + + Random random; + + public Rusard() { + this.setName("Rusard"); + random = new 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 void onMessage(String ch, String s, String l, String h, String m) { + messageParser(m, s, ch); + } + + 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")) { + 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")) { + int v = random.nextInt(6) + 1; + sendMessage(replyTo, "De : " + v); + } + 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")) { + int t = Integer.parseInt(message.substring(3)); + int limite = 0, score = random.nextInt(100) + 1; + switch(t) { + case 0: + limite = 10; + break; + case 1: + limite = 30; + break; + case 2: + limite = 50; + break; + case 3: + limite = 70; + break; + case 4: + limite = 80; + break; + default: + limite = 98; + } + if(score > limite) { + sendMessage(replyTo, "Réussite (" + score + "/" + limite + ")"); + } + else { + sendMessage(replyTo, "Echec (" + score + "/" + limite + ")"); + } + } + } + + public void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target) { + sendNotice(sourceNick, "Rusard - MP Bot v0.0.1"); + } +}