1 |
rakin |
51 |
import { CommandInteraction, FileOptions, 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 default class AddsnippetCommand extends BaseCommand { |
12 |
|
|
supportsInteractions: boolean = true; |
13 |
|
|
supportsLegacy: boolean = false; |
14 |
|
|
|
15 |
|
|
constructor() { |
16 |
|
|
super('snippet', 'utils', []); |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
async run(client: DiscordClient, msg: CommandInteraction, options: InteractionOptions) { |
20 |
|
|
if (options.options.getSubcommand(true) === 'get') { |
21 |
|
|
const snippet = await client.snippetManager.get(msg.guild!.id, options.options.getString('name')!); |
22 |
|
|
|
23 |
|
|
if (!snippet) { |
24 |
|
|
await msg.reply({ |
25 |
|
|
content: ":x: No snippet found with that name.", |
26 |
|
|
ephemeral: true |
27 |
|
|
}); |
28 |
|
|
|
29 |
|
|
return; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
await msg.reply({ |
33 |
|
|
content: snippet.content, |
34 |
|
|
files: snippet.files.map(name => { |
35 |
|
|
return { |
36 |
|
|
name, |
37 |
|
|
attachment: path.resolve(__dirname, '../../../storage', name) |
38 |
|
|
} as FileOptions |
39 |
|
|
}), |
40 |
|
|
}); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
let cmdName = ''; |
44 |
|
|
|
45 |
|
|
if (options.options.getSubcommand(true) === 'create') |
46 |
|
|
cmdName = 'addsnippet'; |
47 |
|
|
else if (options.options.getSubcommand(true) === 'delete') |
48 |
|
|
cmdName = 'delsnippet'; |
49 |
|
|
else if (options.options.getSubcommand(true) === 'rename') |
50 |
|
|
cmdName = 'mvsnippet'; |
51 |
|
|
|
52 |
|
|
const command = await client.commands.get(cmdName); |
53 |
|
|
|
54 |
|
|
if (command) { |
55 |
|
|
return await command.run(client, msg, options); |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
} |