1 |
import { CommandInteraction, GuildMember, Interaction, Message, MessageAttachment } from 'discord.js'; |
/** |
2 |
|
* This file is part of SudoBot. |
3 |
|
* |
4 |
|
* Copyright (C) 2021-2022 OSN Inc. |
5 |
|
* |
6 |
|
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
|
* under the terms of the GNU Affero General Public License as published by |
8 |
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* SudoBot is distributed in the hope that it will be useful, but |
12 |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU Affero General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU Affero General Public License |
17 |
|
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
|
*/ |
19 |
|
|
20 |
|
import { CommandInteraction, Message } from 'discord.js'; |
21 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
22 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
23 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
24 |
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.channel!.send({ |
|
|
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, '\\*')}**`)) |
|
|
] |
|
|
}); |
|
|
}); |
|
|
} |
|
25 |
|
|
26 |
export default class AFKCommand extends BaseCommand { |
export default class AFKCommand extends BaseCommand { |
27 |
supportsInteractions = true; |
supportsInteractions = true; |
30 |
super('afk', 'utils', []); |
super('afk', 'utils', []); |
31 |
} |
} |
32 |
|
|
33 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
34 |
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(" "); |
35 |
if (data) { |
|
36 |
notAFK(client, msg, data); |
if (message instanceof Message) { |
37 |
} |
status = status?.trim() === '' ? undefined : status; |
38 |
else { |
} |
39 |
AFK(client, msg, options); |
|
40 |
} |
await client.afkEngine.toggle(message, true, status); |
|
}); |
|
41 |
} |
} |
42 |
} |
} |