1 |
import { CommandInteraction, GuildMember, Interaction, Message, MessageAttachment } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
7 |
import { download } from '../../utils/util'; |
8 |
import path from 'path'; |
9 |
import { fetchEmoji } from '../../utils/Emoji'; |
10 |
|
11 |
export async function notAFK(client: DiscordClient, msg: Message | CommandInteraction, data: any) { |
12 |
client.db.get('DELETE FROM afk WHERE user_id = ?', [msg.member!.user.id], async (err: any) => { |
13 |
await msg.reply({ |
14 |
embeds: [ |
15 |
new MessageEmbed() |
16 |
.setDescription('You\'re no longer AFK. You had **' + data.mentions + '** mentions in the servers where SudoBot is joined.') |
17 |
] |
18 |
}); |
19 |
}); |
20 |
} |
21 |
|
22 |
export async function AFK(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
23 |
let reason: string | undefined = undefined; |
24 |
|
25 |
if (!options.isInteraction) { |
26 |
reason = options.args[0] === undefined ? undefined : options.args.join(' '); |
27 |
} |
28 |
else if (options.options.getString('reason')) { |
29 |
reason = <string> await options.options.getString('reason'); |
30 |
} |
31 |
|
32 |
client.db.get('INSERT INTO afk(user_id, date, mentions, reason) VALUES(?, ?, ?, ?)', [msg.member!.user.id, new Date().toISOString(), '0', reason === undefined ? '' : reason], async (err: any) => { |
33 |
await msg.reply({ |
34 |
embeds: [ |
35 |
new MessageEmbed() |
36 |
.setDescription('You\'re AFK now.' + (reason === undefined ? '' : ` Your status has been updated to: **${reason.replace(/\*/g, '\\*')}**`)) |
37 |
] |
38 |
}); |
39 |
}); |
40 |
} |
41 |
|
42 |
export default class AFKCommand extends BaseCommand { |
43 |
supportsInteractions = true; |
44 |
|
45 |
constructor() { |
46 |
super('afk', 'utils', []); |
47 |
} |
48 |
|
49 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
50 |
client.db.get("SELECT * FROM afk WHERE user_id = ?", [msg.member!.user.id], async (err: any, data: any) => { |
51 |
if (data) { |
52 |
notAFK(client, msg, data); |
53 |
} |
54 |
else { |
55 |
AFK(client, msg, options); |
56 |
} |
57 |
}); |
58 |
} |
59 |
} |