generated from nhcarrigan/template
feat: handle join roles
This commit is contained in:
parent
34c6d2d189
commit
1d2ae0e5a1
@ -59,6 +59,7 @@ model configs {
|
|||||||
modLogChannel String @default("")
|
modLogChannel String @default("")
|
||||||
eventLogChannel String @default("")
|
eventLogChannel String @default("")
|
||||||
messageReportChannel String @default("")
|
messageReportChannel String @default("")
|
||||||
|
joinRole String @default("")
|
||||||
|
|
||||||
@@unique([serverId], map: "serverId")
|
@@unique([serverId], map: "serverId")
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,25 @@ import {
|
|||||||
|
|
||||||
import { logChannelChoices } from "../config/LogChannelChoices";
|
import { logChannelChoices } from "../config/LogChannelChoices";
|
||||||
import { Command } from "../interfaces/Command";
|
import { Command } from "../interfaces/Command";
|
||||||
|
import { CommandHandler } from "../interfaces/CommandHandler";
|
||||||
import { getConfig } from "../modules/data/getConfig";
|
import { getConfig } from "../modules/data/getConfig";
|
||||||
import { handleAppealLink } from "../modules/subcommands/config/handleAppealLink";
|
import { handleAppealLink } from "../modules/subcommands/config/handleAppealLink";
|
||||||
import { handleInviteLink } from "../modules/subcommands/config/handleInviteLink";
|
import { handleInviteLink } from "../modules/subcommands/config/handleInviteLink";
|
||||||
|
import { handleJoinRole } from "../modules/subcommands/config/handleJoinRole";
|
||||||
import { handleList } from "../modules/subcommands/config/handleList";
|
import { handleList } from "../modules/subcommands/config/handleList";
|
||||||
import { handleLogging } from "../modules/subcommands/config/handleLogging";
|
import { handleLogging } from "../modules/subcommands/config/handleLogging";
|
||||||
import { handleRole } from "../modules/subcommands/config/handleRole";
|
import { handleRole } from "../modules/subcommands/config/handleRole";
|
||||||
import { errorHandler } from "../utils/errorHandler";
|
import { errorHandler } from "../utils/errorHandler";
|
||||||
|
|
||||||
|
const handlers: { [key: string]: CommandHandler } = {
|
||||||
|
list: handleList,
|
||||||
|
"invite-link": handleInviteLink,
|
||||||
|
"appeal-link": handleAppealLink,
|
||||||
|
logging: handleLogging,
|
||||||
|
role: handleRole,
|
||||||
|
"join-role": handleJoinRole
|
||||||
|
};
|
||||||
|
|
||||||
export const config: Command = {
|
export const config: Command = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("config")
|
.setName("config")
|
||||||
@ -79,6 +90,17 @@ export const config: Command = {
|
|||||||
.setDescription("The role to toggle.")
|
.setDescription("The role to toggle.")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
.addSubcommand(
|
||||||
|
new SlashCommandSubcommandBuilder()
|
||||||
|
.setName("join-role")
|
||||||
|
.setDescription("Configure a role to be assigned when a member joins.")
|
||||||
|
.addRoleOption((o) =>
|
||||||
|
o
|
||||||
|
.setName("role")
|
||||||
|
.setDescription("The role to assign.")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
run: async (bot, interaction) => {
|
run: async (bot, interaction) => {
|
||||||
try {
|
try {
|
||||||
@ -105,27 +127,15 @@ export const config: Command = {
|
|||||||
|
|
||||||
const subcommand = interaction.options.getSubcommand();
|
const subcommand = interaction.options.getSubcommand();
|
||||||
|
|
||||||
switch (subcommand) {
|
const handler = handlers[subcommand];
|
||||||
case "list":
|
|
||||||
await handleList(bot, interaction, config);
|
if (handler) {
|
||||||
break;
|
await handler(bot, interaction, config);
|
||||||
case "logging":
|
return;
|
||||||
await handleLogging(bot, interaction, config);
|
}
|
||||||
break;
|
|
||||||
case "invite-link":
|
|
||||||
await handleInviteLink(bot, interaction, config);
|
|
||||||
break;
|
|
||||||
case "appeal-link":
|
|
||||||
await handleAppealLink(bot, interaction, config);
|
|
||||||
break;
|
|
||||||
case "roles":
|
|
||||||
await handleRole(bot, interaction, config);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: "This is an invalid subcommand. Please contact Naomi."
|
content: "This is an invalid subcommand. Please contact Naomi."
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const id = await errorHandler(bot, "config command", err);
|
const id = await errorHandler(bot, "config command", err);
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
|
@ -17,6 +17,10 @@ export const onMemberAdd = async (bot: ExtendedClient, member: GuildMember) => {
|
|||||||
|
|
||||||
const config = await getConfig(bot, guild.id);
|
const config = await getConfig(bot, guild.id);
|
||||||
|
|
||||||
|
if (config.joinRole) {
|
||||||
|
await member.roles.add(config.joinRole).catch(() => null);
|
||||||
|
}
|
||||||
|
|
||||||
if (!config.eventLogChannel) {
|
if (!config.eventLogChannel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
34
src/modules/subcommands/config/handleJoinRole.ts
Normal file
34
src/modules/subcommands/config/handleJoinRole.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { CommandHandler } from "../../../interfaces/CommandHandler";
|
||||||
|
import { errorHandler } from "../../../utils/errorHandler";
|
||||||
|
import { setConfig } from "../../data/setConfig";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the role to be assigned when a member joins.
|
||||||
|
*/
|
||||||
|
export const handleJoinRole: CommandHandler = async (bot, interaction) => {
|
||||||
|
try {
|
||||||
|
const role = interaction.options.getRole("role", true);
|
||||||
|
|
||||||
|
const success = await setConfig(
|
||||||
|
bot,
|
||||||
|
interaction.guild.id,
|
||||||
|
"joinRole",
|
||||||
|
role.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
await interaction.editReply({
|
||||||
|
content: `Members will be given ${role.toString()} when they join..`
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await interaction.editReply({
|
||||||
|
content: "Failed to set the settings."
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
const id = await errorHandler(bot, "config join-role subcommand", err);
|
||||||
|
await interaction.editReply({
|
||||||
|
content: `Something went wrong. Please [join our support server](https://chat.naomi.lgbt) and provide this ID: \`${id}\``
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user