Search in sources :

Example 1 with IRCBot

use of irc.IRCBot in project Botnak by Gocnak.

the class AccountManager method run.

@Override
public void run() {
    //handle connection status
    while (!GUIMain.shutDown) {
        Task t = tasks.next();
        if (t != null) {
            switch(t.type) {
                case CREATE_BOT_ACCOUNT:
                    GUIMain.bot = new IRCBot();
                    PircBot bot = new PircBot(GUIMain.bot);
                    bot.setNick(getBotAccount().getName());
                    bot.setPassword(getBotAccount().getKey().getKey());
                    bot.setMessageDelay(1500);
                    setBot(bot);
                    addTask(new Task(getBot(), Task.Type.CONNECT, "Loaded Bot: " + getBotAccount().getName() + "!"));
                    break;
                case CREATE_VIEWER_ACCOUNT:
                    GUIMain.viewer = new IRCViewer();
                    PircBot viewer = new PircBot(GUIMain.viewer);
                    //TODO remove this
                    viewer.setVerbose(true);
                    viewer.setNick(getUserAccount().getName());
                    viewer.setPassword(getUserAccount().getKey().getKey());
                    setViewer(viewer);
                    addTask(new Task(getViewer(), Task.Type.CONNECT, "Loaded User: " + getUserAccount().getName() + "!"));
                    break;
                case DISCONNECT:
                    if (t.doer != null) {
                        if (t.doer.getConnection() != null) {
                            ReconnectThread potential = reconnectThreads.get(t.doer.getConnection().getName());
                            if (potential != null) {
                                potential.t.cancel();
                                reconnectThreads.remove(t.doer.getNick());
                            }
                        }
                        t.doer.disconnect();
                        t.doer.dispose();
                    }
                    break;
                case JOIN_CHANNEL:
                    if (t.doer != null) {
                        if (t.doer.isConnected()) {
                            String channel = (String) t.message;
                            if (!channel.startsWith("#"))
                                channel = "#" + channel;
                            t.doer.joinChannel(channel);
                        } else {
                            createReconnectThread(t.doer.getConnection());
                            //loops back around, adds to the reconnect thread
                            addTask(t);
                        }
                    }
                    break;
                case CONNECT:
                    if (t.doer.connect()) {
                        GUIMain.log(t.message);
                    } else {
                        if (!t.doer.isConnected()) {
                            createReconnectThread(t.doer.getConnection());
                        }
                    }
                    break;
                case LEAVE_CHANNEL:
                    if (t.doer != null) {
                        if (t.doer.isConnected()) {
                            String chaan = (String) t.message;
                            if (!chaan.startsWith("#"))
                                chaan = "#" + chaan;
                            t.doer.partChannel(chaan);
                        } else {
                            createReconnectThread(t.doer.getConnection());
                            //loops back around, adds to the reconnect thread
                            addTask(t);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : IRCViewer(irc.IRCViewer) TimerTask(java.util.TimerTask) IRCBot(irc.IRCBot) PircBot(lib.pircbot.PircBot)

Aggregations

IRCBot (irc.IRCBot)1 IRCViewer (irc.IRCViewer)1 TimerTask (java.util.TimerTask)1 PircBot (lib.pircbot.PircBot)1