use of com.google.common.eventbus.Subscribe in project SmartCity-Market by TechnionYP5777.
the class CustomerMainScreen method smartcodeScanned.
@Subscribe
public void smartcodeScanned(SmartcodeScanEvent ¢) {
SmartCode smartCode = ¢.getSmarCode();
scannedSmartCode = smartCode;
smartcodeScannedHandler();
}
use of com.google.common.eventbus.Subscribe in project graylog2-server by Graylog2.
the class InputEventListener method inputCreated.
@Subscribe
public void inputCreated(InputCreated inputCreatedEvent) {
LOG.debug("Input created/changed: " + inputCreatedEvent.id());
final Input input;
try {
input = inputService.find(inputCreatedEvent.id());
} catch (NotFoundException e) {
LOG.warn("Received InputCreated event but could not find Input: ", e);
return;
}
final IOState<MessageInput> inputState = inputRegistry.getInputState(inputCreatedEvent.id());
if (inputState != null) {
inputRegistry.remove(inputState);
}
if (!input.isGlobal() && !this.nodeId.toString().equals(input.getNodeId())) {
return;
}
final MessageInput messageInput;
try {
messageInput = inputService.getMessageInput(input);
messageInput.initialize();
} catch (NoSuchInputTypeException e) {
LOG.warn("Newly created input is of invalid type: " + input.getType(), e);
return;
}
final IOState<MessageInput> newInputState = inputLauncher.launch(messageInput);
inputRegistry.add(newInputState);
}
use of com.google.common.eventbus.Subscribe in project graylog2-server by Graylog2.
the class InputStateListener method inputStateChanged.
@Subscribe
public void inputStateChanged(IOStateChangedEvent<MessageInput> event) {
final IOState<MessageInput> state = event.changedState();
final MessageInput input = state.getStoppable();
switch(event.newState()) {
case FAILED:
activityWriter.write(new Activity(state.getDetailedMessage(), InputRegistry.class));
Notification notification = notificationService.buildNow();
notification.addType(Notification.Type.INPUT_FAILED_TO_START).addSeverity(Notification.Severity.NORMAL);
notification.addNode(serverStatus.getNodeId().toString());
notification.addDetail("input_id", input.getId());
notification.addDetail("reason", state.getDetailedMessage());
notificationService.publishIfFirst(notification);
break;
case RUNNING:
notificationService.fixed(Notification.Type.NO_INPUT_RUNNING);
default:
final String msg = "Input [" + input.getName() + "/" + input.getId() + "] is now " + event.newState().toString();
activityWriter.write(new Activity(msg, InputStateListener.class));
break;
}
LOG.debug("Input State of [{}/{}] changed: {} -> {}", input.getTitle(), input.getId(), event.oldState(), event.newState());
LOG.info("Input [{}/{}] is now {}", input.getName(), input.getId(), event.newState());
}
use of com.google.common.eventbus.Subscribe in project graylog2-server by Graylog2.
the class StartPageCleanupListener method removeStartpageReferencesIfDashboardDeleted.
@Subscribe
@SuppressWarnings("unused")
public void removeStartpageReferencesIfDashboardDeleted(DashboardDeletedEvent dashboardDeletedEvent) {
final Startpage deletedStartpage = Startpage.create("dashboard", dashboardDeletedEvent.dashboardId());
resetReferencesToStartpage(deletedStartpage);
}
use of com.google.common.eventbus.Subscribe 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);
}
Aggregations