Mercurial > defr > bots
changeset 4:f9f6348eb8e9
Ajout d'une nouvelle classe de base.
author | Franck Deroche <defr@defr.net> |
---|---|
date | Sun, 13 May 2007 21:49:24 +0200 |
parents | 568c206089c1 |
children | 7b4e82a18764 |
files | org/defr/bots/Bot.java |
diffstat | 1 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/defr/bots/Bot.java Sun May 13 21:49:24 2007 +0200 @@ -0,0 +1,47 @@ +package org.defr.bots; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import org.jibble.pircbot.IrcException; +import org.jibble.pircbot.NickAlreadyInUseException; +import org.jibble.pircbot.PircBot; + +/** + * Cette classe étend PircBot, en y intégrant le support des fichiers de + * configuration XML via la classe configuration. + * @author defr + */ +public class Bot extends PircBot { + protected Configuration conf; + + public Bot() { + super(); + } + + /** + * Lecture des paramètres à partir du fichier <param>conf/<em>botName</em>.xml</param> + * @param botName + */ + public Bot(String botName) { + conf = new Configuration("conf/" + botName + ".xml"); + setName(conf.getBotName()); + setLogin(conf.getBotName()); + try { + setEncoding(conf.getEncoding()); + } catch (UnsupportedEncodingException e) { + System.out.println("Cet encodage n'est pas supporté," + + " des caractères peuvent ressortir étrangement"); + } + } + + /** + * Connexion au serveur IRC défini dans le fichier de configuration + * @throws NickAlreadyInUseException + * @throws IOException + * @throws IrcException + */ + public void connect() throws NickAlreadyInUseException, IOException, IrcException { + connect(conf.getServerName()); + } +}