-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
71 lines (69 loc) · 2.38 KB
/
index.ts
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
/* eslint-disable no-invalid-this */
import { UPlugin } from '@classes';
export default class CumcordLoader extends UPlugin {
public appId = Astra.commands.registerSection({
name: 'Cumcord',
icon: 'https://avatars.githubusercontent.com/u/81397549?s=500'
});
public window = window as any;
start(): void {
fetch('https://raw.githubusercontent.com/Cumcord/Cumcord/stable/dist/build.js').then(res =>
res.text().then(text => {
eval(text);
Astra.commands.registerCommand('Cumcord', {
name: 'plugin',
description: 'Manage Cumcord plugins.',
aliases: [],
applicationId: this.appId,
execute: async eArgs => {
const { options } = eArgs;
if (options.add) {
let plugUrl = options.add;
if (
plugUrl.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g)
) {
plugUrl = options.add.replace(/\/\s*$/, '');
const res = await fetch(`${plugUrl}/plugin.json`);
const manifest = await res.json();
console.log(manifest.name);
this.window.cumcord.plugins.importPlugin(plugUrl);
return {
content: `Added \`${manifest.name}\``
};
}
return {
content: 'Invalid plugin URL!'
};
}
if (options.remove) return {
content: `Removed \`${options.remove}\``
};
},
options: [
{
name: 'add',
description: 'The plugin to add.',
type: 3
},
{
name: 'remove',
description: 'The plugin to remove.',
type: 3,
choices: this.window.cumcord.plugins.pluginCache
? Object.keys(this.window.cumcord.plugins.pluginCache).map(plugin => ({
name: this.window.cumcord.plugins.pluginCache[plugin].manifest.name,
value: plugin
}))
: []
}
]
});
}));
}
stop(): void {
this.window.cumcord.uninject();
Astra.commands.unregisterSection(this.appId);
Astra.commands.unregisterCommands('hi');
Astra.n11s.show('Cumcord has unloaded.');
}
}