1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
// 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,
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 <@217348698294714370>.",
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 so: " +
"`/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`.",
);
});
|