diff options
| author | Fuwn <[email protected]> | 2022-05-18 04:08:52 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-05-18 04:08:52 -0700 |
| commit | ebc72061fec75d44f41c776708275d9c323ca827 (patch) | |
| tree | 983dfda1c7de41cfcb6283a6f657e75fb771c729 | |
| parent | refactor: reimplement (diff) | |
| download | macy-main.tar.xz macy-main.zip | |
| -rw-r--r-- | macy.ts | 251 | ||||
| -rw-r--r-- | mod.ts | 40 | ||||
| -rw-r--r-- | old/deps.ts | 10 | ||||
| -rw-r--r-- | old/mod.ts | 205 |
4 files changed, 264 insertions, 242 deletions
@@ -0,0 +1,251 @@ +// This file is part of Macy <https://github.com/Fuwn/macy>. +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// +// All Rights Reserved. +// +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// SPDX-License-Identifier: UNLICENSED + +import { + APPROVED_ROLE, + CLASS_MEMBERS, + FUWN_ID, + LOBBY_CHANNEL, +} from "./config.ts"; +import { + ApplicationCommandInteraction, + ApplicationCommandOptionType, + Client, + event, + PermissionFlags, + slash, +} from "https://deno.land/x/[email protected]/mod.ts"; + +export class Macy extends Client { + verificationQueue = new Map<string, string>(); + + @event() + ready() { + console.log(`${this.user?.username}#${this.user?.discriminator} is ready!`); + + this.user?.client.setPresence({ + activity: { + name: "your work", + type: "WATCHING", + }, + }); + + this.interactions.commands.bulkEdit([ + { + name: "setup", + description: "Setup the informational message in the lobby channel", + }, + { + name: "queue", + description: "View the verification queue", + }, + { + name: "verify", + description: "Add your account to the verification queue", + options: [ + { + name: "name", + description: "Your full name as shown in Zoom", + required: true, + type: ApplicationCommandOptionType.STRING, + }, + ], + }, + { + name: "approve", + description: "Approve an account in the verification queue", + options: [ + { + name: "name", + description: + "A users full name as shown in Zoom. If not specified, all " + + "queued accounts will be approved.", + required: false, + type: ApplicationCommandOptionType.STRING, + }, + ], + }, + { + name: "check", + description: "Check if you are recognized as a class member", + options: [ + { + name: "name", + description: "Your full name as shown in Zoom", + required: true, + type: ApplicationCommandOptionType.STRING, + }, + ], + }, + ]); + + console.log("Commands setup!"); + } + + @slash() + setup(_: ApplicationCommandInteraction) { + this.user?.client?.channels.sendMessage( + LOBBY_CHANNEL, + "To access the rest of the server, send a message structured like this: " + + "`/verify [name]`, with `name` being your full name as shown in Zoom." + + "\n\nAn example of a valid verification request looks like this: " + + "`/verify Zoltan Szabatin`.\n\nIf you are unable to verify yourself; " + + "first, check if your name is recognized as a class member using the " + + "`/check [name]` command, with `name` being your full name as show in " + + "Zoom. An example of a valid check command looks like: " + + "`/check Zoltan Szabatin`.\n\nIf you are unable to verify yourself and " + + "your name is not recognized as a class member, you should then DM " + + `<@${FUWN_ID}>.`, + ); + } + + @slash() + async verify(d: ApplicationCommandInteraction) { + const member = d.member; + const name = d.option<string>("name"); + + if (member === null) { + d.respond({ + content: "I cannot obtain your ID, please try again.", + ephemeral: true, + }); + + return; + } + + if ((await member?.roles.get(APPROVED_ROLE)) !== undefined) { + d.respond({ + content: "You are already verified!", + ephemeral: true, + }); + + return; + } + + this.verificationQueue.forEach((verificationName, id) => { + if (id === member?.id || verificationName === name) { + d.respond({ + content: "You are already in the verification queue!", + ephemeral: true, + }); + + return; + } + }); + + if ( + Deno.env.get("CLASS")?.toLowerCase() === "true" || + Deno.env.get("CLASS") === "1" + ) { + if (!CLASS_MEMBERS.includes(name)) { + d.respond({ + content: "You are not a class member!", + ephemeral: true, + }); + + return; + } + } + + (await d.guild?.members.fetchList())?.forEach((member) => { + if (member.nick === name) { + d.respond({ + content: "Someone with that exact name is already verified! If you " + + `think this is an error, DM <@${FUWN_ID}>.`, + ephemeral: true, + }); + + return; + } + }); + + this.verificationQueue.set(name, member!.id); + + d.respond({ + content: + `Hello, ${name}! You have been added into the verification queue and ` + + "will be verified shortly.", + ephemeral: true, + }); + } + + @slash() + async approve(d: ApplicationCommandInteraction) { + if (this.verificationQueue.size === 0) { + d.reply("There are no users in the verification queue."); + + return; + } + + const name = d.option<string | undefined>("name"); + + if ( + !(d.member?.permissions.has(PermissionFlags.ADMINISTRATOR)) + ) { + d.respond({ + content: "You do not have sufficient permissions to verify this user!", + ephemeral: true, + }); + + return; + } + + if (name === undefined) { + console.log(this.verificationQueue); + this.verificationQueue.forEach(async (id, name) => { + this.verificationQueue.delete(name); + (await d.guild!.members.get(id))?.roles.add(APPROVED_ROLE); + (await d.guild!.members.get(id))?.setNickname(name); + }); + d.reply("All users within the verification queue have been approved!"); + } else { + const member = this.verificationQueue.get(name); + + if (member === undefined) { + d.reply(`${name} is not in the verification queue.`); + } else { + this.verificationQueue.delete(name); + (await d.guild!.members.get(member))?.roles.add(APPROVED_ROLE); + (await d.guild!.members.get(member))?.setNickname(name); + d.reply(`${name} has been approved!`); + } + } + } + + @slash() + queue(d: ApplicationCommandInteraction) { + if (this.verificationQueue.size === 0) { + d.reply("There are no users in the verification queue."); + + return; + } + + let verificationQueueString = "Map { "; + let i = 1; + + this.verificationQueue.forEach((name, id) => { + verificationQueueString += `\"${id}\" => \"${name}\" ${ + i == this.verificationQueue.size ? "" : ", " + }`; + i += 1; + }); + + d.reply(verificationQueueString + "}"); + } + + @slash() + check(d: ApplicationCommandInteraction) { + const name = d.option<string>("name"); + + if (CLASS_MEMBERS.includes(name)) { + d.reply(`${name} is a class member!`); + } else { + d.reply(`${name} is not a class member!`); + } + } +} @@ -1,29 +1,15 @@ -import * as deploy from "https://deno.land/x/[email protected]/deploy.ts"; -import { FUWN_ID, LOBBY_CHANNEL } from "./config.ts"; +// This file is part of Macy <https://github.com/Fuwn/macy>. +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// +// All Rights Reserved. +// +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// SPDX-License-Identifier: UNLICENSED -deploy.init({ env: true }); +import { Macy } from "./macy.ts"; +import { config } from "https://deno.land/x/[email protected]/mod.ts"; +import { GatewayIntents } from "https://deno.land/x/[email protected]/mod.ts"; -if ((await deploy.commands.all()).size) { - deploy.commands.bulkEdit([ - { - name: "setup", - description: "Setup the informational message in the lobby channel.", - }, - ]); -} - -deploy.handle("setup", (_: deploy.ApplicationCommandInteraction) => { - deploy.client.client?.channels.sendMessage( - LOBBY_CHANNEL, - "To access the rest of the server, send a message structured like this: " + - "`/verify [name]`, with `name` being your full name as shown in Zoom." + - "\n\nAn example of a valid verification request looks like this: " + - "`/verify Zoltan Szabatin`.\n\nIf you are unable to verify yourself; " + - "first, check if your name is recognized as a class member using the " + - "`/check [name]` command, with `name` being your full name as show in " + - "Zoom. An example of a valid check command looks like: " + - "`/check Zoltan Szabatin`.\n\nIf you are unable to verify yourself and " + - "your name is not recognized as a class member, you should then DM " + - `<@${FUWN_ID}>.`, - ); -}); +(new Macy()).connect(config().TOKEN, [ + GatewayIntents.GUILD_MEMBERS, +]); diff --git a/old/deps.ts b/old/deps.ts deleted file mode 100644 index f3c2ba6..0000000 --- a/old/deps.ts +++ /dev/null @@ -1,10 +0,0 @@ -// This file is part of Macy <https://github.com/Fuwn/macy>. -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// -// All Rights Reserved. -// -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// SPDX-License-Identifier: UNLICENSED - -export * as deploy from "https://deno.land/x/[email protected]/deploy.ts"; -export * from "https://deno.land/x/[email protected]/mod.ts"; diff --git a/old/mod.ts b/old/mod.ts deleted file mode 100644 index d677d71..0000000 --- a/old/mod.ts +++ /dev/null @@ -1,205 +0,0 @@ -// This file is part of Macy <https://github.com/Fuwn/macy>. -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// -// All Rights Reserved. -// -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// SPDX-License-Identifier: UNLICENSED - -// import { config } from "./deps.ts"; -import { deploy } from "./deps.ts"; -import { - APPROVED_ROLE, - BREAKOUT_ROOM_EIGHT_ROLE, - CLASS_MEMBERS, - FUWN_ID, - LOBBY_CHANNEL, -} from "./config.ts"; - -const verificationQueue = new Map<string, string>(); - -deploy.init({ env: true }); -// deploy.init({ token: config().TOKEN, publicKey: config().PUBLIC_KEY }); - -if ((await deploy.commands.all()).size !== 4) { - deploy.commands.bulkEdit([ - { - name: "verify", - description: "Add your account into the verification queue.", - options: [ - { - name: "name", - description: "Your full name as shown in Zoom.", - required: true, - type: deploy.ApplicationCommandOptionType.STRING, - }, - ], - }, - { - name: "approve", - description: "Approve an account in the verification queue.", - options: [ - { - name: "name", - description: - "A users full name as shown in Zoom. If not specified, all " + - "queued verifees will be approved.", - required: false, - type: deploy.ApplicationCommandOptionType.STRING, - }, - ], - }, - { - name: "queue", - description: "View the verification queue.", - }, - { - name: "setup", - description: "Setup the informational verification message in the " + - "lobby channel.", - }, - ]); -} - -deploy.client.client?.setPresence({ - activity: { - name: "your work", - type: "WATCHING", - }, -}); - -deploy.handle("verify", async (d: deploy.ApplicationCommandInteraction) => { - const member = d.member; - const name = d.option<string>("name"); - - if (member === null) { - d.respond({ - content: "I cannot obtain your ID, please try again.", - ephemeral: true, - }); - - return; - } - - if ((await member?.roles.get(APPROVED_ROLE)) !== undefined) { - d.respond({ - content: "You are already verified!", - ephemeral: true, - }); - - return; - } - - verificationQueue.forEach((verificationName, id) => { - if (id === member?.id || verificationName === name) { - d.respond({ - content: "You are already in the verification queue!", - ephemeral: true, - }); - - return; - } - }); - - if ( - Deno.env.get("CLASS")?.toLowerCase() === "true" || - Deno.env.get("CLASS") === "1" - ) { - if (!CLASS_MEMBERS.includes(name)) { - d.respond({ - content: "You are not a class member!", - ephemeral: true, - }); - - return; - } - } - - (await d.guild?.members.fetchList())?.forEach((member) => { - if (member.nick === name) { - d.respond({ - content: "Someone with that exact name is already verified! If you " + - `think this is an error, DM <@${FUWN_ID}>.`, - ephemeral: true, - }); - - return; - } - }); - - verificationQueue.set(name, member!.id); - - d.respond({ - content: - `Hello, ${name}! You have been added into the verification queue and will be ` + - "verified shortly.", - ephemeral: true, - }); -}); - -deploy.handle("approve", async (d: deploy.ApplicationCommandInteraction) => { - const name = d.option<string | undefined>("name"); - - if ((await d.member?.roles.get(BREAKOUT_ROOM_EIGHT_ROLE)) === undefined) { - d.respond({ - content: "You do not have sufficient permissions to verify this user!", - ephemeral: true, - }); - - return; - } - - if (name === undefined) { - verificationQueue.forEach((name, id) => { - console.log(`${name} (${id})`); - }); - d.reply("All users within the verification queue have been approved!"); - } else { - const member = verificationQueue.get(name); - - if (member === undefined) { - d.reply(`${name} is not in the verification queue.`); - } else { - verificationQueue.delete(name); - (await d.guild!.members.get(member))?.roles.add(APPROVED_ROLE); - (await d.guild!.members.get(member))?.setNickname(name); - d.reply(`${name} has been approved!`); - } - } -}); - -deploy.handle("queue", (d: deploy.ApplicationCommandInteraction) => { - if (verificationQueue.size === 0) { - d.reply("There are no users in the verification queue."); - - return; - } - - let verificationQueueString = "Map { "; - let i = 1; - - verificationQueue.forEach((name, id) => { - verificationQueueString += `\"${name}\" => \"${id}\" ${ - i == verificationQueue.size ? "" : ", " - }`; - i += 1; - }); - - d.reply(verificationQueueString + "}"); -}); - -deploy.handle("setup", (_: deploy.ApplicationCommandInteraction) => { - deploy.client.client?.channels.sendMessage( - LOBBY_CHANNEL, - "To access the rest of the server, send a message structured like this: " + - "`/verify [name]`, with `name` being your full name as shown in Zoom." + - "\n\nAn example of a valid verification request looks like this: " + - "`/verify Zoltan Szabatin`.\n\nIf you are unable to verify yourself; " + - "first, check if your name is recognized as a class member using the " + - "`/check [name]` command, with `name` being your full name as show in " + - "Zoom. An example of a valid check command looks like: " + - "`/check Zoltan Szabatin`.\n\nIf you are unable to verify yourself and " + - "your name is not recognized as a class member, you should then DM " + - `<@${FUWN_ID}>.`, - ); -}); |