1 |
import { CommandInteraction, FileOptions } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import InteractionOptions from '../../types/InteractionOptions'; |
5 |
import path from 'path'; |
6 |
|
7 |
export default class AddsnippetCommand extends BaseCommand { |
8 |
supportsInteractions: boolean = true; |
9 |
supportsLegacy: boolean = false; |
10 |
|
11 |
constructor() { |
12 |
super('snippet', 'utils', []); |
13 |
} |
14 |
|
15 |
async run(client: DiscordClient, msg: CommandInteraction, options: InteractionOptions) { |
16 |
if (options.options.getSubcommand(true) === 'get') { |
17 |
const snippet = await client.snippetManager.getParsed(msg.guild!.id, options.options.getString('name')!); |
18 |
|
19 |
if (!snippet) { |
20 |
await msg.reply({ |
21 |
content: ":x: No snippet found with that name.", |
22 |
ephemeral: true |
23 |
}); |
24 |
|
25 |
return; |
26 |
} |
27 |
|
28 |
try { |
29 |
await msg.reply({ |
30 |
content: snippet.content.trim() === '' ? undefined : snippet.content, |
31 |
files: snippet.files.map(name => { |
32 |
return { |
33 |
name, |
34 |
attachment: path.resolve(__dirname, '../../../storage', name) |
35 |
} as FileOptions |
36 |
}), |
37 |
embeds: snippet.embeds |
38 |
}); |
39 |
} |
40 |
catch (e) { |
41 |
console.log(e); |
42 |
await msg.reply({ content: 'Looks like that snippet is corrupted. Maybe invalid embed schema?', ephemeral: true }); |
43 |
} |
44 |
} |
45 |
|
46 |
let cmdName = ''; |
47 |
|
48 |
if (options.options.getSubcommand(true) === 'create') |
49 |
cmdName = 'addsnippet'; |
50 |
else if (options.options.getSubcommand(true) === 'delete') |
51 |
cmdName = 'delsnippet'; |
52 |
else if (options.options.getSubcommand(true) === 'rename') |
53 |
cmdName = 'mvsnippet'; |
54 |
|
55 |
const command = await client.commands.get(cmdName); |
56 |
|
57 |
if (command) { |
58 |
return await command.run(client, msg, options); |
59 |
} |
60 |
} |
61 |
} |