1 |
import { FileOptions, TextChannel } from "discord.js"; |
2 |
import path from "path"; |
3 |
import DiscordClient from "../client/Client"; |
4 |
|
5 |
export default async (client: DiscordClient, command: string, msg_id: string, channel_id: string, guild_id: string) => { |
6 |
try { |
7 |
const guild = await client.guilds.cache.get(guild_id); |
8 |
|
9 |
if (guild) { |
10 |
const channel = await guild.channels.fetch(channel_id); |
11 |
|
12 |
if (channel) { |
13 |
const msg = await (channel as TextChannel).messages.fetch(msg_id); |
14 |
|
15 |
if (msg) { |
16 |
const realMessage = await client.msg; |
17 |
client.msg = await msg; |
18 |
|
19 |
const argv = command.split(/ +/g); |
20 |
const args = [...argv]; |
21 |
const cmdName = args.shift(); |
22 |
const cmdObj = await client.commands.get(cmdName!); |
23 |
|
24 |
console.log(command); |
25 |
|
26 |
if (cmdObj && cmdObj.supportsLegacy) { |
27 |
await cmdObj.run(client, msg, { |
28 |
argv, |
29 |
args, |
30 |
normalArgs: args.filter(a => a[0] !== '-'), |
31 |
options: args.filter(a => a[0] === '-'), |
32 |
isInteraction: false, |
33 |
cmdName: cmdName! |
34 |
}); |
35 |
|
36 |
client.msg = realMessage; |
37 |
|
38 |
return; |
39 |
} |
40 |
|
41 |
const snippet = await client.snippetManager.get(msg.guild!.id, cmdName!); |
42 |
|
43 |
if (snippet) { |
44 |
await msg.channel.send({ |
45 |
content: snippet.content, |
46 |
files: snippet.files.map(name => { |
47 |
return { |
48 |
name, |
49 |
attachment: path.resolve(__dirname, '../../storage', name) |
50 |
} as FileOptions |
51 |
}), |
52 |
}); |
53 |
|
54 |
client.msg = realMessage; |
55 |
|
56 |
return; |
57 |
} |
58 |
} |
59 |
} |
60 |
} |
61 |
} |
62 |
catch (e) { |
63 |
console.log(e); |
64 |
} |
65 |
}; |