Search in sources :

Example 1 with TwitchFollowEvent

use of me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchFollowEvent 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 TwitchFollowEvent

use of me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchFollowEvent in project quorrabot by GloriousEggroll.

the class FollowersCache method quickUpdate.

public int quickUpdate(String channel) throws Exception {
    JSONObject j = TwitchAPIv3.instance().GetChannelFollows(channel, 100, 0, false);
    if (j.getBoolean("_success")) {
        if (j.getInt("_http") == 200) {
            int i = j.getInt("_total");
            Map<String, JSONObject> newCache = Maps.newHashMap();
            JSONArray followers = j.getJSONArray("follows");
            for (int b = 0; b < followers.length(); b++) {
                JSONObject follower = followers.getJSONObject(b);
                newCache.put(follower.getJSONObject("user").getString("name"), follower);
            }
            for (String key : newCache.keySet()) {
                if (cache == null || !cache.containsKey(key)) {
                    cache.put(key, newCache.get(key));
                    EventBus.instance().post(new TwitchFollowEvent(key, Quorrabot.getChannel(this.channel)));
                }
            }
            if (cache != null) {
                for (String key : cache.keySet()) {
                    if (!newCache.containsKey(key)) {
                        EventBus.instance().post(new TwitchUnfollowEvent(key, Quorrabot.getChannel(this.channel)));
                    }
                }
            }
            this.count = cache.size();
            return i;
        } else {
            throw new Exception("[HTTPErrorException] HTTP " + j.getInt("_http") + " " + j.getString("error") + ". req=" + j.getString("_type") + " " + j.getString("_url") + " " + j.getString("_post") + "   " + (j.has("message") && !j.isNull("message") ? "message=" + j.getString("message") : "content=" + j.getString("_content")));
        }
    } else {
        throw new Exception("[" + j.getString("_exception") + "] " + j.getString("_exceptionMessage"));
    }
}
Also used : TwitchFollowEvent(me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchFollowEvent) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TwitchUnfollowEvent(me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchUnfollowEvent)

Aggregations

TwitchFollowEvent (me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchFollowEvent)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 IrcPrivateMessageEvent (me.gloriouseggroll.quorrabot.event.irc.message.IrcPrivateMessageEvent)1 TwitchUnfollowEvent (me.gloriouseggroll.quorrabot.event.twitch.follower.TwitchUnfollowEvent)1 TwitchHostedEvent (me.gloriouseggroll.quorrabot.event.twitch.host.TwitchHostedEvent)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1