/[sudobot]/trunk/src/services/Verification.ts
ViewVC logotype

Annotation of /trunk/src/services/Verification.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3627 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
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 rakin 127 import { GuildMember } from "discord.js";
21 rakin 130 import { Request } from "express";
22 rakin 127 import MessageEmbed from "../client/MessageEmbed";
23 rakin 226 import Service from "../utils/structures/Service";
24 rakin 127
25 rakin 226 export default class Verification extends Service {
26 rakin 130 async success(member: GuildMember, req: Request) {
27 rakin 127 await member.roles.remove(this.client.config.props[member.guild.id].verification.role);
28    
29 rakin 158 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 rakin 127
48     const { default: UnverifiedMember } = await import('../models/UnverifiedMember');
49    
50     const data = await UnverifiedMember.findOne({
51 rakin 340 guild_id: member.guild.id,
52     user_id: member.id,
53     status: 'pending'
54 rakin 127 });
55    
56     await data?.set('status', 'done');
57 rakin 130 await data?.set('ip', req.ip);
58     await data?.set('user_agent', req.get('User-Agent'));
59 rakin 127 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 rakin 340 status: 'pending',
69     createdAt: new Date()
70 rakin 127 });
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 rakin 158 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 rakin 127 }
102 rakin 158 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26