Package org.pircbotx

Examples of org.pircbotx.PircBotX


//                System.exit(3);
//            }
//            fis.close();
        }

        PircBotX bot = new RhqIrcBot(rhqBotListener);
        bot.connect(server);
        bot.joinChannel(channel.trim());
    }
View Full Code Here


    public void onMessage(final MessageEvent<RhqIrcBot> event) throws Exception {
        if (event.getUser().getNick().toLowerCase().contains("bot")) {
            return; // never talk with artificial forms of life
        }

        final PircBotX bot = event.getBot();
        if (!bot.getNick().equals(bot.getName())) {
            bot.changeNick(bot.getName());
        }
        String message = event.getMessage();

        // react to BZs in the messages
        Matcher bzMatcher = BZ_PATTERN.matcher(message);
        while (bzMatcher.find()) {
            final String response = bzResolver.resolve(bzMatcher.group(2));
            bot.sendMessage(event.getChannel(), response);
        }

        // react to Jira bugs in the messages
        Matcher jiraMatcher = JIRA_PATTERN.matcher(message);
        while (jiraMatcher.find()) {
            //            final String response = jiraResolver.resolve(bzMatcher.group(1));
            //            bot.sendMessage(event.getChannel(), response);
            final String bugId = jiraMatcher.group(1);
            final Promise<Issue> issuePromise = jiraResolver.resolveAsync(bugId);
            issuePromise.done(new Effect<Issue>() {
                @Override
                public void apply(Issue a) {
                    bot.sendMessage(event.getChannel(), bugId + ": " + Color.RED + a.getSummary() + Color.NORMAL
                        + ", priority: " + Color.GREEN + a.getPriority().getName() + Color.NORMAL + ", created: "
                        + a.getCreationDate().toString("YYYY-MM-DD") + "  [ " + JiraResolver.JIRA_URL + "/browse/"
                        + bugId + " ]");
                }
            });
            issuePromise.fail(new Effect<Throwable>() {
                @Override
                public void apply(Throwable e) {
                    bot.sendMessage(event.getChannel(),
                        "Failed to access bug " + bugId + " Cause: " + shorten(e.getMessage()));
                }
            });
        }

        // react to the commit hashs included in the messages
        Matcher commitMatcher = COMMIT_PATTERN.matcher(message);
        while (commitMatcher.find()) {
            String shaHash = commitMatcher.group(2);
            String response = String.format(COMMIT_LINK, shaHash);
            bot.sendMessage(event.getChannel(), event.getUser().getNick() + ": " + response);
        }

        if (message.startsWith(event.getBot().getNick())) {
            // someone asked bot directly, we have to remove that from message
            message = message.substring(event.getBot().getNick().length());
            message = message.replaceFirst("[^ ]*", "");
        }
        // react to commands included in the messages
        Matcher commandMatcher = commandPattern.matcher(message);
        while (commandMatcher.find()) {
            Command command = Command.valueOf(commandMatcher.group(1).toUpperCase());
            String response = prepareResponseForCommand(command);
            if (response != null) {
                bot.sendMessage(event.getChannel(), event.getUser().getNick() + ": " + shorten(response));
            }
        }

        // ping JON devs
        if (message.matches(".*\\b(jon-team|jboss-on-team)\\b.*")) {
            Set<User> users = bot.getUsers(event.getChannel());
            StringBuilder presentJonDevs = new StringBuilder();
            for (User user : users) {
                String nick = user.getNick();
                if (JON_DEVS.contains(nick) && !nick.equals(event.getUser().getNick())) {
                    presentJonDevs.append(nick).append(' ');
                }
            }
            bot.sendMessage(event.getChannel(), presentJonDevs + ": see message from " + event.getUser().getNick()
                + " above");
        }
    }
View Full Code Here

        }
    }

    @Override
    public void onPrivateMessage(PrivateMessageEvent<RhqIrcBot> privateMessageEvent) throws Exception {
        PircBotX bot = privateMessageEvent.getBot();
        String message = privateMessageEvent.getMessage();
        Matcher echoMatcher = ECHO_PATTERN.matcher(message);
        if (echoMatcher.matches()) {
            if (!JON_DEVS.contains(privateMessageEvent.getUser().getNick())) {
                privateMessageEvent.respond("You're not my master, I am your master, go away");
            } else {
                String echoMessage = echoMatcher.group(1);
                bot.sendMessage(this.channel, echoMessage);
            }
        } else if (message.equalsIgnoreCase(Command.PREFIX + "listrenames")) {
            //Generate a list of renames in the form of old1 changed to new1, old2 changed to new2, etc
            StringBuilder users = new StringBuilder();
            for (Map.Entry<String, String> curUser : names.entrySet()) {
                users.append(curUser.getKey()).append(" changed to ").append(curUser.getValue()).append(", ");
            }
            String usersString = users.substring(0, users.length() - 3);
            privateMessageEvent.respond("Renamed users: " + usersString);
        } else {
            boolean isCommand = false;
            // react to commands included in the messages
            Matcher commandMatcher = commandPattern.matcher(message);
            while (commandMatcher.find()) {
                isCommand = true;
                Command command = Command.valueOf(commandMatcher.group(1).toUpperCase());
                String response = prepareResponseForCommand(command);
                if (response != null) {
                    bot.sendMessage(privateMessageEvent.getUser(), response);
                }
            }
            if (!isCommand) {
                bot.sendMessage(privateMessageEvent.getUser(), "Hi, I am " + bot.getFinger() + ".\n"
                    + prepareResponseForCommand(Command.HELP));
            }
        }
    }
View Full Code Here

    public void onDisconnect(DisconnectEvent<RhqIrcBot> disconnectEvent) throws Exception {
        boolean connected = false;
        while (!connected) {
            Thread.sleep(60 * 1000L); // 1 minute
            try {
                PircBotX newBot = new RhqIrcBot(this);
                newBot.connect(this.server);
                newBot.joinChannel(this.channel);

                connected = true;
            } catch (Exception e) {
                System.err.println("Failed to reconnect to " + disconnectEvent.getBot().getServer() + " IRC server: "
                    + e);
            }
        }

        // Try to clean up the old bot, so it can release any memory, sockets, etc. it's using.
        PircBotX oldBot = disconnectEvent.getBot();
        Set<Listener> oldListeners = new HashSet<Listener>(oldBot.getListenerManager().getListeners());
        for (Listener oldListener : oldListeners) {
            oldBot.getListenerManager().removeListener(oldListener);
        }
    }
View Full Code Here

    private static PircBotX bot;

    public static void connectToServer()
    {
        OutputHandler.felog.info("Initializing IRC connection");
        bot = new PircBotX();
        bot.setName(name);
        bot.getListenerManager().addListener(new IRCHelper());
        bot.setLogin(name);
        bot.setVerbose(false);
        bot.setAutoNickChange(true);
View Full Code Here

            builder.getListenerManager().addListener(new com.zack6849.alphabot.listeners.MessageEvent(config, manager));
            builder.getListenerManager().addListener(new com.zack6849.alphabot.listeners.InviteEvent(config, manager));
            for (String channel : config.getChannels()) {
                builder.addAutoJoinChannel(channel);
            }
            PircBotX bot = new PircBotX(builder.buildConfiguration());
            System.out.println("Starting bot...");
            if (config.isEnableChatSocket()) {
                new Thread(new ChatSocketListener(bot, config)).start();
            }
            bot.startBot();
            System.out.println("Shutting down");
            System.exit(0);
        } catch (Exception ex) {
            ex.printStackTrace();
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

TOP

Related Classes of org.pircbotx.PircBotX

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.