This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (76 loc) · 2.23 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
const { Plugin } = require('powercord/entities');
const commands = require('./commands');
const TAG_ARGUMENT_REGEX = /\$\$(@|\d+)/g;
module.exports = class Tags extends Plugin {
startPlugin () {
this.registerMain();
this.registerTags();
}
pluginWillUnload () {
this.unregisterTags();
powercord.api.commands.unregisterCommand('tag');
}
registerMain () {
powercord.api.commands.registerCommand({
command: 'tag',
description: 'Send, preview and manage your tags',
usage: '{c} <view|list|add|update|delete> <tagName> [tagContent]',
executor: (args) => {
const subcommand = commands[args[0]];
if (!subcommand) {
return {
send: false,
result: `\`${args[0]}\` is not a valid subcommand. Specify one of ${Object.keys(commands).map(cmd => `\`${cmd}\``).join(', ')}.`
};
}
return subcommand.executor(args.slice(1), this);
},
autocomplete: (args) => {
if (args[0] !== void 0 && args.length === 1) {
return {
commands: Object.values(commands).filter(({ command }) => command.includes(args[0].toLowerCase())),
header: 'tag subcommands'
};
}
const subcommand = commands[args[0]];
if (!subcommand || !subcommand.autocomplete) {
return false;
}
return subcommand.autocomplete(args.slice(1), this.settings);
}
});
}
registerTags () {
for (const tag of this.settings.getKeys()) {
this.registerTag(tag);
}
}
registerTag (name) {
const content = this.settings.get(name);
powercord.api.commands.registerCommand({
command: name,
description: `Tag: ${content}`,
usage: '{c}',
executor: (args) => ({
send: true,
result: content.replace(TAG_ARGUMENT_REGEX, (match, idx) => (
match === '$$@'
? args.join(' ')
: args[idx - 1]
))
})
});
}
unregisterTags () {
for (const tag of this.settings.getKeys()) {
this.unregisterTag(tag);
}
}
unregisterTag (name) {
powercord.api.commands.unregisterCommand(name);
}
reloadTag (name) {
this.unregisterTag(name);
this.registerTag(name);
}
};