From 94830509e88120871a15b23c1b7699e50fbfb077 Mon Sep 17 00:00:00 2001 From: Curle Date: Sun, 4 Sep 2022 16:40:28 +0100 Subject: [PATCH 1/4] Implement support ticketing --- .../java/tk/sciwhiz12/concord/ChatBot.java | 18 ++++++-- .../tk/sciwhiz12/concord/ConcordConfig.java | 7 +++ .../concord/command/ConcordCommand.java | 44 +++++++++++++++++++ .../sciwhiz12/concord/util/Translations.java | 3 ++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/main/java/tk/sciwhiz12/concord/ChatBot.java b/src/main/java/tk/sciwhiz12/concord/ChatBot.java index 193fb45e..02f689dd 100644 --- a/src/main/java/tk/sciwhiz12/concord/ChatBot.java +++ b/src/main/java/tk/sciwhiz12/concord/ChatBot.java @@ -26,10 +26,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Activity; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.GuildChannel; +import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.events.ReadyEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.utils.messages.MessageRequest; @@ -141,4 +138,17 @@ boolean checkSatisfaction() { // Required permissions are there. All checks satisfied. return true; } + + public TextChannel getChatChannel() { + checkSatisfaction(); + final Guild guild = discord.getGuildById(ConcordConfig.GUILD_ID.get()); + return (TextChannel) guild.getGuildChannelById(ConcordConfig.CHAT_CHANNEL_ID.get()); + } + + public TextChannel getReportChannel() { + checkSatisfaction(); + final Guild guild = discord.getGuildById(ConcordConfig.GUILD_ID.get()); + return (TextChannel) guild.getGuildChannelById(ConcordConfig.REPORT_CHANNEL_ID.get()); + } + } diff --git a/src/main/java/tk/sciwhiz12/concord/ConcordConfig.java b/src/main/java/tk/sciwhiz12/concord/ConcordConfig.java index 7d93ff2d..28503ae0 100644 --- a/src/main/java/tk/sciwhiz12/concord/ConcordConfig.java +++ b/src/main/java/tk/sciwhiz12/concord/ConcordConfig.java @@ -42,6 +42,8 @@ public class ConcordConfig { public static final ForgeConfigSpec.ConfigValue CHAT_CHANNEL_ID; public static final ForgeConfigSpec.ConfigValue REPORT_CHANNEL_ID; + public static final ForgeConfigSpec.ConfigValue MODERATOR_ROLE_ID; + public static final ForgeConfigSpec.BooleanValue USE_CUSTOM_FONT; public static final ForgeConfigSpec.BooleanValue LAZY_TRANSLATIONS; public static final ForgeConfigSpec.EnumValue HIDE_CROWN; @@ -111,6 +113,11 @@ public static void register() { "If empty, reports will be disabled.") .define("report_channel_id", ""); + MODERATOR_ROLE_ID = builder.comment("The snowflake ID of the role that will be treated as a moderator role.", + "This role will be able to use Concord's Moderation slash commands on Discord - /kick, /ban, etc.", + "This should not be treated as an alternative to proper Discord permissions configuration, but exists as a safeguard so that random users may not ban you while you're setting up.") + .define("moderator_role_id", ""); + builder.pop(); } diff --git a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java index 5b9eddbf..036eb50a 100644 --- a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java +++ b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java @@ -24,13 +24,20 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Message; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.minecraftforge.event.RegisterCommandsEvent; import tk.sciwhiz12.concord.Concord; +import tk.sciwhiz12.concord.ConcordConfig; import tk.sciwhiz12.concord.util.Translations; +import java.awt.*; +import java.time.Instant; +import java.util.Collections; + import static net.minecraft.ChatFormatting.GREEN; import static net.minecraft.ChatFormatting.RED; import static net.minecraft.commands.Commands.literal; @@ -55,6 +62,9 @@ public static void onRegisterCommands(RegisterCommandsEvent event) { .then(literal("status") .executes(ConcordCommand::status) ) + .then(literal("support") + .executes(ConcordCommand::support) + ) ); } @@ -101,4 +111,38 @@ private static int status(CommandContext ctx) { ctx.getSource().sendSuccess(Translations.COMMAND_STATUS_PREFIX.resolvedComponent(source, result), false); return Command.SINGLE_SUCCESS; } + + private static int support(CommandContext ctx) { + CommandSourceStack source = ctx.getSource(); + + if (Concord.isEnabled() && !ConcordConfig.MODERATOR_ROLE_ID.get().isEmpty()) { + // We need to ping the moderators, and we can't do it from an embed, and we can't ping anyone unless it's explicitly told to, so.. + // Send the message with the mention + Concord.BOT.getReportChannel().sendMessage("<@&" + ConcordConfig.MODERATOR_ROLE_ID.get() + ">") + // Enable role mentions for just this message + .allowedMentions( + Collections.singleton(Message.MentionType.ROLE) + ) + // Allow the moderator role to be the one mentioned, for just this message + .mentionRoles( + ConcordConfig.MODERATOR_ROLE_ID.get() + ).queue(); + // Send the embed too + Concord.BOT.getReportChannel().sendMessageEmbeds( + new EmbedBuilder() + .setTitle("Support Requst") + .setDescription("A user has requested the support of a Server Administrator!") + .addField("User", source.getTextName(), false) + .setTimestamp(Instant.now()) + .setColor(Color.ORANGE) + .build() + ).queue(); + + ctx.getSource().sendSuccess(Translations.COMMAND_SUPPORT_SUCCESS.resolvedComponent(source), false); + } else { + ctx.getSource().sendSuccess(Translations.COMMAND_SUPPORT_DISABLED.resolvedComponent(source), false); + } + + return Command.SINGLE_SUCCESS; + } } diff --git a/src/main/java/tk/sciwhiz12/concord/util/Translations.java b/src/main/java/tk/sciwhiz12/concord/util/Translations.java index 761b35d8..5af9b554 100644 --- a/src/main/java/tk/sciwhiz12/concord/util/Translations.java +++ b/src/main/java/tk/sciwhiz12/concord/util/Translations.java @@ -63,6 +63,9 @@ public enum Translations implements Translation { COMMAND_RELOADING("command", "reload", "1.0.0", "Reloading discord integration..."), COMMAND_REPORT_STATUS("command", "report.status", "1.1.0", "Reporting users is currently %s"), COMMAND_REPORT_SUCCESS("command", "report.success", "1.1.0", "Submitted report for %s for reason: %s"), + + COMMAND_SUPPORT_DISABLED("command", "support.disabled", "1.1.0", "Sorry, but Concord is currently disabled, you may not send a support ticket at this time."), + COMMAND_SUPPORT_SUCCESS("command", "support.success", "1.1.0", "Support Ticket sent successfully."), COMMAND_STATUS_PREFIX("command", "status", "1.0.0", "Discord integration status: %s"), COMMAND_STATUS_ENABLED("command", "status.enabled", "1.0.0", "ENABLED"), COMMAND_STATUS_DISABLED("command", "status.disabled", "1.0.0", "DISABLED"); From b6636946aef6709d5477f5099eaf8e490b3e3a72 Mon Sep 17 00:00:00 2001 From: Curle Date: Sun, 4 Sep 2022 16:42:58 +0100 Subject: [PATCH 2/4] Append the embed to the message, rather than sending two --- .../tk/sciwhiz12/concord/command/ConcordCommand.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java index 036eb50a..7c8bc936 100644 --- a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java +++ b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java @@ -126,17 +126,15 @@ private static int support(CommandContext ctx) { // Allow the moderator role to be the one mentioned, for just this message .mentionRoles( ConcordConfig.MODERATOR_ROLE_ID.get() - ).queue(); - // Send the embed too - Concord.BOT.getReportChannel().sendMessageEmbeds( - new EmbedBuilder() + ) + // And set context too. + .setEmbeds(new EmbedBuilder() .setTitle("Support Requst") .setDescription("A user has requested the support of a Server Administrator!") .addField("User", source.getTextName(), false) .setTimestamp(Instant.now()) .setColor(Color.ORANGE) - .build() - ).queue(); + .build()).queue(); ctx.getSource().sendSuccess(Translations.COMMAND_SUPPORT_SUCCESS.resolvedComponent(source), false); } else { From b3209763b2cbd1d7815e062eb22713d3fc1a034e Mon Sep 17 00:00:00 2001 From: Curle Date: Sun, 4 Sep 2022 16:55:47 +0100 Subject: [PATCH 3/4] Update to JDA5 stuff --- .../java/tk/sciwhiz12/concord/command/ConcordCommand.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java index 7c8bc936..a7e55c29 100644 --- a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java +++ b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java @@ -119,14 +119,10 @@ private static int support(CommandContext ctx) { // We need to ping the moderators, and we can't do it from an embed, and we can't ping anyone unless it's explicitly told to, so.. // Send the message with the mention Concord.BOT.getReportChannel().sendMessage("<@&" + ConcordConfig.MODERATOR_ROLE_ID.get() + ">") - // Enable role mentions for just this message - .allowedMentions( + .setAllowedMentions( Collections.singleton(Message.MentionType.ROLE) ) - // Allow the moderator role to be the one mentioned, for just this message - .mentionRoles( - ConcordConfig.MODERATOR_ROLE_ID.get() - ) + .mentionRoles(ConcordConfig.MODERATOR_ROLE_ID.get()) // And set context too. .setEmbeds(new EmbedBuilder() .setTitle("Support Requst") From 2db65539d3ce95c2608ce790308d436e939cae55 Mon Sep 17 00:00:00 2001 From: Curle Date: Sun, 4 Sep 2022 17:26:04 +0100 Subject: [PATCH 4/4] Add reasons to the pings --- .../sciwhiz12/concord/command/ConcordCommand.java | 15 +++++++++++---- .../tk/sciwhiz12/concord/util/Translations.java | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java index a7e55c29..5b0a5b74 100644 --- a/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java +++ b/src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java @@ -23,11 +23,15 @@ package tk.sciwhiz12.concord.command; import com.mojang.brigadier.Command; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.sun.jdi.connect.Connector; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.network.chat.Component; import net.minecraftforge.event.RegisterCommandsEvent; import tk.sciwhiz12.concord.Concord; @@ -63,8 +67,10 @@ public static void onRegisterCommands(RegisterCommandsEvent event) { .executes(ConcordCommand::status) ) .then(literal("support") - .executes(ConcordCommand::support) - ) + .executes((ctx) -> ConcordCommand.support(ctx, Translations.COMMAND_SUPPORT_NO_REASON.resolvedComponent(ctx.getSource()))) + .then(Commands.argument("reason", MessageArgument.message()) + .executes((ctx) -> ConcordCommand.support(ctx, MessageArgument.getMessage(ctx, "reason"))) + )) ); } @@ -112,7 +118,7 @@ private static int status(CommandContext ctx) { return Command.SINGLE_SUCCESS; } - private static int support(CommandContext ctx) { + private static int support(CommandContext ctx, Component reason) { CommandSourceStack source = ctx.getSource(); if (Concord.isEnabled() && !ConcordConfig.MODERATOR_ROLE_ID.get().isEmpty()) { @@ -125,9 +131,10 @@ private static int support(CommandContext ctx) { .mentionRoles(ConcordConfig.MODERATOR_ROLE_ID.get()) // And set context too. .setEmbeds(new EmbedBuilder() - .setTitle("Support Requst") + .setTitle("Support Request") .setDescription("A user has requested the support of a Server Administrator!") .addField("User", source.getTextName(), false) + .addField("Reason", reason.getString(), false) .setTimestamp(Instant.now()) .setColor(Color.ORANGE) .build()).queue(); diff --git a/src/main/java/tk/sciwhiz12/concord/util/Translations.java b/src/main/java/tk/sciwhiz12/concord/util/Translations.java index 5af9b554..9c7ae7b9 100644 --- a/src/main/java/tk/sciwhiz12/concord/util/Translations.java +++ b/src/main/java/tk/sciwhiz12/concord/util/Translations.java @@ -66,6 +66,7 @@ public enum Translations implements Translation { COMMAND_SUPPORT_DISABLED("command", "support.disabled", "1.1.0", "Sorry, but Concord is currently disabled, you may not send a support ticket at this time."), COMMAND_SUPPORT_SUCCESS("command", "support.success", "1.1.0", "Support Ticket sent successfully."), + COMMAND_SUPPORT_NO_REASON("command", "support.noreason", "1.1.0", "No Reason Provided"), COMMAND_STATUS_PREFIX("command", "status", "1.0.0", "Discord integration status: %s"), COMMAND_STATUS_ENABLED("command", "status.enabled", "1.0.0", "ENABLED"), COMMAND_STATUS_DISABLED("command", "status.disabled", "1.0.0", "DISABLED");