1 |
rakin |
344 |
import { CommandInteraction, Message } from 'discord.js'; |
2 |
rakin |
51 |
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 { fetchEmoji } from '../../utils/Emoji'; |
8 |
|
|
|
9 |
|
|
export default class MvsnippetCommand extends BaseCommand { |
10 |
|
|
constructor() { |
11 |
|
|
super('mvsnippet', 'utils', []); |
12 |
|
|
} |
13 |
|
|
|
14 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
15 |
|
|
if (!options.isInteraction && options.args[1] === undefined) { |
16 |
|
|
await msg.reply({ |
17 |
|
|
embeds: [ |
18 |
|
|
new MessageEmbed() |
19 |
|
|
.setColor('#f14a60') |
20 |
|
|
.setDescription(`This command requires at least two arguments.`) |
21 |
|
|
] |
22 |
|
|
}); |
23 |
|
|
|
24 |
|
|
return; |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
let name: string; |
28 |
|
|
let newName: string; |
29 |
|
|
|
30 |
|
|
if (options.isInteraction) { |
31 |
|
|
await (msg as CommandInteraction).deferReply(); |
32 |
|
|
name = <string> await options.options.getString('old-name'); |
33 |
|
|
newName = <string> await options.options.getString('new-name'); |
34 |
|
|
} |
35 |
|
|
else { |
36 |
|
|
name = options.args[0]; |
37 |
|
|
newName = options.args[1]; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
const oldsnippet = client.snippetManager.get(msg.guild!.id, name); |
41 |
|
|
const newsnippet = client.snippetManager.get(msg.guild!.id, newName); |
42 |
|
|
|
43 |
|
|
if (!oldsnippet) { |
44 |
|
|
await this.deferReply(msg, { |
45 |
|
|
embeds: [ |
46 |
|
|
new MessageEmbed() |
47 |
|
|
.setColor('#f14a60') |
48 |
|
|
.setDescription("No snippet exists with that name.") |
49 |
|
|
] |
50 |
|
|
}); |
51 |
|
|
|
52 |
|
|
return; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
if (newsnippet) { |
56 |
|
|
await this.deferReply(msg, { |
57 |
|
|
embeds: [ |
58 |
|
|
new MessageEmbed() |
59 |
|
|
.setColor('#f14a60') |
60 |
|
|
.setDescription("A snippet already exists with the new name.") |
61 |
|
|
] |
62 |
|
|
}); |
63 |
|
|
|
64 |
|
|
return; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
await client.snippetManager.deleteData(msg.guild!.id, name); |
68 |
|
|
await client.snippetManager.set(msg.guild!.id, newName, oldsnippet.content, oldsnippet.files); |
69 |
|
|
await client.snippetManager.write(); |
70 |
|
|
|
71 |
|
|
await this.deferReply(msg, { |
72 |
|
|
embeds: [ |
73 |
|
|
new MessageEmbed() |
74 |
|
|
.setDescription((await fetchEmoji('check'))!.toString() + " Snippet renamed") |
75 |
|
|
] |
76 |
|
|
}); |
77 |
|
|
} |
78 |
|
|
} |