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 |
try { |
16 |
await member.send({ |
17 |
embeds: [ |
18 |
new MessageEmbed({ |
19 |
author: { |
20 |
name: member.guild.name, |
21 |
iconURL: member.guild.iconURL() ?? undefined, |
22 |
}, |
23 |
title: "Thanks for verifying!", |
24 |
description: "The verification was completed successfully!", |
25 |
timestamp: new Date() |
26 |
}) |
27 |
], |
28 |
}); |
29 |
} |
30 |
catch (e) { |
31 |
console.log(e); |
32 |
} |
33 |
|
34 |
const { default: UnverifiedMember } = await import('../models/UnverifiedMember'); |
35 |
|
36 |
const data = await UnverifiedMember.findOne({ |
37 |
where: { |
38 |
guild_id: member.guild.id, |
39 |
user_id: member.id, |
40 |
status: 'pending' |
41 |
} |
42 |
}); |
43 |
|
44 |
await data?.set('status', 'done'); |
45 |
await data?.set('ip', req.ip); |
46 |
await data?.set('user_agent', req.get('User-Agent')); |
47 |
await data?.save(); |
48 |
} |
49 |
|
50 |
async start(member: GuildMember) { |
51 |
const { default: UnverifiedMember } = await import('../models/UnverifiedMember'); |
52 |
|
53 |
await UnverifiedMember.create({ |
54 |
guild_id: member.guild.id, |
55 |
user_id: member.id, |
56 |
status: 'pending' |
57 |
}); |
58 |
|
59 |
await member.roles.add(this.client.config.props[member.guild.id].verification.role); |
60 |
|
61 |
const url = `${this.client.config.props.global.cp_host}/challenge/v1/verify/?guild_id=${member.guild.id}`; |
62 |
|
63 |
try { |
64 |
await member.send({ |
65 |
embeds: [ |
66 |
new MessageEmbed({ |
67 |
author: { |
68 |
name: member.guild.name, |
69 |
iconURL: member.guild.iconURL() ?? undefined, |
70 |
}, |
71 |
title: "Verification Required!", |
72 |
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*`, |
73 |
timestamp: new Date(), |
74 |
fields: [ |
75 |
{ |
76 |
name: "Verification URL", |
77 |
value: url |
78 |
} |
79 |
], |
80 |
url |
81 |
}) |
82 |
] |
83 |
}); |
84 |
} |
85 |
catch (e) { |
86 |
console.log(e); |
87 |
} |
88 |
} |
89 |
} |