From 985db250d95861a4398f84ccbeb47ed028e1b869 Mon Sep 17 00:00:00 2001 From: Alyxia Sother Date: Sun, 15 Aug 2021 22:42:27 +0200 Subject: [PATCH] Add autorole system See https://lists.sr.ht/~keanucode/travbot-v3/%3C20210815204227.2899-1-lexisoth2005%40gmail.com%3E/raw --- src/commands/system/admin.ts | 25 +++++++++++++++++++++++++ src/modules/guildMemberAdd.ts | 6 +++++- src/structures.ts | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/commands/system/admin.ts b/src/commands/system/admin.ts index 399c5a1..f32125a 100644 --- a/src/commands/system/admin.ts +++ b/src/commands/system/admin.ts @@ -61,6 +61,31 @@ export default new NamedCommand({ }) }) }), + autoroles: new NamedCommand({ + description: "Configure your server's autoroles.", + usage: "", + async run({send, guild}) { + Storage.getGuild(guild!.id).autoRoles = []; + Storage.save(); + send("Reset this server's autoroles."); + }, + id: "role", + any: new RestCommand({ + description: "The roles to set as autoroles.", + async run({send, guild, args}) { + const guildd = Storage.getGuild(guild!.id); + for (const role of args) { + if (!role.toString().match(/^<@&(\d{17,})>$/)) { + return send("Not all arguments are a role mention!"); + } + const id = role.toString().match(/^<@&(\d{17,})>$/)![1]; + guildd.autoRoles!.push(id); + } + Storage.save(); + return send("Saved."); + } + }) + }), welcome: new NamedCommand({ description: "Configure your server's welcome settings for the bot.", usage: "type/channel <...>", diff --git a/src/modules/guildMemberAdd.ts b/src/modules/guildMemberAdd.ts index 2d441ac..8e41bf6 100644 --- a/src/modules/guildMemberAdd.ts +++ b/src/modules/guildMemberAdd.ts @@ -16,7 +16,11 @@ function applyText(canvas: Canvas, text: string) { } client.on("guildMemberAdd", async (member) => { - const {welcomeType, welcomeChannel, welcomeMessage} = Storage.getGuild(member.guild.id); + const {welcomeType, welcomeChannel, welcomeMessage, autoRoles} = Storage.getGuild(member.guild.id); + + if (autoRoles) { + member.roles.add(autoRoles); + } if (welcomeChannel) { const channel = member.guild.channels.cache.get(welcomeChannel); diff --git a/src/structures.ts b/src/structures.ts index d7b3bc6..c92f5fc 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -82,6 +82,7 @@ class Guild { public welcomeType: "none" | "text" | "graphical"; public welcomeChannel: string | null; public welcomeMessage: string | null; + public autoRoles: string[] | null; // StringArray of role IDs public streamingChannel: string | null; public streamingRoles: {[role: string]: string}; // Role ID: Category Name public channelNames: {[channel: string]: string}; @@ -91,6 +92,7 @@ class Guild { this.prefix = select(data?.prefix, null, String); this.welcomeChannel = select(data?.welcomeChannel, null, String); this.welcomeMessage = select(data?.welcomeMessage, null, String); + this.autoRoles = select(data?.autoRoles, null, String, true); this.streamingChannel = select(data?.streamingChannel, null, String); this.streamingRoles = {}; this.channelNames = {};