1 |
import { GuildMember } from "discord.js"; |
2 |
import { Request } from "express"; |
3 |
import { Op } from "sequelize"; |
4 |
import DiscordClient from "../client/Client"; |
5 |
import MessageEmbed from "../client/MessageEmbed"; |
6 |
|
7 |
export default class Verification { |
8 |
constructor(protected client: DiscordClient) { |
9 |
|
10 |
} |
11 |
|
12 |
async success(member: GuildMember, req: Request) { |
13 |
await member.roles.remove(this.client.config.props[member.guild.id].verification.role); |
14 |
|
15 |
await member.send({ |
16 |
embeds: [ |
17 |
new MessageEmbed({ |
18 |
author: { |
19 |
name: member.guild.name, |
20 |
iconURL: member.guild.iconURL() ?? undefined, |
21 |
}, |
22 |
title: "Thanks for verifying!", |
23 |
description: "The verification was completed successfully!", |
24 |
timestamp: new Date() |
25 |
}) |
26 |
], |
27 |
}); |
28 |
|
29 |
const { default: UnverifiedMember } = await import('../models/UnverifiedMember'); |
30 |
|
31 |
const data = await UnverifiedMember.findOne({ |
32 |
where: { |
33 |
guild_id: member.guild.id, |
34 |
user_id: member.id, |
35 |
status: 'pending' |
36 |
} |
37 |
}); |
38 |
|
39 |
await data?.set('status', 'done'); |
40 |
await data?.set('ip', req.ip); |
41 |
await data?.set('user_agent', req.get('User-Agent')); |
42 |
await data?.save(); |
43 |
} |
44 |
|
45 |
async start(member: GuildMember) { |
46 |
const { default: UnverifiedMember } = await import('../models/UnverifiedMember'); |
47 |
|
48 |
await UnverifiedMember.create({ |
49 |
guild_id: member.guild.id, |
50 |
user_id: member.id, |
51 |
status: 'pending' |
52 |
}); |
53 |
|
54 |
await member.roles.add(this.client.config.props[member.guild.id].verification.role); |
55 |
|
56 |
const url = `${this.client.config.props.global.cp_host}/challenge/v1/verify/?guild_id=${member.guild.id}`; |
57 |
|
58 |
await member.send({ |
59 |
embeds: [ |
60 |
new MessageEmbed({ |
61 |
author: { |
62 |
name: member.guild.name, |
63 |
iconURL: member.guild.iconURL() ?? undefined, |
64 |
}, |
65 |
title: "Verification Required!", |
66 |
description: `Hey ${member.nickname ?? member.user.username}, the server **${member.guild.name}** requires verification!\nTo verify yourself, simply go to the verification URL given below and you might be asked to solve some captcha.\n\nHave a nice day,\n*${member.guild.name} Staff*`, |
67 |
timestamp: new Date(), |
68 |
fields: [ |
69 |
{ |
70 |
name: "Verification URL", |
71 |
value: url |
72 |
} |
73 |
], |
74 |
url |
75 |
}) |
76 |
] |
77 |
}); |
78 |
} |
79 |
} |