From 7baa540663f0c1dd166fa023220752801d178458 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Fri, 28 Apr 2023 14:35:06 +0200 Subject: [PATCH] commands/grantTester: new command --- env.json | 1 + src/commands/grantTester.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/commands/grantTester.ts diff --git a/env.json b/env.json index 0d499a3..611bac3 100644 --- a/env.json +++ b/env.json @@ -33,6 +33,7 @@ "description": "The unique ID for the role that the bot will *remove* when the user accepts the rules." }, "DISCORD_DEVELOPER_ROLE": true, + "DISCORD_TESTER_ROLE": true, "DISCORD_LOGIN_TOKEN": { "description": "The login token of the bot." }, diff --git a/src/commands/grantTester.ts b/src/commands/grantTester.ts new file mode 100644 index 0000000..cf385cc --- /dev/null +++ b/src/commands/grantTester.ts @@ -0,0 +1,20 @@ +import logger from '../logging'; +import * as discord from 'discord.js'; +import { grantRole } from '../common'; + +const role = process.env.DISCORD_TESTER_ROLE; + +export const roles = ['Admins', 'Moderators', 'CitraBot']; +export async function command (message: discord.Message) { + if (!role) { + logger.error('DISCORD_TESTER_ROLE suddenly became undefined?!'); + return Promise.resolve([]); + } + + return Promise.all(message.mentions.users.map(async (user) => { + return message.guild?.members.fetch(user).then((member) => grantRole(member, role, message.channel)) + .catch(async () => { + await message.channel.send(`User ${user.toString()} was not found in the channel.`); + }); + })); +}