From 920fcd4b8ec09056602a985353e8302bb6df8783 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 16 Jan 2023 05:28:35 -0500 Subject: [PATCH] Generic ChatChannelHandler created. --- src/discord/MagicBot.java | 12 ++-- .../handlers/AnnounceChannelHandler.java | 55 ------------------ src/discord/handlers/ChangeLogHandler.java | 44 --------------- .../handlers/ForToFixChannelHandler.java | 56 ------------------- .../handlers/GeneralChannelHandler.java | 56 ------------------- .../handlers/PoliticalChannelHandler.java | 55 ------------------ .../handlers/RecruitChannelHandler.java | 56 ------------------- 7 files changed, 6 insertions(+), 328 deletions(-) delete mode 100644 src/discord/handlers/AnnounceChannelHandler.java delete mode 100644 src/discord/handlers/ChangeLogHandler.java delete mode 100644 src/discord/handlers/ForToFixChannelHandler.java delete mode 100644 src/discord/handlers/GeneralChannelHandler.java delete mode 100644 src/discord/handlers/PoliticalChannelHandler.java delete mode 100644 src/discord/handlers/RecruitChannelHandler.java diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 8be071ee..9bf6b233 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -182,22 +182,22 @@ public class MagicBot extends ListenerAdapter { PasswordChangeHandler.handleRequest(event, args); break; case "#changelog": - ChangeLogHandler.handleRequest(event, args); + ChatChannelHandler.handleRequest(ChatChannel.CHANGELOG, event, args); break; case "#general": - GeneralChannelHandler.handleRequest(event, args); + ChatChannelHandler.handleRequest(ChatChannel.GENERAL, event, args); break; case "#politics": - PoliticalChannelHandler.handleRequest(event, args); + ChatChannelHandler.handleRequest(ChatChannel.POLITICAL, event, args); break; case "#announce": - AnnounceChannelHandler.handleRequest(event, args); + ChatChannelHandler.handleRequest(ChatChannel.ANNOUNCE, event, args); break; case "#bug": - ForToFixChannelHandler.handleRequest(event, args); + ChatChannelHandler.handleRequest(ChatChannel.FORTOFIX, event, args); break; case "#recruit": - RecruitChannelHandler.handleRequest(event, args); + ChatChannelHandler.handleRequest(ChatChannel.RECRUIT, event, args); break; case "#lookup": LookupRequestHandler.handleRequest(event, args); diff --git a/src/discord/handlers/AnnounceChannelHandler.java b/src/discord/handlers/AnnounceChannelHandler.java deleted file mode 100644 index be534e6b..00000000 --- a/src/discord/handlers/AnnounceChannelHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package discord.handlers; - -import discord.MagicBot; -import discord.RobotSpeak; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.pmw.tinylog.Logger; - -import static discord.ChatChannel.ANNOUNCE; - -public class AnnounceChannelHandler { - - public static void handleRequest(MessageReceivedEvent event, String[] args) { - - String chatText; - String outString; - - // Early exit if database unavailable or is not an admin - - if (MagicBot.isAdminEvent(event) == false) - return; - - // Nothing to send? - - if (args.length == 0) - return; - - // Convert argument array into string; - - chatText = String.join(" ", args); - - // Build String - - if (chatText.startsWith("-r ")) - outString = - "```\n" + "Hello Players \n\n" + - chatText.substring(3) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - else outString = chatText; - - // Write string to announce channel - - if (ANNOUNCE.textChannel.canTalk()) - ANNOUNCE.textChannel.sendMessage(outString).queue(); - - Logger.info(event.getAuthor().getName() + " announce: " + chatText); - } -} diff --git a/src/discord/handlers/ChangeLogHandler.java b/src/discord/handlers/ChangeLogHandler.java deleted file mode 100644 index 73ec2710..00000000 --- a/src/discord/handlers/ChangeLogHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package discord.handlers; - -import discord.MagicBot; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.pmw.tinylog.Logger; - -import static discord.ChatChannel.CHANGELOG; - -public class ChangeLogHandler { - - public static void handleRequest(MessageReceivedEvent event, String[] args) { - - String outString; - - // Early exit if database unavailable or is not an admin - - if (MagicBot.isAdminEvent(event) == false) - return; - - // Nothing to send? - - if (args.length == 0) - return; - - // Convert argument array into string; - - outString = String.join(" ", args); - - // Write string to changelog channel - - if (CHANGELOG.textChannel.canTalk()) - CHANGELOG.textChannel.sendMessage(outString).queue(); - - Logger.info(event.getAuthor().getName() + " changelog entry: " + outString); - } -} diff --git a/src/discord/handlers/ForToFixChannelHandler.java b/src/discord/handlers/ForToFixChannelHandler.java deleted file mode 100644 index 8af07639..00000000 --- a/src/discord/handlers/ForToFixChannelHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package discord.handlers; - -import discord.MagicBot; -import discord.RobotSpeak; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.pmw.tinylog.Logger; - -import static discord.ChatChannel.FORTOFIX; - -public class ForToFixChannelHandler { - - public static void handleRequest(MessageReceivedEvent event, String[] args) { - - String chatText; - String outString; - - // Early exit if database unavailable or is not an admin - - if (MagicBot.isAdminEvent(event) == false) - return; - - // Nothing to send? - - if (args.length == 0) - return; - - // Convert argument array into string; - - chatText = String.join(" ", args); - - // Build String - - if (chatText.startsWith("-r ")) - outString = - "```\n" + "Hello Players \n\n" + - chatText.substring(3) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - else outString = chatText; - - // Write string to changelog channel - - if (FORTOFIX.textChannel.canTalk()) - FORTOFIX.textChannel.sendMessage(outString).queue(); - - Logger.info(event.getAuthor().getName() + "fortofix: " + chatText); - - } -} diff --git a/src/discord/handlers/GeneralChannelHandler.java b/src/discord/handlers/GeneralChannelHandler.java deleted file mode 100644 index 90e36c2c..00000000 --- a/src/discord/handlers/GeneralChannelHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package discord.handlers; - -import discord.MagicBot; -import discord.RobotSpeak; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.pmw.tinylog.Logger; - -import static discord.ChatChannel.GENERAL; - -public class GeneralChannelHandler { - - public static void handleRequest(MessageReceivedEvent event, String[] args) { - - String chatText; - String outString; - - // Early exit if database unavailable or is not an admin - - if (MagicBot.isAdminEvent(event) == false) - return; - - // Nothing to send? - - if (args.length == 0) - return; - - // Convert argument array into string; - - chatText = String.join(" ", args); - - // Build String - - if (chatText.startsWith("-r ")) - outString = - "```\n" + "Hello Players \n\n" + - chatText.substring(3) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - else outString = chatText; - - // Write string to changelog channel - - if (GENERAL.textChannel.canTalk()) - GENERAL.textChannel.sendMessage(outString).queue(); - - Logger.info(event.getAuthor().getName() + "general: " + chatText); - - } -} diff --git a/src/discord/handlers/PoliticalChannelHandler.java b/src/discord/handlers/PoliticalChannelHandler.java deleted file mode 100644 index 1b046407..00000000 --- a/src/discord/handlers/PoliticalChannelHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package discord.handlers; - -import discord.MagicBot; -import discord.RobotSpeak; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.pmw.tinylog.Logger; - -import static discord.ChatChannel.POLITICAL; - -public class PoliticalChannelHandler { - - public static void handleRequest(MessageReceivedEvent event, String[] args) { - - String chatText; - String outString; - - // Early exit if database unavailable or is not an admin - - if (MagicBot.isAdminEvent(event) == false) - return; - - // Nothing to send? - - if (args.length == 0) - return; - - // Convert argument array into string; - - chatText = String.join(" ", args); - - // Build String - - if (chatText.startsWith("-r ")) - outString = - "```\n" + "Hello Players \n\n" + - chatText.substring(3) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - else outString = chatText; - - // Write string to changelog channel - - if (POLITICAL.textChannel.canTalk()) - POLITICAL.textChannel.sendMessage(outString).queue(); - - Logger.info(event.getAuthor().getName() + " politics: " + chatText); - } -} diff --git a/src/discord/handlers/RecruitChannelHandler.java b/src/discord/handlers/RecruitChannelHandler.java deleted file mode 100644 index 798c1588..00000000 --- a/src/discord/handlers/RecruitChannelHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package discord.handlers; - -import discord.MagicBot; -import discord.RobotSpeak; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.pmw.tinylog.Logger; - -import static discord.ChatChannel.RECRUIT; - -public class RecruitChannelHandler { - - public static void handleRequest(MessageReceivedEvent event, String[] args) { - - String chatText; - String outString; - - // Early exit if database unavailable or is not an admin - - if (MagicBot.isAdminEvent(event) == false) - return; - - // Nothing to send? - - if (args.length == 0) - return; - - // Convert argument array into string; - - chatText = String.join(" ", args); - - // Build String - - if (chatText.startsWith("-r ")) - outString = - "```\n" + "Hello Players \n\n" + - chatText.substring(3) + "\n\n" + - RobotSpeak.getRobotSpeak() + "\n```"; - else outString = chatText; - - // Write string to changelog channel - - if (RECRUIT.textChannel.canTalk()) - RECRUIT.textChannel.sendMessage(outString).queue(); - - Logger.info(event.getAuthor().getName() + "recruit: " + chatText); - - } -}