From 43e31ddf63edae041fca19cd4422b59c053a522f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 27 Apr 2019 20:30:12 -0700 Subject: [PATCH] Added twitterNotification method. --- .../net/thauvin/erik/mobibot/Mobibot.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index 93c75c2..3ad36c0 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -818,21 +818,7 @@ public class Mobibot extends PircBot { public final void joinChannel() { joinChannel(ircChannel); - if (twitterModule.isEnabled() && Utils.isValidString(twitterHandle)) { - new Thread(() -> { - try { - twitterModule.post( - twitterHandle, - getName() + ReleaseInfo.VERSION + " has joined " + ircChannel, - true); - } catch (ModuleException e) { - if (logger.isWarnEnabled()) { - logger.warn( - "Failed to notify " + twitterHandle + " of joining " + ircChannel + " on Twitter.", e); - } - } - }).start(); - } + twitterNotification("has joined " + ircChannel); } /** @@ -1273,6 +1259,7 @@ public class Mobibot extends PircBot { System.exit(0); } else if (Commands.DIE_CMD.equals(cmd) && isOp(sender)) { send(ircChannel, sender + " has just signed my death sentence."); + twitterNotification("killed by " + sender + " on " + ircChannel); saveEntries(true); sleep(3); quitServer("The Bot Is Out There!"); @@ -1593,6 +1580,28 @@ public class Mobibot extends PircBot { } } + /** + * Send a notification to the registered Twitter handle. + * + * @param msg The twitter message. + */ + final void twitterNotification(final String msg) { + if (twitterModule.isEnabled() && Utils.isValidString(twitterHandle)) { + new Thread(() -> { + try { + twitterModule.post( + twitterHandle, + getName() + ' ' + ReleaseInfo.VERSION + " " + msg, true); + } catch (ModuleException e) { + if (logger.isWarnEnabled()) { + logger.warn( + "Failed to notify @" + twitterHandle + ": " + msg, e); + } + } + }).start(); + } + } + /** * Responds with the users on a channel. *