/[sudobot]/branches/2.x/src/services/AFKEngine.ts
ViewVC logotype

Contents of /branches/2.x/src/services/AFKEngine.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 2081 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
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 import Service from "../utils/structures/Service";
6
7 export default class AFKEngine extends Service {
8 mention(msg: Message, user: GuildMember, cb: (data: any) => void, msg1?: any) {
9 this.client.db.get('SELECT * FROM afk WHERE user_id = ?', [user.id], (err: any, data: any) => {
10 if (data) {
11 if (msg1 === undefined) {
12 msg.channel!.send({
13 embeds: [
14 new MessageEmbed()
15 .setDescription(`**${user.user.tag}** is AFK right now${data.reason.trim() == '' ? '.' : (' for reason: **' + data.reason.replace(/\*/g, '\\*') + '**')}`)
16 ]
17 });
18 }
19
20 this.client.db.get('UPDATE afk SET mentions = ? WHERE id = ?', [parseInt(data.mentions) + 1, data.id], (err: any) => {});
21
22 cb(data);
23 }
24 });
25
26 }
27
28 start(msg: Message) {
29 if (msg.author.bot)
30 return;
31
32 const mention = msg.mentions.members!.first();
33
34 if (mention) {
35 this.mention(msg, msg.member!, data => {
36 if (msg.author.id === data.user_id) {
37 notAFK(this.client, msg, data);
38 }
39 }, true);
40
41 msg.mentions.members!.forEach((member) => {
42 this.mention(msg, member, data => {
43 if (msg.author.id === data.user_id) {
44 notAFK(this.client, msg, data);
45 }
46 });
47 });
48 }
49 else {
50 this.client.db.get('SELECT * FROM afk WHERE user_id = ?', [msg.author.id], (err: any, data: any) => {
51 if (data) {
52 notAFK(this.client, msg, data);
53 }
54 });
55 }
56 }
57 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26