summaryrefslogtreecommitdiff
path: root/server/src/commands/emma/Verify.ts
diff options
context:
space:
mode:
author8cy <[email protected]>2020-07-26 07:02:25 -0700
committer8cy <[email protected]>2020-07-26 07:02:25 -0700
commit8a7f1253716c79e2d36d356b9ad380d382d8603e (patch)
tree91281e6ce74752560c2c38ddc3587a6541370436 /server/src/commands/emma/Verify.ts
parentimprovment: bold and tag darling check (diff)
downloaddep-core-test-captcha.tar.xz
dep-core-test-captcha.zip
feat/ fix/ chore/ improvmenttest-captcha
feat: - new img method on client - verification command finally lul, this also had me add stuff to the config fix: - fanart msg now says "video/ img" instead of just video. - re-add f reaction to leave msgs chore: - capitalize s in sending in help msg. improvement: - 3 new welcome msgs - 4 new goodbye msgs - make "1/ 1000" in secret msg bold and react with star emoji
Diffstat (limited to 'server/src/commands/emma/Verify.ts')
-rw-r--r--server/src/commands/emma/Verify.ts73
1 files changed, 73 insertions, 0 deletions
diff --git a/server/src/commands/emma/Verify.ts b/server/src/commands/emma/Verify.ts
new file mode 100644
index 0000000..09bebbb
--- /dev/null
+++ b/server/src/commands/emma/Verify.ts
@@ -0,0 +1,73 @@
+import { Command } from 'discord-akairo';
+import { Message } from 'discord.js';
+import { colour } from '../../Config';
+import * as svgCaptcha from 'svg-captcha';
+import { MessageAttachment } from 'discord.js';
+import { TextChannel } from 'discord.js';
+import { captchaSettings, verificationRole, verificationChannel } from '../../Config';
+
+export default class VerifyEmma extends Command {
+ public constructor() {
+ super('verify', {
+ aliases: ['verify'],
+ category: 'moderation',
+ description: {
+ content: 'Allows to to verify yourself so you can access the rest of a server. Public version out soon!',
+ usage: '',
+ examples: [
+ ''
+ ]
+ },
+ ratelimit: 3
+ });
+ }
+
+ public async exec(msg: Message): Promise<Message> {
+ msg.delete();
+ if ((msg.channel as TextChannel).name !== verificationChannel) return;
+ if (msg.channel.type ==='dm') return msg.channel.send('Sorry, verification needs to be initialized in the server\'s verification channel!');
+ const captcha = await svgCaptcha.create(captchaSettings);
+ const attachment = new MessageAttachment(await this.client.img(captcha.data).then(r => r), 'captcha.png');
+ const embed = this.client.util.embed()
+ .setColor(colour)
+ .setDescription('Please reply with the following captcha. (**case-sensitive**).')
+ //@ts-ignore
+ .attachFiles(attachment)
+ .setImage('attachment://captcha.png')
+ .setFooter('Expires in 60 seconds.')
+ const m1 = await msg.author.send('Generating captcha...').catch(async () => {
+ const deleteMessage = await msg.reply('I\'m unable to send you a direct message. Please, make sure to allow direct messages from server members in the privacy settings!');
+ await this.wait(7000);
+ return deleteMessage.delete();
+ });
+ m1.delete();
+ const message = await msg.author.send(embed);
+ const response = await this.awaitReplyDM(msg.member, message, 60000);
+ if (!response) return msg.author.send(`The captcha has expired! Try again by typing \`${this.client.commandHandler.prefix}verify\` in the server's verification channel!`).catch(async () => {
+ const deleteMessage = await msg.reply('I\'m unable to send you a direct message. Please, make sure to allow direct messages from server members in the privacy settings!');
+ await this.wait(7000);
+ return deleteMessage.delete();
+ });
+ if (response.includes(captcha.text)) {
+ msg.author.send('You passed the captcha! Granting access...').then(async m => {
+ const role = await msg.guild.roles.cache.find(r => r.name.toLowerCase() === verificationRole.toLowerCase());
+ if (role) msg.member.roles.add(role.id);
+ m.edit(`Access granted to **${msg.guild.name}**!`);
+ });
+ } else {
+ return msg.author.send(`Wrong captcha! Try again by typing \`${this.client.commandHandler.prefix}verify\` in the server's verification channel!`);
+ }
+ }
+
+ public awaitReplyDM = async (member, msg, question, limit = 60000) => {
+ const filter = m => member.id == member.id;
+ try {
+ const collected = await msg.channel.awaitMessages(filter, { max: 1, time: limit, errors: ['time'] });
+ return collected.first().content;
+ } catch (error) {
+ return false;
+ }
+ }
+
+ public wait = require("util").promisify(setTimeout);
+} \ No newline at end of file