This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (55 loc) · 1.92 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { Plugin } = require('powercord/entities');
const { channels, getModule } = require("powercord/webpack");
module.exports = class SendEmbeds extends Plugin {
async startPlugin () {
let MessageQueue = await getModule(m => m.enqueue, false);
let MessageParser = await getModule(['createBotMessage'], false);
powercord.api.commands.registerCommand({
command: 'jsonembed',
description: 'Send JSON embed',
usage: '{c} [json data]',
executor: (args) => {
let discordEmbed = null
// parse and clean json input
try {
discordEmbed = JSON.parse(args.join(' '))
if (discordEmbed.color !== undefined
&& discordEmbed.color.match !== undefined
&& discordEmbed.color.match(/^#?[0-9A-Z]{6}/gi) !== undefined) {
discordEmbed.color = discordEmbed.color.replace(/#/g, "");
discordEmbed.color = parseInt(discordEmbed.color, 16);
}
} catch (e) {
return { send: false, result: `Failed to parse your input: ${e}` }
}
// send message
try {
let channelID = channels.getChannelId();
let msg = MessageParser.createBotMessage(channelID, '');
MessageQueue.enqueue({
type: 0,
message: {
channelId: channelID,
content: '',
tts: false,
nonce: msg.id,
embed: discordEmbed
}
}, r => {
if (r.ok !== true) {
powercord.api.notices.sendToast('jsonembed', {
header: `Failed to send the message: ${r.body.message}`
})
}
})
} catch (e) {
return { send: false, result: `Failed to send the message: ${e}` }
}
return {send: false, result: null}
}
});
}
pluginWillUnload () {
powercord.api.commands.unregisterCommand('jsonembed');
}
};