Search in sources :

Example 1 with TwitchHostedEvent

use of me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent in project quorrabot by GloriousEggroll.

the class Quorrabot method onConsoleMessage.

@Subscribe
public void onConsoleMessage(ConsoleInputEvent msg) {
    String message = msg.getMsg();
    boolean changed = false;
    if (message == null) {
        return;
    }
    if (message.equals("debugon")) {
        Quorrabot.setDebugging(true);
    }
    //used for testing notifications
    if (message.equalsIgnoreCase("subtest")) {
        String randomUser = generateRandomString(10);
        EventBus.instance().post(new IrcPrivateMessageEvent(this.session, "twitchnotify", randomUser + " just subscribed!"));
    }
    if (message.equalsIgnoreCase("resubtest")) {
        String randomUser = generateRandomString(10);
        EventBus.instance().post(new IrcPrivateMessageEvent(this.session, "twitchnotify", randomUser + " just subscribed for 10 months in a row!"));
    }
    if (message.equalsIgnoreCase("followtest")) {
        String randomUser = generateRandomString(10);
        EventBus.instance().post(new TwitchFollowEvent(randomUser, this.channel));
    }
    if (message.equalsIgnoreCase("hosttest")) {
        String randomUser = generateRandomString(10);
        EventBus.instance().post(new TwitchHostedEvent(randomUser, this.tcechannel));
    }
    if (message.equals("debugoff")) {
        Quorrabot.setDebugging(false);
    }
    if (message.startsWith("inidb.get")) {
        String[] spl = message.split(" ", 4);
        com.gmt2001.Console.out.println(dataStoreObj.GetString(spl[1], spl[2], spl[3]));
    }
    if (message.startsWith("inidb.set")) {
        String[] spl = message.split(" ", 5);
        dataStoreObj.SetString(spl[1], spl[2], spl[3], spl[4]);
        com.gmt2001.Console.out.println(dataStoreObj.GetString(spl[1], spl[2], spl[3]));
    }
    if (message.equals("apioauth")) {
        com.gmt2001.Console.out.print("Please enter the bot owner's api oauth string: ");
        String newoauth = System.console().readLine().trim();
        TwitchAPIv3.instance().SetOAuth(newoauth);
        apioauth = newoauth;
        changed = true;
    }
    if (message.equalsIgnoreCase("mysqlsetup")) {
        try {
            com.gmt2001.Console.out.println("");
            com.gmt2001.Console.out.println("QuorraBot MySQL setup.");
            com.gmt2001.Console.out.println("");
            com.gmt2001.Console.out.print("Please enter your MySQL host name or IP: ");
            String newHost = System.console().readLine().trim();
            mySqlHost = newHost;
            com.gmt2001.Console.out.print("Please enter your MySQL port: ");
            String newPost = System.console().readLine().trim();
            mySqlPort = newPost;
            com.gmt2001.Console.out.print("Please enter your MySQL db name: ");
            String newName = System.console().readLine().trim();
            mySqlName = newName;
            com.gmt2001.Console.out.print("Please enter a username for MySQL: ");
            String newUser = System.console().readLine().trim();
            mySqlUser = newUser;
            com.gmt2001.Console.out.print("Please enter a password for MySQL: ");
            String newPass = System.console().readLine().trim();
            mySqlPass = newPass;
            datastore = "MySQLStore";
            dataStoreObj = MySQLStore.instance();
            if (mySqlPort.isEmpty()) {
                mySqlConn = "jdbc:mariadb://" + mySqlHost + "/" + mySqlName;
            } else {
                mySqlConn = "jdbc:mariadb://" + mySqlHost + ":" + mySqlPort + "/" + mySqlName;
            }
            /**
                 * Check to see if we can create a connection
                 */
            if (dataStoreObj.CreateConnection(mySqlConn, mySqlUser, mySqlPass) == null) {
                com.gmt2001.Console.out.println("Could not create a connection with MySql. QuorraBot now shutting down...");
                System.exit(0);
            }
            if (IniStore.instance().GetFileList().length > 0) {
                ini2MySql(true);
            } else if (SqliteStore.instance().GetFileList().length > 0) {
                sqlite2MySql();
            }
            com.gmt2001.Console.out.println("QuorraBot MySQL setup done.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }
    if (message.equals("clientid")) {
        com.gmt2001.Console.out.print("Please enter the bot api clientid string: ");
        String newclientid = System.console().readLine().trim();
        TwitchAPIv3.instance().SetClientID(newclientid);
        clientid = newclientid;
        changed = true;
    }
    if (message.equals("baseport")) {
        com.gmt2001.Console.out.print("Please enter a new base port: ");
        String newbaseport = System.console().readLine().trim();
        baseport = Integer.parseInt(newbaseport);
        changed = true;
    }
    if (message.equals("ip")) {
        com.gmt2001.Console.out.print("Please enter an IP address to bind to: ");
        String ipstr = System.console().readLine().trim();
        try {
            InetAddress newip = InetAddress.getByName(ipstr);
            ip = newip;
            changed = true;
        } catch (UnknownHostException e) {
            com.gmt2001.Console.out.print("Error binding to IP address, please double check your IP entry.");
            return;
        }
    }
    if (message.equals("youtubekey")) {
        com.gmt2001.Console.out.print("Please enter a new YouTube API key: ");
        String newyoutubekey = System.console().readLine().trim();
        YouTubeAPIv3.instance().SetAPIKey(newyoutubekey);
        youtubekey = newyoutubekey;
        changed = true;
    }
    if (message.equals("twitchalerts")) {
        com.gmt2001.Console.out.print("Please enter a new TwitchAlerts Access Token: ");
        String newtwitchalertstoken = System.console().readLine().trim();
        DonationHandlerAPI.instance().SetAccessToken(newtwitchalertstoken, "twitchalerts");
        twitchalertstoken = newtwitchalertstoken;
        changed = true;
    }
    if (message.equals("lastfm")) {
        com.gmt2001.Console.out.print("Please enter a last.fm username: ");
        String newlastfmuser = System.console().readLine().trim();
        LastFMAPI.instance().SetUsername(newlastfmuser);
        lastfmuser = newlastfmuser;
        changed = true;
    }
    if (message.equals("tipeeestream")) {
        com.gmt2001.Console.out.print("Please enter a new Tipeeestream Access Token: ");
        String newtpetoken = System.console().readLine().trim();
        DonationHandlerAPI.instance().SetAccessToken(newtpetoken, "tpestream");
        tpetoken = newtpetoken;
        changed = true;
    }
    if (message.equals("twitter")) {
        com.gmt2001.Console.out.print("Please visit this url to grant QuorraBot twitter access, then enter your pin" + "\n");
        com.gmt2001.Console.out.print(TwitterAPI.instance().getRequestTokenURL() + "\n");
        com.gmt2001.Console.out.print("Twitter PIN:");
        String newtwittertoken = System.console().readLine().trim();
        TwitterAPI.instance().CreateAccessToken(newtwittertoken);
        twittertoken = TwitterAPI.instance().getAccessToken();
        twittertokensecret = TwitterAPI.instance().getAccessTokenSecret();
        changed = true;
    }
    if (message.equals("streamtip")) {
        com.gmt2001.Console.out.print("Please enter a new StreamTip Client ID: ");
        String newstreamtipid = System.console().readLine().trim();
        DonationHandlerAPI.instance().SetClientID(newstreamtipid, "streamtip");
        streamtipid = newstreamtipid;
        com.gmt2001.Console.out.print("Please enter a new StreamTip Access Token: ");
        String newstreamtiptoken = System.console().readLine().trim();
        DonationHandlerAPI.instance().SetAccessToken(newstreamtiptoken, "streamtip");
        streamtiptoken = newstreamtiptoken;
        changed = true;
    }
    if (message.equals("gamewisp")) {
        com.gmt2001.Console.out.print("Please enter a new GameWisp Access Token: ");
        String newgamewispauth = System.console().readLine().trim();
        gamewispauth = newgamewispauth;
        GameWispAPI.instance().SetAccessToken(gamewispauth);
        SingularityAPI.instance().setAccessToken(gamewispauth);
        com.gmt2001.Console.out.print("Please enter a new GameWisp Refresh Token: ");
        String newgamewisprefresh = System.console().readLine().trim();
        gamewisprefresh = newgamewisprefresh;
        GameWispAPI.instance().SetRefreshToken(gamewisprefresh);
        doRefreshGameWispToken();
        changed = true;
    }
    if (message.equals("discord")) {
        com.gmt2001.Console.out.print("Please enter a new Discord Access Token: ");
        String newdiscordtoken = System.console().readLine().trim();
        discordToken = newdiscordtoken;
        com.gmt2001.Console.out.print("Please enter the name of the discord channel for the bot to join: ");
        String newdiscordmainchannel = System.console().readLine().trim();
        discordMainChannel = newdiscordmainchannel;
        changed = true;
    }
    if (message.equals("testgwrefresh")) {
        com.gmt2001.Console.out.println("[CONSOLE] Executing testgwrefresh");
        updateGameWispTokens(GameWispAPI.instance().refreshToken());
        changed = true;
    }
    if (message.equals("testgwsub")) {
        com.gmt2001.Console.out.println("[CONSOLE] Executing testgwsub");
        EventBus.instance().post(new GameWispSubscribeEvent(this.username, 1));
        return;
    }
    if (message.equals("testgwresub")) {
        com.gmt2001.Console.out.println("[CONSOLE] Executing testgwresub");
        EventBus.instance().post(new GameWispAnniversaryEvent(this.username, 2, 3));
        return;
    }
    if (message.equals("webenable")) {
        com.gmt2001.Console.out.print("Please note that the music server will also be disabled if the web server is disabled. The bot will require a restart for this to take effect. Type true or false to enable/disable web server: ");
        String newwebenable = System.console().readLine().trim();
        changed = true;
        if (newwebenable.equalsIgnoreCase("1") || newwebenable.equalsIgnoreCase("true")) {
            webenable = true;
        } else {
            webenable = false;
        }
    }
    if (message.equals("musicenable")) {
        if (!webenable) {
            com.gmt2001.Console.out.println("Web server must be enabled first. ");
        } else {
            com.gmt2001.Console.out.print("The bot will require a restart for this to take effect. Please type true or false to enable/disable music server: ");
            String newmusicenable = System.console().readLine().trim();
            changed = true;
            if (newmusicenable.equalsIgnoreCase("1") || newmusicenable.equalsIgnoreCase("true")) {
                musicenable = true;
            } else {
                musicenable = false;
            }
        }
    }
    if (changed) {
        try {
            String data = "";
            data += "user=" + username + "\r\n";
            data += "oauth=" + oauth + "\r\n";
            data += "apioauth=" + apioauth + "\r\n";
            data += "clientid=" + clientid + "\r\n";
            data += "webauth=" + webauth + "\r\n";
            data += "webauthro=" + webauthro + "\r\n";
            data += "owner=" + ownerName + "\r\n";
            data += "channel=" + channelName + "\r\n";
            data += "baseport=" + baseport + "\r\n";
            data += "ip=" + ip.getHostAddress() + "\r\n";
            data += "hostname=" + hostname + "\r\n";
            data += "port=" + port + "\r\n";
            data += "msglimit30=" + msglimit30 + "\r\n";
            data += "datastore=" + datastore + "\r\n";
            data += "youtubekey=" + youtubekey + "\r\n";
            data += "twitchalertstoken=" + twitchalertstoken + "\r\n";
            data += "gamewispauth=" + gamewispauth + "\r\n";
            data += "gamewisprefresh=" + gamewisprefresh + "\r\n";
            data += "lastfmuser=" + lastfmuser + "\r\n";
            data += "tpetoken=" + tpetoken + "\r\n";
            data += "twittertoken=" + twittertoken + "\r\n";
            data += "twittertokensecret=" + twittertokensecret + "\r\n";
            data += "streamtiptoken=" + streamtiptoken + "\r\n";
            data += "streamtipid=" + streamtipid + "\r\n";
            data += "webenable=" + webenable + "\r\n";
            data += "musicenable=" + musicenable + "\r\n";
            data += "usehttps=" + usehttps + "\r\n";
            data += "logtimezone=" + timeZone + "\r\n";
            data += "mysqlhost=" + mySqlHost + "\r\n";
            data += "mysqlport=" + mySqlPort + "\r\n";
            data += "mysqlname=" + mySqlName + "\r\n";
            data += "mysqluser=" + mySqlUser + "\r\n";
            data += "mysqlpass=" + mySqlPass + "\r\n";
            data += "keystorepath=" + keystorepath + "\r\n";
            data += "discordtoken=" + discordToken + "\r\n";
            data += "discordmainchannel=" + discordMainChannel + "\r\n";
            Files.write(Paths.get("./botlogin.txt"), data.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
            SingularityAPI.instance().setAccessToken(gamewispauth);
            if (webenable) {
                com.gmt2001.Console.out.println("[SHUTDOWN] Terminating web server...");
                eventsocketserver.dispose();
                if (musicenable) {
                    com.gmt2001.Console.out.println("[SHUTDOWN] Terminating music server...");
                    musicsocketserver.dispose();
                }
                httpserver.dispose();
                startWebServices();
            }
            if (!discordToken.isEmpty()) {
                DiscordAPI.instance().reconnect();
                connectDiscord();
            }
            com.gmt2001.Console.out.println("Changes have been saved! Some changes may only take place after QuorraBot is restarted.");
        } catch (IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }
    if (message.equals("save")) {
        dataStoreObj.SaveAll(true);
    }
    if (message.equals("quicksave")) {
        dataStoreObj.SaveChangedNow();
    }
    if (message.equals("exit")) {
        System.exit(0);
    }
    Map<String, String> tags = new HashMap<>();
    handleCommand(username, message, tags, channel, ownerName);
}
Also used : IrcPrivateMessageEvent(me.gloriouseggroll.quorrabot.event.irc.message.IrcPrivateMessageEvent) UnknownHostException(java.net.UnknownHostException) GameWispSubscribeEvent(me.gloriouseggroll.quorrabot.event.gamewisp.GameWispSubscribeEvent) HashMap(java.util.HashMap) IOException(java.io.IOException) TwitchHostedEvent(me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent) TwitchFollowEvent(me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchFollowEvent) GameWispAnniversaryEvent(me.gloriouseggroll.quorrabot.event.gamewisp.GameWispAnniversaryEvent) InetAddress(java.net.InetAddress) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with TwitchHostedEvent

use of me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent 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)

Aggregations

IrcPrivateMessageEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcPrivateMessageEvent)2 TwitchHostedEvent (me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent)2 Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 GameWispAnniversaryEvent (me.gloriouseggroll.quorrabot.event.gamewisp.GameWispAnniversaryEvent)1 GameWispSubscribeEvent (me.gloriouseggroll.quorrabot.event.gamewisp.GameWispSubscribeEvent)1 IrcChannelUserModeEvent (me.gloriouseggroll.quorrabot.event.irc.channel.IrcChannelUserModeEvent)1 IrcChannelMessageEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcChannelMessageEvent)1 IrcModerationEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcModerationEvent)1 NewBits (me.gloriouseggroll.quorrabot.event.twitch.bits.NewBits)1 TwitchFollowEvent (me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchFollowEvent)1