1 |
import { CommandInteraction, GuildMember, Interaction, Message, MessageAttachment } from 'discord.js'; |
import { Util, CommandInteraction, GuildMember, Interaction, Message, MessageAttachment } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
|
import MessageEmbed from '../../client/MessageEmbed'; |
|
|
import { download } from '../../utils/util'; |
|
|
import path from 'path'; |
|
|
import { fetchEmoji } from '../../utils/Emoji'; |
|
|
|
|
|
export async function notAFK(client: DiscordClient, msg: Message | CommandInteraction, data: any) { |
|
|
client.db.get('DELETE FROM afk WHERE user_id = ?', [msg.member!.user.id], async (err: any) => { |
|
|
await msg.reply({ |
|
|
embeds: [ |
|
|
new MessageEmbed() |
|
|
.setDescription('You\'re no longer AFK. You had **' + data.mentions + '** mentions in the servers where SudoBot is joined.') |
|
|
] |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
export async function AFK(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
|
|
let reason: string | undefined = undefined; |
|
|
|
|
|
if (!options.isInteraction) { |
|
|
reason = options.args[0] === undefined ? undefined : options.args.join(' '); |
|
|
} |
|
|
else if (options.options.getString('reason')) { |
|
|
reason = <string> await options.options.getString('reason'); |
|
|
} |
|
|
|
|
|
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) => { |
|
|
await msg.reply({ |
|
|
embeds: [ |
|
|
new MessageEmbed() |
|
|
.setDescription('You\'re AFK now.' + (reason === undefined ? '' : ` Your status has been updated to: **${reason.replace(/\*/g, '\\*')}**`)) |
|
|
] |
|
|
}); |
|
|
}); |
|
|
} |
|
6 |
|
|
7 |
export default class AFKCommand extends BaseCommand { |
export default class AFKCommand extends BaseCommand { |
8 |
supportsInteractions = true; |
supportsInteractions = true; |
11 |
super('afk', 'utils', []); |
super('afk', 'utils', []); |
12 |
} |
} |
13 |
|
|
14 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
15 |
client.db.get("SELECT * FROM afk WHERE user_id = ?", [msg.member!.user.id], async (err: any, data: any) => { |
let status = options.isInteraction ? options.options.getString("reason") ?? undefined : options.args.join(" "); |
16 |
if (data) { |
|
17 |
notAFK(client, msg, data); |
if (message instanceof Message) { |
18 |
} |
status = status?.trim() === '' ? undefined : status; |
19 |
else { |
} |
20 |
AFK(client, msg, options); |
|
21 |
} |
await client.afkEngine.toggle(message, true, status); |
|
}); |
|
22 |
} |
} |
23 |
} |
} |