use of me.gloriouseggroll.quorrabot.event.gamewisp.GameWispSubscribeEvent 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);
}
use of me.gloriouseggroll.quorrabot.event.gamewisp.GameWispSubscribeEvent in project quorrabot by GloriousEggroll.
the class SingularityAPI method StartService.
public void StartService() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
try {
SSLContext mySSLContext = SSLContext.getInstance("TLS");
mySSLContext.init(null, null, null);
IO.Options opts = new IO.Options();
opts.sslContext = mySSLContext;
opts.hostnameVerifier = new NullHostnameVerifier();
webSocket = IO.socket(apiURL);
webSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
//com.gmt2001.Console.out.println("GameWisp API: Connected to Singularity");
webSocket.emit("authentication", new JSONObject().put("key", gwIdentifier).put("access_token", AccessToken));
}
});
webSocket.on("unauthorized", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject jsonObject = new JSONObject(args[0].toString());
com.gmt2001.Console.err.println("GameWisp API: Authorization Failed: " + jsonObject.getString("message"));
com.gmt2001.Console.err.println("Token: " + AccessToken + " Session ID: " + SessionID + " Client ID: " + gwIdentifier);
}
});
webSocket.on("authenticated", new Emitter.Listener() {
@Override
public void call(Object... args) {
//com.gmt2001.Console.out.println("GameWisp API: Authenticated");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("session")) {
com.gmt2001.Console.err.println("GameWisp API: Missing Session in Authenticated Return JSON");
Authenticated = false;
return;
}
SessionID = jsonObject.getString("session");
Authenticated = true;
}
});
webSocket.on("app-channel-connected", new Emitter.Listener() {
@Override
public void call(Object... args) {
if (Authenticated) {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println("GameWisp API: Connected to Channel");
} else {
com.gmt2001.Console.out.println("GameWisp API: Connected and Ready for Requests");
}
ChannelConnected = true;
} else {
com.gmt2001.Console.out.println("GameWisp API: Connected to Channel; Missing Session ID; Unusable Session");
ChannelConnected = false;
}
}
});
webSocket.on("subscriber-new", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-new received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.getJSONObject("data").has("tier")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("tier").has("level")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("usernames").getString("twitch");
int tier = jsonObject.getJSONObject("data").getJSONObject("tier").getInt("level");
EventBus.instance().post(new GameWispSubscribeEvent(username, tier));
}
});
webSocket.on("subscriber-anniversary", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-anniversary received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("subscriber")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("subscriber").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("subscriber").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.getJSONObject("data").has("month_count")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("subscriber").getJSONObject("usernames").getString("twitch");
int tier = jsonObject.getJSONObject("data").getJSONObject("subscriber").getJSONObject("tier").getInt("level");
int months = jsonObject.getJSONObject("data").getInt("month_count");
EventBus.instance().post(new GameWispAnniversaryEvent(username, months, tier));
}
});
webSocket.on("subscriber-benefits-change", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-benefits-change received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.has("tier")) {
return;
}
if (!jsonObject.getJSONObject("tier").has("level")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("usernames").getString("twitch");
int tier = jsonObject.getJSONObject("tier").getInt("level");
EventBus.instance().post(new GameWispBenefitsEvent(username, tier));
}
});
/**
* Status Change Values:
* https://gamewisp.readme.io/docs/subscriber-new active - a
* currently active subscriber trial - a subscriber on a trial code
* grace_period - a canceled subscriber that is still received
* benefits billing_grace_period - a canceled subscriber still
* receiving benefits that was canceled due to a payment processing
* error inactive - a subscriber that is canceled and receiving no
* benefits twitch - a subscriber that is receiving free benefits
* from a partnered Twitch streamer.
*/
webSocket.on("subscriber-status-change", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-status-changed received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.getJSONObject("data").has("status")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("usernames").getString("twitch");
String status = jsonObject.getJSONObject("data").getString("status");
EventBus.instance().post(new GameWispChangeEvent(username, status));
}
});
webSocket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: Disconnected");
}
});
webSocket.connect();
} catch (Exception ex) {
com.gmt2001.Console.err.println("GameWisp API: Exception: " + ex.getMessage());
}
}
Aggregations