changeset 7:c7972ff66484

Connexion du bot et longueur de chaine. - le bot ne se connectait pas au lancement... - les commandes ne sont plus prefixes par un @, il y a donc un caractere de moins a supprimer quand on s'interesse aux sous-chaines.
author Franck Deroche <webmaster@defr.net>
date Sat, 19 May 2007 17:47:17 +0200
parents 31b594967cf2
children 8391a973c9dc
files org/defr/bots/Rusard.java
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/org/defr/bots/Rusard.java	Sun May 13 21:57:46 2007 +0200
+++ b/org/defr/bots/Rusard.java	Sat May 19 17:47:17 2007 +0200
@@ -2,9 +2,13 @@
 
 import java.util.Random;
 import java.util.Calendar;
+import java.io.IOException;
 import java.text.DateFormat;
 import java.util.Locale;
 
+import org.jibble.pircbot.IrcException;
+import org.jibble.pircbot.NickAlreadyInUseException;
+
 public class Rusard extends Bot {
 
 	Random random;
@@ -14,10 +18,19 @@
 		random = new Random();
 	}
 
-	public static void main(String arg[]) throws Exception {
+	public static void main(String arg[]) {
 		Locale.setDefault(Locale.FRANCE);
 		Rusard b = new Rusard();
-		b.setVerbose(false);
+		try {
+			b.connect();
+		} catch (NickAlreadyInUseException e) {
+			System.out.println("Ce pseudo est utilisé sur le chat.");
+		} catch (IOException e) {
+			e.printStackTrace();
+		} catch (IrcException e) {
+			e.printStackTrace();
+		}
+		b.setVerbose(true);
 		b.joinChannel("#quidditch");
 	}
 
@@ -51,12 +64,12 @@
 			sendMessage(replyTo, "De : " + v);
 		}
 		else if(message.matches("d\\d+")) {
-			int t = Integer.parseInt(message.substring(2));
+			int t = Integer.parseInt(message.substring(1));
 			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 t = Integer.parseInt(message.substring(2));
 			int limite = 0, score = random.nextInt(100) + 1;
 			switch(t) {
 				case 0: