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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2063 byte(s)
Release version 2.0
1 import { CommandInteraction, GuildMember, Message, User } from "discord.js";
2 import DiscordClient from "../client/Client";
3 import MessageEmbed from "../client/MessageEmbed";
4 import { notAFK } from "../commands/utils/AFKCommand";
5
6 export default class AFKEngine {
7 client: DiscordClient;
8
9 constructor(client: DiscordClient) {
10 this.client = client;
11 }
12
13 mention(msg: Message, user: GuildMember, cb: (data: any) => void, msg1?: any) {
14 this.client.db.get('SELECT * FROM afk WHERE user_id = ?', [user.id], (err: any, data: any) => {
15 if (data) {
16 if (msg1 === undefined) {
17 msg.channel!.send({
18 embeds: [
19 new MessageEmbed()
20 .setDescription(`**${user.user.tag}** is AFK right now${data.reason.trim() == '' ? '.' : (' for reason: **' + data.reason.replace(/\*/g, '\\*') + '**')}`)
21 ]
22 });
23 }
24
25 this.client.db.get('UPDATE afk SET mentions = ? WHERE id = ?', [parseInt(data.mentions) + 1, data.id], (err: any) => {});
26
27 cb(data);
28 }
29 });
30
31 }
32
33 start(msg: Message) {
34 const mention = msg.mentions.members!.first();
35
36 if (mention) {
37 this.mention(msg, msg.member!, data => {
38 if (msg.author.id === data.user_id) {
39 notAFK(this.client, msg, data);
40 }
41 }, true);
42
43 msg.mentions.members!.forEach((member) => {
44 this.mention(msg, member, data => {
45 if (msg.author.id === data.user_id) {
46 notAFK(this.client, msg, data);
47 }
48 });
49 });
50 }
51 else {
52 this.client.db.get('SELECT * FROM afk WHERE user_id = ?', [msg.author.id], (err: any, data: any) => {
53 if (data) {
54 notAFK(this.client, msg, data);
55 }
56 });
57 }
58 }
59 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26