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