Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support ticketing #8

Open
wants to merge 4 commits into
base: dev/1.19.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/java/tk/sciwhiz12/concord/ChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

}
7 changes: 7 additions & 0 deletions src/main/java/tk/sciwhiz12/concord/ConcordConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class ConcordConfig {
public static final ForgeConfigSpec.ConfigValue<String> CHAT_CHANNEL_ID;
public static final ForgeConfigSpec.ConfigValue<String> REPORT_CHANNEL_ID;

public static final ForgeConfigSpec.ConfigValue<String> MODERATOR_ROLE_ID;

public static final ForgeConfigSpec.BooleanValue USE_CUSTOM_FONT;
public static final ForgeConfigSpec.BooleanValue LAZY_TRANSLATIONS;
public static final ForgeConfigSpec.EnumValue<CrownVisibility> HIDE_CROWN;
Expand Down Expand Up @@ -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();
}

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/tk/sciwhiz12/concord/command/ConcordCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@
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;
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;
Expand All @@ -55,6 +66,11 @@ public static void onRegisterCommands(RegisterCommandsEvent event) {
.then(literal("status")
.executes(ConcordCommand::status)
)
.then(literal("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")))
))
);
}

Expand Down Expand Up @@ -101,4 +117,33 @@ private static int status(CommandContext<CommandSourceStack> ctx) {
ctx.getSource().sendSuccess(Translations.COMMAND_STATUS_PREFIX.resolvedComponent(source, result), false);
return Command.SINGLE_SUCCESS;
}

private static int support(CommandContext<CommandSourceStack> ctx, Component reason) {
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() + ">")
.setAllowedMentions(
Collections.singleton(Message.MentionType.ROLE)
)
.mentionRoles(ConcordConfig.MODERATOR_ROLE_ID.get())
// And set context too.
.setEmbeds(new EmbedBuilder()
.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();

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;
}
}
4 changes: 4 additions & 0 deletions src/main/java/tk/sciwhiz12/concord/util/Translations.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ 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_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");
Expand Down