This repository has been archived by the owner on Mar 21, 2019. It is now read-only.
/
plugin.js
72 lines (63 loc) · 2.63 KB
/
plugin.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
const { Collection } = require('eris');
const Command = require('./command');
module.exports = class MaikaPlugin {
/**
* Create a new Maika plugin instance
* @param {PluginMeta} info The plugin meta information
*/
constructor(info) {
this.name = info.name;
this.description = info.description;
this.visible = info.visible || true;
/** @type {Collection<import('./command')>} */
this.commands = new Collection();
this.file = null;
this.disabled = info.disabled || false;
info.commands.forEach((command) => {
if (command.disabled)
return;
if (this.commands.has(command.command))
return;
this.commands.set(command.command, new Command(command));
});
}
/**
* Sets the file for reloading, loading, & unloading
* @param {string} file The file from the file system
* @returns {MaikaPlugin} Instance to chain
*/
setFile(file) {
this.file = file;
return this;
}
/**
* See if the command exist
* @param {string} name The command name
* @returns {boolean}
*/
hasCommand(name) {
return this.commands.filter(c => c.command === name || c.aliases.includes(name)).length > 0;
}
/**
* Gets the command instance
* @param {string} name The command name
* @returns {import('./command')} The command instance
*/
getCommand(name) {
return this.commands.filter(c => c.command === name || c.aliases.includes(name))[0];
}
}
/**
* @typedef {Object} PluginMeta
* @prop {string} name The plugin name
* @prop {string} description The plugin description
* @prop {boolean} [visible=true] Should the plugin be visiable to all users?
* @prop {import('./command').CommandInfo[]} commands The array of commands to add
* @prop {boolean} [disabled=false] If the plugin should be disabled
*/
/**
* @typedef {(client: import('./client'), ctx: import('./context')) => IPromisedCommand} CommandRun
* @typedef {Promise<void>} IPromisedCommand
* @typedef {String[]} CommandAlias
* @typedef {"createInstantInvite" | "kickMembers" | "banMembers" | "administrator" | "manageChannels" | "manageGuild" | "addReactions" | "viewAuditLogs" | "voicePrioritySpeaker" | "readMessages" | "sendMessages" | "sendTTSMessages" | "manageMessages" | "embedLinks" | "attachFiles" | "readMessageHistory" | "mentionEveryone" | "externalEmojis" | "voiceConnect" | "voiceSpeak" | "voiceMuteMembers" | "voiceDeafenMembers"| "voiceUseVAD" | "changeNickname" | "manageNicknames" | "manageRoles" | "manageWebhooks" | "manageEmojis"} Permission
*/