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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2903 byte(s)
chore: eslint autofix
1 import { GuildMember } from "discord.js";
2 import { Request } from "express";
3 import MessageEmbed from "../client/MessageEmbed";
4 import Service from "../utils/structures/Service";
5
6 export default class Verification extends Service {
7 async success(member: GuildMember, req: Request) {
8 await member.roles.remove(this.client.config.props[member.guild.id].verification.role);
9
10 try {
11 await member.send({
12 embeds: [
13 new MessageEmbed({
14 author: {
15 name: member.guild.name,
16 iconURL: member.guild.iconURL() ?? undefined,
17 },
18 title: "Thanks for verifying!",
19 description: "The verification was completed successfully!",
20 timestamp: new Date()
21 })
22 ],
23 });
24 }
25 catch (e) {
26 console.log(e);
27 }
28
29 const { default: UnverifiedMember } = await import('../models/UnverifiedMember');
30
31 const data = await UnverifiedMember.findOne({
32 guild_id: member.guild.id,
33 user_id: member.id,
34 status: 'pending'
35 });
36
37 await data?.set('status', 'done');
38 await data?.set('ip', req.ip);
39 await data?.set('user_agent', req.get('User-Agent'));
40 await data?.save();
41 }
42
43 async start(member: GuildMember) {
44 const { default: UnverifiedMember } = await import('../models/UnverifiedMember');
45
46 await UnverifiedMember.create({
47 guild_id: member.guild.id,
48 user_id: member.id,
49 status: 'pending',
50 createdAt: new Date()
51 });
52
53 await member.roles.add(this.client.config.props[member.guild.id].verification.role);
54
55 const url = `${this.client.config.props.global.cp_host}/challenge/v1/verify/?guild_id=${member.guild.id}`;
56
57 try {
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 catch (e) {
80 console.log(e);
81 }
82 }
83 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26