1 |
/** |
2 |
* This file is part of SudoBot. |
3 |
* |
4 |
* Copyright (C) 2021-2022 OSN Inc. |
5 |
* |
6 |
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
* under the terms of the GNU Affero General Public License as published by |
8 |
* the Free Software Foundation, either version 3 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* SudoBot is distributed in the hope that it will be useful, but |
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU Affero General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU Affero General Public License |
17 |
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
*/ |
19 |
|
20 |
import { GuildMember } from "discord.js"; |
21 |
import { Request } from "express"; |
22 |
import MessageEmbed from "../client/MessageEmbed"; |
23 |
import Service from "../utils/structures/Service"; |
24 |
|
25 |
export default class Verification extends Service { |
26 |
async success(member: GuildMember, req: Request) { |
27 |
await member.roles.remove(this.client.config.props[member.guild.id].verification.role); |
28 |
|
29 |
try { |
30 |
await member.send({ |
31 |
embeds: [ |
32 |
new MessageEmbed({ |
33 |
author: { |
34 |
name: member.guild.name, |
35 |
iconURL: member.guild.iconURL() ?? undefined, |
36 |
}, |
37 |
title: "Thanks for verifying!", |
38 |
description: "The verification was completed successfully!", |
39 |
timestamp: new Date() |
40 |
}) |
41 |
], |
42 |
}); |
43 |
} |
44 |
catch (e) { |
45 |
console.log(e); |
46 |
} |
47 |
|
48 |
const { default: UnverifiedMember } = await import('../models/UnverifiedMember'); |
49 |
|
50 |
const data = await UnverifiedMember.findOne({ |
51 |
guild_id: member.guild.id, |
52 |
user_id: member.id, |
53 |
status: 'pending' |
54 |
}); |
55 |
|
56 |
await data?.set('status', 'done'); |
57 |
await data?.set('ip', req.ip); |
58 |
await data?.set('user_agent', req.get('User-Agent')); |
59 |
await data?.save(); |
60 |
} |
61 |
|
62 |
async start(member: GuildMember) { |
63 |
const { default: UnverifiedMember } = await import('../models/UnverifiedMember'); |
64 |
|
65 |
await UnverifiedMember.create({ |
66 |
guild_id: member.guild.id, |
67 |
user_id: member.id, |
68 |
status: 'pending', |
69 |
createdAt: new Date() |
70 |
}); |
71 |
|
72 |
await member.roles.add(this.client.config.props[member.guild.id].verification.role); |
73 |
|
74 |
const url = `${this.client.config.props.global.cp_host}/challenge/v1/verify/?guild_id=${member.guild.id}`; |
75 |
|
76 |
try { |
77 |
await member.send({ |
78 |
embeds: [ |
79 |
new MessageEmbed({ |
80 |
author: { |
81 |
name: member.guild.name, |
82 |
iconURL: member.guild.iconURL() ?? undefined, |
83 |
}, |
84 |
title: "Verification Required!", |
85 |
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*`, |
86 |
timestamp: new Date(), |
87 |
fields: [ |
88 |
{ |
89 |
name: "Verification URL", |
90 |
value: url |
91 |
} |
92 |
], |
93 |
url |
94 |
}) |
95 |
] |
96 |
}); |
97 |
} |
98 |
catch (e) { |
99 |
console.log(e); |
100 |
} |
101 |
} |
102 |
} |