Search in sources :

Example 1 with IrcChannelMessageEvent

use of me.gloriouseggroll.quorrabot.event.irc.message.IrcChannelMessageEvent in project quorrabot by GloriousEggroll.

the class IRCParser method privMsg.

/*
     * ----------------------------------------------------------------------
     * Event Handling Methods. The below methods are all referenced from the
     * parserMap object.
     * ----------------------------------------------------------------------
     */
/*
     * Handles the PRIVMSG event from IRC.
     *
     * @param String message
     * @param String username
     * @param Map<String, String> tagsMap
     */
private void privMsg(String message, String username, Map<String, String> tagsMap) {
    /* Check to see if the user is using a ACTION in the channel. (/me) */
    if (message.startsWith("\001ACTION")) {
        message = message.replaceAll("\001", "").replace("ACTION", "/me");
    }
    /* Print the IRCv3 tags if debug mode is on*/
    com.gmt2001.Console.debug.println("IRCv3 Tags: " + tagsMap);
    //Check for JTV notices
    if (username.equalsIgnoreCase("jtv")) {
        com.gmt2001.Console.debug.println("jtv");
        //Check for hosts
        if (message.indexOf("host") != -1) {
            //com.gmt2001.Console.out.println("host");
            String hoster = message.split(" ")[0].toString();
            eventBus.post(new TwitchHostedEvent(hoster, this.channel, message));
            com.gmt2001.Console.debug.println("Hoster::" + hoster + "::true");
            return;
        }
        //Check for moderators on .mods notice
        if (message.indexOf("The moderators of this room are: ") != -1) {
            try {
                Thread.sleep(2000);
                Quorrabot.instance().channelUsersCache.updateCache();
                eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, this.ownerName.toLowerCase(), "O", true));
                String[] moderators = message.substring(33).split(", ");
                for (String moderator : moderators) {
                    if (moderator.equalsIgnoreCase(this.session.getNick())) {
                        this.session.setAllowSendMessages(true);
                    }
                    if (Quorrabot.instance().channelUsersCache.getCache().toString().contains(moderator.toLowerCase() + "=mod")) {
                        eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, moderator.toLowerCase(), "O", true));
                    }
                }
            } catch (Exception e) {
                //
                com.gmt2001.Console.out.println("Error::" + e.toString());
            }
            return;
        }
    }
    /* Print the parsed message in the console. */
    com.gmt2001.Console.out.println(username + ": " + message);
    /* Check to see if the users disaplay name. Used in the scripts. */
    if (tagsMap.containsKey("display-name")) {
        usernameCache.addUser(username, tagsMap.get("display-name"));
        com.gmt2001.Console.debug.println("Username::" + username + "::Display-Name::" + tagsMap.get("display-name"));
    }
    /* Check to see if the user is subscribing to the channel */
    if (message.endsWith("subscribed!") || message.endsWith("Prime!")) {
        if (username.equalsIgnoreCase("twitchnotify")) {
            message = message.split(" ")[0] + " just subscribed!";
            com.gmt2001.Console.debug.println(message.split(" ")[0] + " just subscribed!");
        }
    }
    /* Check to see if the user is donating/cheering bits */
    if (tagsMap.containsKey("bits")) {
        scriptEventManager.runDirect(new NewBits(this.session, this.channel, username, tagsMap.get("bits")));
        com.gmt2001.Console.debug.println("Bits::" + username + "::amount::" + tagsMap.get("bits"));
    }
    /* Check to see if the user is a channel subscriber */
    if (tagsMap.containsKey("subscriber")) {
        if (tagsMap.get("subscriber").equals("1")) {
            eventBus.post(new IrcPrivateMessageEvent(this.session, "jtv", "SPECIALUSER " + username + " subscriber", tagsMap));
            com.gmt2001.Console.debug.println("Subscriber::" + username + "::true");
        }
    }
    /* Check to see if the user is a moderator */
    if (tagsMap.containsKey("user-type")) {
        if (tagsMap.get("user-type").length() > 0) {
            if (!moderators.contains(username.toLowerCase())) {
                moderators.add(username.toLowerCase());
                eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, username, "O", true));
                com.gmt2001.Console.debug.println("Moderator::" + username + "::true");
            }
        } else if (this.channelName.equalsIgnoreCase(username)) {
            if (!moderators.contains(username.toLowerCase())) {
                moderators.add(username.toLowerCase());
                eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, username, "O", true));
                com.gmt2001.Console.debug.println("Broadcaster::" + username + "::true");
            }
        }
    }
    if (!username.equalsIgnoreCase("jtv") && !username.equalsIgnoreCase("twitchnotify") && !this.session.getNick().equalsIgnoreCase(this.session.getOwner())) {
        if (message.startsWith("!")) {
            String command;
            String argsString;
            if (message.indexOf(" ") == -1) {
                command = message.substring(1, message.length());
                argsString = "";
            } else {
                command = message.substring(1, message.indexOf(" "));
                argsString = message.substring(message.indexOf(" ") + 1);
            }
            Quorrabot.handleCommand(username, message.substring(1), tagsMap, this.channel, this.ownerName);
            //EventBus.instance().post(new CommandEvent(username, command, argsString, tagsMap, this.channel));
            return;
        }
    }
    /* Moderate the incoming message. Have it run in the background on a thread. */
    if (!this.session.getNick().equalsIgnoreCase(this.ownerName)) {
        try {
            ModerationRunnable moderationRunnable = new ModerationRunnable(this.session, username, message, this.channel, tagsMap);
            new Thread(moderationRunnable).start();
        } catch (Exception ex) {
            scriptEventManager.runDirect(new IrcModerationEvent(this.session, username, message, this.channel, tagsMap));
        }
        /* Send the message to the scripts. */
        eventBus.post(new IrcChannelMessageEvent(this.session, username, message, this.channel, tagsMap));
    }
    /* Incrememnt the chat lines, this should be the last operation of this function. */
    this.session.chatLinesIncr();
}
Also used : IrcPrivateMessageEvent(me.gloriouseggroll.quorrabot.event.irc.message.IrcPrivateMessageEvent) IrcModerationEvent(me.gloriouseggroll.quorrabot.event.irc.message.IrcModerationEvent) IrcChannelUserModeEvent(me.gloriouseggroll.quorrabot.event.irc.channel.IrcChannelUserModeEvent) NewBits(me.gloriouseggroll.quorrabot.event.twitch.bits.NewBits) IrcChannelMessageEvent(me.gloriouseggroll.quorrabot.event.irc.message.IrcChannelMessageEvent) TwitchHostedEvent(me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent)

Example 2 with IrcChannelMessageEvent

use of me.gloriouseggroll.quorrabot.event.irc.message.IrcChannelMessageEvent in project quorrabot by GloriousEggroll.

the class HTTPSServer method handlePutRequest.

private void handlePutRequest(String user, String message, HttpExchange exchange, Boolean hasPassword) {
    if (!hasPassword) {
        sendHTMLError(403, "Access Denied", exchange);
        return;
    }
    if (user == "" || message == "") {
        sendHTMLError(400, "Missing Parameter", exchange);
        return;
    }
    EventBus.instance().post(new IrcChannelMessageEvent(Quorrabot.instance().getSession(), user, message, Quorrabot.instance().getChannel()));
    sendData("text/text", "event posted", exchange);
}
Also used : IrcChannelMessageEvent(me.gloriouseggroll.quorrabot.event.irc.message.IrcChannelMessageEvent)

Aggregations

IrcChannelMessageEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcChannelMessageEvent)2 IrcChannelUserModeEvent (me.gloriouseggroll.quorrabot.event.irc.channel.IrcChannelUserModeEvent)1 IrcModerationEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcModerationEvent)1 IrcPrivateMessageEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcPrivateMessageEvent)1 NewBits (me.gloriouseggroll.quorrabot.event.twitch.bits.NewBits)1 TwitchHostedEvent (me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent)1