changeset 1:4f934dfaa45a

Ajout de Rusard, pas forcement pircbot a cet endroit
author defr@albus
date Mon, 30 Apr 2007 15:16:07 +0200
parents 4348c80b039a
children a2285ee1c687
files .classpath org/defr/bots/Rusard.java
diffstat 2 files changed, 88 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Sat Mar 31 17:11:58 2007 +0200
+++ b/.classpath	Mon Apr 30 15:16:07 2007 +0200
@@ -2,6 +2,5 @@
 <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/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");
+    }
+}