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 |
rakin |
255 |
const snippet = await client.snippetManager.getParsed(msg.guild!.id, options.options.getString('name')!); |
22 |
rakin |
51 |
|
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 |
rakin |
255 |
content: snippet.content.trim() === '' ? undefined : snippet.content, |
34 |
rakin |
51 |
files: snippet.files.map(name => { |
35 |
|
|
return { |
36 |
|
|
name, |
37 |
|
|
attachment: path.resolve(__dirname, '../../../storage', name) |
38 |
|
|
} as FileOptions |
39 |
|
|
}), |
40 |
rakin |
255 |
embeds: snippet.embeds |
41 |
rakin |
51 |
}); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
let cmdName = ''; |
45 |
|
|
|
46 |
|
|
if (options.options.getSubcommand(true) === 'create') |
47 |
|
|
cmdName = 'addsnippet'; |
48 |
|
|
else if (options.options.getSubcommand(true) === 'delete') |
49 |
|
|
cmdName = 'delsnippet'; |
50 |
|
|
else if (options.options.getSubcommand(true) === 'rename') |
51 |
|
|
cmdName = 'mvsnippet'; |
52 |
|
|
|
53 |
|
|
const command = await client.commands.get(cmdName); |
54 |
|
|
|
55 |
|
|
if (command) { |
56 |
|
|
return await command.run(client, msg, options); |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
} |