Bot IRC

Palleas_44 Messages postés 130 Date d'inscription lundi 12 décembre 2005 Statut Membre Dernière intervention 19 avril 2009 - 15 déc. 2007 à 13:47
cs_shown Messages postés 40 Date d'inscription jeudi 26 août 2004 Statut Membre Dernière intervention 24 décembre 2007 - 18 déc. 2007 à 21:06
Bonjour les gens :)

J'ai envie de coder un bot en Java histoire de comprendre comment ça marche tout ça. Mais je rame, j'arrive apparement à me connecter au serveur et à gérer les pings, vu que je suis tout déconnecter et que j'arrive à pinger le serveur. Mais impossible de me connecter à un canal, voila mon code :

package classes;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class Canal {
    private int port;
    private String server,name, botUser, botRealName, botHost, botNick,line;
    private BufferedReader input;
    private PrintStream output;
    private Boolean connected = false;
   
    public static final String __N = "\015";
    public Canal(String server,String name, int port, String botUser, String botRealName, String botHost, String botNick) {
        this.server = server.trim();
        this.name = name.trim();
        this.port = port;
        this.botUser = botUser.trim();
        this.botRealName = botRealName.trim();
        this.botHost = botHost.trim();
        this.botNick = botNick.trim();
        connect();
        try {
            send("JOIN #nextwizard"+__N);
            while(isConnected()) {
                line = input.readLine();
                System.out.println(line);
                if(getCommand().equals("ping")) {
                    pong(line.substring(6));
                }
                ping();
            }
        } catch(IOException e) {
            System.out.println(e);
        }
    }
   
    public void connect() {
        try {
            Socket ircSock = new Socket(server,port);
            output = new PrintStream(ircSock.getOutputStream());
            send("USER "+botUser+" UNIX "+botRealName+"@"+botHost+" "+botUser+__N);
            send("NICK "+botNick+__N);
            input = new BufferedReader(new InputStreamReader(ircSock.getInputStream()));
        } catch(IOException e) {
            System.out.println("Exception : ");
            e.printStackTrace();
        }
    }
   
    public void disconnect() {}
   
    public void send(String msg) {
        output.print(msg);
        output.flush();
    }
   
    public String getCommand() {
        String ret = line.substring(0,line.indexOf(" ")).toLowerCase();
        return ret;
    }
   
    public void ping() {
        send("PING "+server+__N);
    }
   
    public void pong(String msg) {
        System.out.println("(PONG) Message à renvoyer au serveur : "+msg);
        output.print("PONG "+msg+__N);
        output.flush();
    }
   
    public boolean isConnected() { return true; }
// Accesseurs (j'enleve pour ne pas surcharger l'affichage :p)  
// toString
   
    public static void main(String[] args) {
        new Canal("irc.epiknet.org","nextwizard",6667,"NWBot","PalleasNextWizard40","nextwizard.com","PalleasNextWizard40");
    }
}

J'avoue que je sèche un peu, car il ne me retourne pas d'erreur, c'est un problème de méconnaissance d'IRC ou il manque des choses à mon java ? :x
Merci d'avance :)

Palleas

1 réponse

cs_shown Messages postés 40 Date d'inscription jeudi 26 août 2004 Statut Membre Dernière intervention 24 décembre 2007
18 déc. 2007 à 21:06
Essaye de remplacer ça :







send("USER "+botUser+" UNIX "+botRealName+"@"+botHost+" "+botUser+__N);


send("NICK "+botNick+__N);







par ça :





send("NICK "+botNick+__N);


send("USER "+botUser+" "+botRealName+" "+botHost+" :"+botUser+__N);

Et dans cet ordre-ci ! Tu peux vérifier en te connectant par telnet si tes commandes sont bonnes.
0
Rejoignez-nous