From c59c0629a7824a9691c1df252f53934223f2ef6f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 16 Jan 2023 05:23:31 -0500 Subject: [PATCH] Generic ChatChannelHandler created. --- src/discord/handlers/ChatChannelHandler.java | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/discord/handlers/ChatChannelHandler.java diff --git a/src/discord/handlers/ChatChannelHandler.java b/src/discord/handlers/ChatChannelHandler.java new file mode 100644 index 00000000..6c59dd28 --- /dev/null +++ b/src/discord/handlers/ChatChannelHandler.java @@ -0,0 +1,57 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package discord.handlers; + +import discord.ChatChannel; +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 ChatChannelHandler { + + public static void handleRequest(ChatChannel chatChannel, 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 (chatChannel.textChannel.canTalk()) + chatChannel.textChannel.sendMessage(outString).queue(); + + Logger.info(event.getAuthor().getName() + "general: " + chatText); + + } +}