-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
103 lines (93 loc) · 2.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const emotes = require('./emotes.json');
const { Plugin } = require('powercord/entities');
const markdownChars = [ '_', '*', '`', '~', '<', '>', '@', '\\' ];
const removeMarkdown = (emote) => {
let emoteFormatted = '';
for (const char of emote) {
emoteFormatted += markdownChars.includes(char) ? `\\${char}` : char;
}
return emoteFormatted;
};
module.exports = class Kaomoji extends Plugin {
startPlugin () {
powercord.api.commands.registerCommand({
command: 'kaomoji',
aliases: [ 'kao' ],
description: 'Appends a kaomoji to your message!',
usage: '{c} [ emotion ]',
executor: (args) => {
if (args[1] === 'random') {
const emoteSelection = emotes[args.shift()];
args.shift();
return {
send: true,
result: `${args.join(' ')} ${removeMarkdown(emoteSelection[Math.floor(Math.random() * emoteSelection.length)])}`
};
}
try {
const emoteSelection = emotes[args.shift()][args.shift()];
if (emoteSelection) {
return {
send: true,
result: `${args.join(' ')} ${removeMarkdown(emoteSelection)}`
};
}
throw new Error();
} catch {
return {
send: false,
result: 'There aren\'t any kaomoji for that emotion! Pick an emotion from the list. If you need help, check out <https://github.com/davidcralph/kaomoji>!'
};
}
},
autocomplete: (args) => {
if (args.length < 1 || args.length > 2) {
return false;
} else if (args.length === 1) {
return {
commands: Object.keys(emotes)
.filter((e) => e.includes(args[0].toLowerCase()))
.map((e) => ({
command: e,
description: ''
})),
header: 'Kaomoji Emotions'
};
} else if (args.length === 2) {
try {
const object = emotes[args.shift()];
const list = object.map((item, index) => ({
command: index,
description: item
}));
list.unshift({
command: 'random',
description: 'Pick random kaomoji'
});
return {
commands: list,
header: 'Kaomoji Emotions'
};
} catch {
return {
commands: [],
header: 'No kaomoji found :('
};
}
}
return {
commands: Object.keys(emotes)
.filter((e) => e.includes(args[0].toLowerCase()))
.map((e) => ({
command: e,
description: ''
})),
header: 'Kaomoji Emotions'
};
}
});
}
pluginWillUnload () {
powercord.api.commands.unregisterCommand('kaomoji');
}
};