@open-discord-bots/framework 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +713 -0
- package/README.md +104 -0
- package/dist/api/api.d.ts +26 -0
- package/dist/api/api.js +44 -0
- package/dist/api/main.d.ts +133 -0
- package/dist/api/main.js +87 -0
- package/dist/api/modules/action.d.ts +34 -0
- package/dist/api/modules/action.js +58 -0
- package/dist/api/modules/base.d.ts +329 -0
- package/dist/api/modules/base.js +804 -0
- package/dist/api/modules/builder.d.ts +647 -0
- package/dist/api/modules/builder.js +1441 -0
- package/dist/api/modules/checker.d.ts +648 -0
- package/dist/api/modules/checker.js +1324 -0
- package/dist/api/modules/client.d.ts +768 -0
- package/dist/api/modules/client.js +1859 -0
- package/dist/api/modules/code.d.ts +33 -0
- package/dist/api/modules/code.js +57 -0
- package/dist/api/modules/config.d.ts +70 -0
- package/dist/api/modules/config.js +206 -0
- package/dist/api/modules/console.d.ts +305 -0
- package/dist/api/modules/console.js +598 -0
- package/dist/api/modules/cooldown.d.ts +138 -0
- package/dist/api/modules/cooldown.js +359 -0
- package/dist/api/modules/database.d.ts +135 -0
- package/dist/api/modules/database.js +271 -0
- package/dist/api/modules/event.d.ts +43 -0
- package/dist/api/modules/event.js +100 -0
- package/dist/api/modules/flag.d.ts +40 -0
- package/dist/api/modules/flag.js +72 -0
- package/dist/api/modules/fuse.d.ts +218 -0
- package/dist/api/modules/fuse.js +123 -0
- package/dist/api/modules/helpmenu.d.ts +106 -0
- package/dist/api/modules/helpmenu.js +167 -0
- package/dist/api/modules/language.d.ts +85 -0
- package/dist/api/modules/language.js +195 -0
- package/dist/api/modules/permission.d.ts +121 -0
- package/dist/api/modules/permission.js +314 -0
- package/dist/api/modules/plugin.d.ts +128 -0
- package/dist/api/modules/plugin.js +168 -0
- package/dist/api/modules/post.d.ts +44 -0
- package/dist/api/modules/post.js +92 -0
- package/dist/api/modules/progressbar.d.ts +108 -0
- package/dist/api/modules/progressbar.js +233 -0
- package/dist/api/modules/responder.d.ts +506 -0
- package/dist/api/modules/responder.js +1468 -0
- package/dist/api/modules/session.d.ts +58 -0
- package/dist/api/modules/session.js +171 -0
- package/dist/api/modules/startscreen.d.ts +165 -0
- package/dist/api/modules/startscreen.js +293 -0
- package/dist/api/modules/stat.d.ts +142 -0
- package/dist/api/modules/stat.js +293 -0
- package/dist/api/modules/verifybar.d.ts +54 -0
- package/dist/api/modules/verifybar.js +60 -0
- package/dist/api/modules/worker.d.ts +41 -0
- package/dist/api/modules/worker.js +93 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +254 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +40 -0
- package/dist/startup/dump.d.ts +14 -0
- package/dist/startup/dump.js +79 -0
- package/dist/startup/errorHandling.d.ts +2 -0
- package/dist/startup/errorHandling.js +43 -0
- package/dist/startup/pluginLauncher.d.ts +2 -0
- package/dist/startup/pluginLauncher.js +202 -0
- package/package.json +9 -3
- package/src/api/api.ts +29 -0
- package/src/api/main.ts +189 -0
- package/src/api/modules/action.ts +58 -0
- package/src/api/modules/base.ts +811 -0
- package/src/api/modules/builder.ts +1554 -0
- package/src/api/modules/checker.ts +1549 -0
- package/src/api/modules/client.ts +2247 -0
- package/src/api/modules/code.ts +58 -0
- package/src/api/modules/config.ts +159 -0
- package/src/api/modules/console.ts +665 -0
- package/src/api/modules/cooldown.ts +348 -0
- package/src/api/modules/database.ts +278 -0
- package/src/api/modules/event.ts +99 -0
- package/src/api/modules/flag.ts +73 -0
- package/src/api/modules/fuse.ts +348 -0
- package/src/api/modules/helpmenu.ts +216 -0
- package/src/api/modules/language.ts +201 -0
- package/src/api/modules/permission.ts +340 -0
- package/src/api/modules/plugin.ts +242 -0
- package/src/api/modules/post.ts +90 -0
- package/src/api/modules/progressbar.ts +232 -0
- package/src/api/modules/responder.ts +1420 -0
- package/src/api/modules/session.ts +155 -0
- package/src/api/modules/startscreen.ts +320 -0
- package/src/api/modules/stat.ts +313 -0
- package/src/api/modules/verifybar.ts +61 -0
- package/src/api/modules/worker.ts +93 -0
- package/src/api/utils.ts +206 -0
- package/src/cli/cli.ts +151 -0
- package/src/cli/editConfig.ts +943 -0
- package/src/index.ts +6 -1
- package/src/startup/compilation.ts +186 -0
- package/src/startup/dump.ts +45 -0
- package/src/startup/errorHandling.ts +38 -0
- package/src/startup/pluginLauncher.ts +261 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ODPermissionManager = exports.ODPermission = exports.ODPermissionLevel = void 0;
|
|
37
|
+
///////////////////////////////////////
|
|
38
|
+
//PERMISSION MODULE
|
|
39
|
+
///////////////////////////////////////
|
|
40
|
+
const base_1 = require("./base");
|
|
41
|
+
const discord = __importStar(require("discord.js"));
|
|
42
|
+
/**## ODPermissionLevel `enum`
|
|
43
|
+
* All available permission types/levels. But as `enum` instead of `type`. Used to calculate the level.
|
|
44
|
+
*/
|
|
45
|
+
var ODPermissionLevel;
|
|
46
|
+
(function (ODPermissionLevel) {
|
|
47
|
+
/**A normal member. (Default for everyone) */
|
|
48
|
+
ODPermissionLevel[ODPermissionLevel["member"] = 0] = "member";
|
|
49
|
+
/**Support team. Higher than a normal member. (Used for ticket-admins) */
|
|
50
|
+
ODPermissionLevel[ODPermissionLevel["support"] = 1] = "support";
|
|
51
|
+
/**Moderator. Higher than the support team. (Unused) */
|
|
52
|
+
ODPermissionLevel[ODPermissionLevel["moderator"] = 2] = "moderator";
|
|
53
|
+
/**Admin. Higher than a moderator. (Used for global-admins) */
|
|
54
|
+
ODPermissionLevel[ODPermissionLevel["admin"] = 3] = "admin";
|
|
55
|
+
/**Server owner. (Able to use all commands including `/stats reset`) */
|
|
56
|
+
ODPermissionLevel[ODPermissionLevel["owner"] = 4] = "owner";
|
|
57
|
+
/**Bot owner or all users from dev team. (Able to use all commands including `/stats reset`) */
|
|
58
|
+
ODPermissionLevel[ODPermissionLevel["developer"] = 5] = "developer";
|
|
59
|
+
})(ODPermissionLevel || (exports.ODPermissionLevel = ODPermissionLevel = {}));
|
|
60
|
+
/**## ODPermission `class`
|
|
61
|
+
* This is an Open Discord permission.
|
|
62
|
+
*
|
|
63
|
+
* It defines a single permission level for a specific scope (global/channel & user/role)
|
|
64
|
+
* These permissions only apply to commands & interactions.
|
|
65
|
+
* They are not related to channel permissions in the ticket system.
|
|
66
|
+
*
|
|
67
|
+
* Register this class to an `ODPermissionManager` to use it!
|
|
68
|
+
*/
|
|
69
|
+
class ODPermission extends base_1.ODManagerData {
|
|
70
|
+
/**The scope of this permission. */
|
|
71
|
+
scope;
|
|
72
|
+
/**The type/level of this permission. */
|
|
73
|
+
permission;
|
|
74
|
+
/**The user/role of this permission. */
|
|
75
|
+
value;
|
|
76
|
+
/**The channel that this permission applies to. (`null` when global) */
|
|
77
|
+
channel;
|
|
78
|
+
constructor(id, scope, permission, value, channel) {
|
|
79
|
+
super(id);
|
|
80
|
+
this.scope = scope;
|
|
81
|
+
this.permission = permission;
|
|
82
|
+
this.value = value;
|
|
83
|
+
this.channel = channel ?? null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ODPermission = ODPermission;
|
|
87
|
+
/**## ODPermissionManager `class`
|
|
88
|
+
* This is an Open Discord permission manager.
|
|
89
|
+
*
|
|
90
|
+
* It manages all permissions in the bot!
|
|
91
|
+
* Use the `getPermissions()` and `hasPermissions()` methods to get user perms.
|
|
92
|
+
*
|
|
93
|
+
* Add new permissions using the `ODPermission` class in your plugin!
|
|
94
|
+
*/
|
|
95
|
+
class ODPermissionManager extends base_1.ODManager {
|
|
96
|
+
/**Alias for Open Discord debugger. */
|
|
97
|
+
#debug;
|
|
98
|
+
/**The function for calculating permissions in this manager. */
|
|
99
|
+
#calculation;
|
|
100
|
+
/**An alias to the Open Discord client manager. */
|
|
101
|
+
#client;
|
|
102
|
+
/**The result which is returned when no other permissions match. (`member` by default) */
|
|
103
|
+
defaultResult = {
|
|
104
|
+
level: ODPermissionLevel["member"],
|
|
105
|
+
scope: "default",
|
|
106
|
+
type: "member",
|
|
107
|
+
source: null
|
|
108
|
+
};
|
|
109
|
+
constructor(debug, client, useDefaultCalculation) {
|
|
110
|
+
super(debug, "permission");
|
|
111
|
+
this.#debug = debug;
|
|
112
|
+
this.#calculation = useDefaultCalculation ? this.#defaultCalculation : null;
|
|
113
|
+
this.#client = client;
|
|
114
|
+
}
|
|
115
|
+
/**Edit the permission calculation function in this manager. */
|
|
116
|
+
setCalculation(calculation) {
|
|
117
|
+
this.#calculation = calculation;
|
|
118
|
+
}
|
|
119
|
+
/**Edit the result which is returned when no other permissions match. (`member` by default) */
|
|
120
|
+
setDefaultResult(result) {
|
|
121
|
+
this.defaultResult = result;
|
|
122
|
+
}
|
|
123
|
+
/**Get an `ODPermissionResult` based on a few context factors. Use `hasPermissions()` to simplify the result. */
|
|
124
|
+
getPermissions(user, channel, guild, settings) {
|
|
125
|
+
try {
|
|
126
|
+
if (!this.#calculation)
|
|
127
|
+
throw new base_1.ODSystemError("ODPermissionManager:getPermissions() => missing perms calculation");
|
|
128
|
+
return this.#calculation(user, channel, guild, settings);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
process.emit("uncaughtException", err);
|
|
132
|
+
throw new base_1.ODSystemError("ODPermissionManager:getPermissions() => failed perms calculation");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**Simplifies the `ODPermissionResult` returned from `getPermissions()` and returns a boolean to check if the user matches the required permissions. */
|
|
136
|
+
hasPermissions(minimum, data) {
|
|
137
|
+
if (minimum == "member")
|
|
138
|
+
return true;
|
|
139
|
+
else if (minimum == "support")
|
|
140
|
+
return (data.level >= ODPermissionLevel["support"]);
|
|
141
|
+
else if (minimum == "moderator")
|
|
142
|
+
return (data.level >= ODPermissionLevel["moderator"]);
|
|
143
|
+
else if (minimum == "admin")
|
|
144
|
+
return (data.level >= ODPermissionLevel["admin"]);
|
|
145
|
+
else if (minimum == "owner")
|
|
146
|
+
return (data.level >= ODPermissionLevel["owner"]);
|
|
147
|
+
else if (minimum == "developer")
|
|
148
|
+
return (data.level >= ODPermissionLevel["developer"]);
|
|
149
|
+
else
|
|
150
|
+
throw new base_1.ODSystemError("Invalid minimum permission type at ODPermissionManager.hasPermissions()");
|
|
151
|
+
}
|
|
152
|
+
/**Check for permissions. (default calculation) */
|
|
153
|
+
async #defaultCalculation(user, channel, guild, settings) {
|
|
154
|
+
const globalCalc = await this.#defaultGlobalCalculation(user, channel, guild, settings);
|
|
155
|
+
const channelCalc = await this.#defaultChannelCalculation(user, channel, guild, settings);
|
|
156
|
+
if (globalCalc.level > channelCalc.level)
|
|
157
|
+
return globalCalc;
|
|
158
|
+
else
|
|
159
|
+
return channelCalc;
|
|
160
|
+
}
|
|
161
|
+
/**Check for global permissions. Result will be compared with the channel perms in `#defaultCalculation()`. */
|
|
162
|
+
async #defaultGlobalCalculation(user, channel, guild, settings) {
|
|
163
|
+
const idRegex = (settings && typeof settings.idRegex != "undefined") ? settings.idRegex : null;
|
|
164
|
+
const allowGlobalUserScope = (settings && typeof settings.allowGlobalUserScope != "undefined") ? settings.allowGlobalUserScope : true;
|
|
165
|
+
const allowGlobalRoleScope = (settings && typeof settings.allowGlobalRoleScope != "undefined") ? settings.allowGlobalRoleScope : true;
|
|
166
|
+
//check for global user permissions
|
|
167
|
+
if (allowGlobalUserScope) {
|
|
168
|
+
const users = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "global-user" && (permission.value instanceof discord.User) && permission.value.id == user.id);
|
|
169
|
+
if (users.length > 0) {
|
|
170
|
+
//sort all permisions from highest to lowest
|
|
171
|
+
users.sort((a, b) => {
|
|
172
|
+
const levelA = ODPermissionLevel[a.permission];
|
|
173
|
+
const levelB = ODPermissionLevel[b.permission];
|
|
174
|
+
if (levelB > levelA)
|
|
175
|
+
return 1;
|
|
176
|
+
else if (levelA > levelB)
|
|
177
|
+
return -1;
|
|
178
|
+
else
|
|
179
|
+
return 0;
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
type: users[0].permission,
|
|
183
|
+
scope: "global-user",
|
|
184
|
+
level: ODPermissionLevel[users[0].permission],
|
|
185
|
+
source: users[0] ?? null
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//check for global role permissions
|
|
190
|
+
if (allowGlobalRoleScope) {
|
|
191
|
+
if (guild) {
|
|
192
|
+
const member = await this.#client.fetchGuildMember(guild, user.id);
|
|
193
|
+
if (member) {
|
|
194
|
+
const memberRoles = member.roles.cache.map((role) => role.id);
|
|
195
|
+
const roles = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "global-role" && (permission.value instanceof discord.Role) && memberRoles.includes(permission.value.id) && permission.value.guild.id == guild.id);
|
|
196
|
+
if (roles.length > 0) {
|
|
197
|
+
//sort all permisions from highest to lowest
|
|
198
|
+
roles.sort((a, b) => {
|
|
199
|
+
const levelA = ODPermissionLevel[a.permission];
|
|
200
|
+
const levelB = ODPermissionLevel[b.permission];
|
|
201
|
+
if (levelB > levelA)
|
|
202
|
+
return 1;
|
|
203
|
+
else if (levelA > levelB)
|
|
204
|
+
return -1;
|
|
205
|
+
else
|
|
206
|
+
return 0;
|
|
207
|
+
});
|
|
208
|
+
return {
|
|
209
|
+
type: roles[0].permission,
|
|
210
|
+
scope: "global-role",
|
|
211
|
+
level: ODPermissionLevel[roles[0].permission],
|
|
212
|
+
source: roles[0] ?? null
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//spread result to prevent accidental referencing
|
|
219
|
+
return { ...this.defaultResult };
|
|
220
|
+
}
|
|
221
|
+
/**Check for channel permissions. Result will be compared with the global perms in `#defaultCalculation()`. */
|
|
222
|
+
async #defaultChannelCalculation(user, channel, guild, settings) {
|
|
223
|
+
const idRegex = (settings && typeof settings.idRegex != "undefined") ? settings.idRegex : null;
|
|
224
|
+
const allowChannelUserScope = (settings && typeof settings.allowChannelUserScope != "undefined") ? settings.allowChannelUserScope : true;
|
|
225
|
+
const allowChannelRoleScope = (settings && typeof settings.allowChannelRoleScope != "undefined") ? settings.allowChannelRoleScope : true;
|
|
226
|
+
if (guild && channel && !channel.isDMBased()) {
|
|
227
|
+
//check for channel user permissions
|
|
228
|
+
if (allowChannelUserScope) {
|
|
229
|
+
const users = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-user" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.User) && permission.value.id == user.id);
|
|
230
|
+
if (users.length > 0) {
|
|
231
|
+
//sort all permisions from highest to lowest
|
|
232
|
+
users.sort((a, b) => {
|
|
233
|
+
const levelA = ODPermissionLevel[a.permission];
|
|
234
|
+
const levelB = ODPermissionLevel[b.permission];
|
|
235
|
+
if (levelB > levelA)
|
|
236
|
+
return 1;
|
|
237
|
+
else if (levelA > levelB)
|
|
238
|
+
return -1;
|
|
239
|
+
else
|
|
240
|
+
return 0;
|
|
241
|
+
});
|
|
242
|
+
return {
|
|
243
|
+
type: users[0].permission,
|
|
244
|
+
scope: "channel-user",
|
|
245
|
+
level: ODPermissionLevel[users[0].permission],
|
|
246
|
+
source: users[0] ?? null
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//check for channel role permissions
|
|
251
|
+
if (allowChannelRoleScope) {
|
|
252
|
+
const member = await this.#client.fetchGuildMember(guild, user.id);
|
|
253
|
+
if (member) {
|
|
254
|
+
const memberRoles = member.roles.cache.map((role) => role.id);
|
|
255
|
+
const roles = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-role" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.Role) && memberRoles.includes(permission.value.id) && permission.value.guild.id == guild.id);
|
|
256
|
+
if (roles.length > 0) {
|
|
257
|
+
//sort all permisions from highest to lowest
|
|
258
|
+
roles.sort((a, b) => {
|
|
259
|
+
const levelA = ODPermissionLevel[a.permission];
|
|
260
|
+
const levelB = ODPermissionLevel[b.permission];
|
|
261
|
+
if (levelB > levelA)
|
|
262
|
+
return 1;
|
|
263
|
+
else if (levelA > levelB)
|
|
264
|
+
return -1;
|
|
265
|
+
else
|
|
266
|
+
return 0;
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
type: roles[0].permission,
|
|
270
|
+
scope: "channel-role",
|
|
271
|
+
level: ODPermissionLevel[roles[0].permission],
|
|
272
|
+
source: roles[0] ?? null
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//spread result to prevent accidental modification because of referencing
|
|
279
|
+
return { ...this.defaultResult };
|
|
280
|
+
}
|
|
281
|
+
/**Check the permissions for a certain command of the bot. */
|
|
282
|
+
async checkCommandPerms(permissionMode, requiredLevel, user, member, channel, guild, settings) {
|
|
283
|
+
if (permissionMode === "none") {
|
|
284
|
+
return { hasPerms: false, reason: "disabled" };
|
|
285
|
+
}
|
|
286
|
+
else if (permissionMode === "everyone") {
|
|
287
|
+
const isAdmin = this.hasPermissions(requiredLevel, await this.getPermissions(user, channel, guild, settings));
|
|
288
|
+
return { hasPerms: true, isAdmin };
|
|
289
|
+
}
|
|
290
|
+
else if (permissionMode === "admin") {
|
|
291
|
+
const isAdmin = this.hasPermissions(requiredLevel, await this.getPermissions(user, channel, guild, settings));
|
|
292
|
+
if (!isAdmin)
|
|
293
|
+
return { hasPerms: false, reason: "no-perms" };
|
|
294
|
+
else
|
|
295
|
+
return { hasPerms: true, isAdmin };
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
if (!guild || !member) {
|
|
299
|
+
this.#debug.debug("ODPermissionManager.checkCommandPerms(): Permission Error, Not in server! (#1)");
|
|
300
|
+
return { hasPerms: false, reason: "not-in-server" };
|
|
301
|
+
}
|
|
302
|
+
const role = await this.#client.fetchGuildRole(guild, permissionMode);
|
|
303
|
+
if (!role) {
|
|
304
|
+
this.#debug.debug("ODPermissionManager.checkCommandPerms(): Permission Error, Not in server! (#2)");
|
|
305
|
+
return { hasPerms: false, reason: "not-in-server" };
|
|
306
|
+
}
|
|
307
|
+
if (!role.members.has(member.id))
|
|
308
|
+
return { hasPerms: false, reason: "no-perms" };
|
|
309
|
+
const isAdmin = this.hasPermissions(requiredLevel, await this.getPermissions(user, channel, guild, settings));
|
|
310
|
+
return { hasPerms: true, isAdmin };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.ODPermissionManager = ODPermissionManager;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ODManager, ODManagerData, ODValidId, ODVersion } from "./base";
|
|
2
|
+
import { ODDebugger } from "./console";
|
|
3
|
+
/**## ODUnknownCrashedPlugin `interface`
|
|
4
|
+
* Basic details for a plugin that crashed while loading the `plugin.json` file.
|
|
5
|
+
*/
|
|
6
|
+
export interface ODUnknownCrashedPlugin {
|
|
7
|
+
/**The name of the plugin. (path when plugin crashed before `name` was loaded) */
|
|
8
|
+
name: string;
|
|
9
|
+
/**The description of the plugin. (when found before crashing) */
|
|
10
|
+
description: string;
|
|
11
|
+
}
|
|
12
|
+
/**## ODPluginManager `class`
|
|
13
|
+
* This is an Open Discord plugin manager.
|
|
14
|
+
*
|
|
15
|
+
* It manages all active plugins in the bot!
|
|
16
|
+
* It also contains all "plugin classes" which are managers registered by plugins.
|
|
17
|
+
* These are accessible via the `opendiscord.plugins.classes` global.
|
|
18
|
+
*
|
|
19
|
+
* Use `isPluginLoaded()` to check if a plugin has been loaded.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ODPluginManager extends ODManager<ODPlugin> {
|
|
22
|
+
/**A manager for all custom managers registered by plugins. */
|
|
23
|
+
classes: ODPluginClassManager;
|
|
24
|
+
/**A list of basic details from all plugins that crashed while loading the `plugin.json` file. */
|
|
25
|
+
unknownCrashedPlugins: ODUnknownCrashedPlugin[];
|
|
26
|
+
constructor(debug: ODDebugger);
|
|
27
|
+
/**Check if a plugin has been loaded successfully and is available for usage.*/
|
|
28
|
+
isPluginLoaded(id: ODValidId): boolean;
|
|
29
|
+
}
|
|
30
|
+
/**## ODPluginData `interface`
|
|
31
|
+
* Parsed data from the `plugin.json` file in a plugin.
|
|
32
|
+
*/
|
|
33
|
+
export interface ODPluginData {
|
|
34
|
+
/**The name of this plugin (shown on startup) */
|
|
35
|
+
name: string;
|
|
36
|
+
/**The id of this plugin. (Must be identical to directory name) */
|
|
37
|
+
id: string;
|
|
38
|
+
/**The version of this plugin. */
|
|
39
|
+
version: string;
|
|
40
|
+
/**The location of the start file of the plugin relative to the rootDir of the plugin */
|
|
41
|
+
startFile: string;
|
|
42
|
+
/**Is this plugin enabled? */
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/**The priority of this plugin. Higher priority will load before lower priority. */
|
|
45
|
+
priority: number;
|
|
46
|
+
/**A list of events to register to the `opendiscord.events` global before loading any plugins. This way, plugins with a higher priority are able to use events from this plugin as well! */
|
|
47
|
+
events: string[];
|
|
48
|
+
/**Npm dependencies which are required for this plugin to work. */
|
|
49
|
+
npmDependencies: string[];
|
|
50
|
+
/**Plugins which are required for this plugin to work. */
|
|
51
|
+
requiredPlugins: string[];
|
|
52
|
+
/**Plugins which are incompatible with this plugin. */
|
|
53
|
+
incompatiblePlugins: string[];
|
|
54
|
+
/**Additional details about this plugin. */
|
|
55
|
+
details: ODPluginDetails;
|
|
56
|
+
}
|
|
57
|
+
/**## ODPluginDetails `interface`
|
|
58
|
+
* Additional details in the `plugin.json` file from a plugin.
|
|
59
|
+
*/
|
|
60
|
+
export interface ODPluginDetails {
|
|
61
|
+
/**The author of the plugin. */
|
|
62
|
+
author: string;
|
|
63
|
+
/**A short description of this plugin. */
|
|
64
|
+
shortDescription: string;
|
|
65
|
+
/**A large description of this plugin. */
|
|
66
|
+
longDescription: string;
|
|
67
|
+
/**A URL to a cover image of this plugin. (currently unused) */
|
|
68
|
+
imageUrl: string;
|
|
69
|
+
/**A URL to the website/project page of this plugin. (currently unused) */
|
|
70
|
+
projectUrl: string;
|
|
71
|
+
/**A list of tags/categories that this plugin affects. */
|
|
72
|
+
tags: string[];
|
|
73
|
+
}
|
|
74
|
+
/**## ODPlugin `class`
|
|
75
|
+
* This is an Open Discord plugin.
|
|
76
|
+
*
|
|
77
|
+
* It represents a single plugin in the `./plugins/` directory.
|
|
78
|
+
* All plugins are accessible via the `opendiscord.plugins` global.
|
|
79
|
+
*
|
|
80
|
+
* Don't re-execute plugins which are already enabled! It might break the bot or plugin.
|
|
81
|
+
*/
|
|
82
|
+
export declare class ODPlugin extends ODManagerData {
|
|
83
|
+
#private;
|
|
84
|
+
/**The name of the directory of this plugin. (same as id) */
|
|
85
|
+
dir: string;
|
|
86
|
+
/**All plugin data found in the `plugin.json` file. */
|
|
87
|
+
data: ODPluginData;
|
|
88
|
+
/**The name of this plugin. */
|
|
89
|
+
name: string;
|
|
90
|
+
/**The priority of this plugin. */
|
|
91
|
+
priority: number;
|
|
92
|
+
/**The version of this plugin. */
|
|
93
|
+
version: ODVersion;
|
|
94
|
+
/**The additional details of this plugin. */
|
|
95
|
+
details: ODPluginDetails;
|
|
96
|
+
/**Is this plugin enabled? */
|
|
97
|
+
enabled: boolean;
|
|
98
|
+
/**Did this plugin execute successfully?. */
|
|
99
|
+
executed: boolean;
|
|
100
|
+
/**Did this plugin crash? (A reason is available in the `crashReason`) */
|
|
101
|
+
crashed: boolean;
|
|
102
|
+
/**The reason which caused this plugin to crash. */
|
|
103
|
+
crashReason: null | "incompatible.plugin" | "missing.plugin" | "missing.dependency" | "executed";
|
|
104
|
+
constructor(dir: string, jsondata: ODPluginData);
|
|
105
|
+
/**Get the startfile location relative to the `./plugins/` directory. (`./dist/plugins/`) when compiled) */
|
|
106
|
+
getStartFile(): string;
|
|
107
|
+
/**Execute this plugin. Returns `false` on crash. */
|
|
108
|
+
execute(debug: ODDebugger, force?: boolean): Promise<boolean>;
|
|
109
|
+
/**Get a list of all missing npm dependencies that are required for this plugin. */
|
|
110
|
+
dependenciesInstalled(): string[];
|
|
111
|
+
/**Get a list of all missing plugins that are required for this plugin. */
|
|
112
|
+
pluginsInstalled(manager: ODPluginManager): string[];
|
|
113
|
+
/**Get a list of all enabled incompatible plugins that interfere with this plugin. */
|
|
114
|
+
pluginsIncompatible(manager: ODPluginManager): string[];
|
|
115
|
+
}
|
|
116
|
+
/**## ODPluginClassManager `class`
|
|
117
|
+
* This is an Open Discord plugin class manager.
|
|
118
|
+
*
|
|
119
|
+
* It manages all managers registered by plugins!
|
|
120
|
+
* Plugins are able to register their own managers, handlers, functions, classes, ... here.
|
|
121
|
+
* By doing this, other plugins are also able to make use of it.
|
|
122
|
+
* This can be useful for plugins that want to extend other plugins.
|
|
123
|
+
*
|
|
124
|
+
* Use `isPluginLoaded()` to check if a plugin has been loaded before trying to access the manager.
|
|
125
|
+
*/
|
|
126
|
+
export declare class ODPluginClassManager extends ODManager<ODManagerData> {
|
|
127
|
+
constructor(debug: ODDebugger);
|
|
128
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ODPluginClassManager = exports.ODPlugin = exports.ODPluginManager = void 0;
|
|
7
|
+
///////////////////////////////////////
|
|
8
|
+
//PLUGIN MODULE
|
|
9
|
+
///////////////////////////////////////
|
|
10
|
+
const base_1 = require("./base");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
/**## ODPluginManager `class`
|
|
13
|
+
* This is an Open Discord plugin manager.
|
|
14
|
+
*
|
|
15
|
+
* It manages all active plugins in the bot!
|
|
16
|
+
* It also contains all "plugin classes" which are managers registered by plugins.
|
|
17
|
+
* These are accessible via the `opendiscord.plugins.classes` global.
|
|
18
|
+
*
|
|
19
|
+
* Use `isPluginLoaded()` to check if a plugin has been loaded.
|
|
20
|
+
*/
|
|
21
|
+
class ODPluginManager extends base_1.ODManager {
|
|
22
|
+
/**A manager for all custom managers registered by plugins. */
|
|
23
|
+
classes;
|
|
24
|
+
/**A list of basic details from all plugins that crashed while loading the `plugin.json` file. */
|
|
25
|
+
unknownCrashedPlugins = [];
|
|
26
|
+
constructor(debug) {
|
|
27
|
+
super(debug, "plugin");
|
|
28
|
+
this.classes = new ODPluginClassManager(debug);
|
|
29
|
+
}
|
|
30
|
+
/**Check if a plugin has been loaded successfully and is available for usage.*/
|
|
31
|
+
isPluginLoaded(id) {
|
|
32
|
+
const newId = new base_1.ODId(id);
|
|
33
|
+
const plugin = this.get(newId);
|
|
34
|
+
return (plugin !== null && plugin.executed);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ODPluginManager = ODPluginManager;
|
|
38
|
+
/**## ODPlugin `class`
|
|
39
|
+
* This is an Open Discord plugin.
|
|
40
|
+
*
|
|
41
|
+
* It represents a single plugin in the `./plugins/` directory.
|
|
42
|
+
* All plugins are accessible via the `opendiscord.plugins` global.
|
|
43
|
+
*
|
|
44
|
+
* Don't re-execute plugins which are already enabled! It might break the bot or plugin.
|
|
45
|
+
*/
|
|
46
|
+
class ODPlugin extends base_1.ODManagerData {
|
|
47
|
+
/**The name of the directory of this plugin. (same as id) */
|
|
48
|
+
dir;
|
|
49
|
+
/**All plugin data found in the `plugin.json` file. */
|
|
50
|
+
data;
|
|
51
|
+
/**The name of this plugin. */
|
|
52
|
+
name;
|
|
53
|
+
/**The priority of this plugin. */
|
|
54
|
+
priority;
|
|
55
|
+
/**The version of this plugin. */
|
|
56
|
+
version;
|
|
57
|
+
/**The additional details of this plugin. */
|
|
58
|
+
details;
|
|
59
|
+
/**Is this plugin enabled? */
|
|
60
|
+
enabled;
|
|
61
|
+
/**Did this plugin execute successfully?. */
|
|
62
|
+
executed;
|
|
63
|
+
/**Did this plugin crash? (A reason is available in the `crashReason`) */
|
|
64
|
+
crashed;
|
|
65
|
+
/**The reason which caused this plugin to crash. */
|
|
66
|
+
crashReason = null;
|
|
67
|
+
constructor(dir, jsondata) {
|
|
68
|
+
super(jsondata.id);
|
|
69
|
+
this.dir = dir;
|
|
70
|
+
this.data = jsondata;
|
|
71
|
+
this.name = jsondata.name;
|
|
72
|
+
this.priority = jsondata.priority;
|
|
73
|
+
this.version = base_1.ODVersion.fromString("plugin", jsondata.version);
|
|
74
|
+
this.details = jsondata.details;
|
|
75
|
+
this.enabled = jsondata.enabled;
|
|
76
|
+
this.executed = false;
|
|
77
|
+
this.crashed = false;
|
|
78
|
+
}
|
|
79
|
+
/**Get the startfile location relative to the `./plugins/` directory. (`./dist/plugins/`) when compiled) */
|
|
80
|
+
getStartFile() {
|
|
81
|
+
const newFile = this.data.startFile.replace(/\.ts$/, ".js");
|
|
82
|
+
return path_1.default.join(this.dir, newFile);
|
|
83
|
+
}
|
|
84
|
+
/**Execute this plugin. Returns `false` on crash. */
|
|
85
|
+
async execute(debug, force) {
|
|
86
|
+
if ((this.enabled && !this.crashed) || force) {
|
|
87
|
+
try {
|
|
88
|
+
//import relative plugin directory path (works on windows & unix based systems)
|
|
89
|
+
const pluginPath = path_1.default.join("../../../../plugins/", this.getStartFile()).replaceAll("\\", "/");
|
|
90
|
+
await import(pluginPath);
|
|
91
|
+
debug.console.log("Plugin \"" + this.id.value + "\" loaded successfully!", "plugin");
|
|
92
|
+
this.executed = true;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
this.crashed = true;
|
|
97
|
+
this.crashReason = "executed";
|
|
98
|
+
debug.console.log(error.message + ", canceling plugin execution...", "plugin", [
|
|
99
|
+
{ key: "path", value: "./plugins/" + this.dir }
|
|
100
|
+
]);
|
|
101
|
+
debug.console.log("You can see more about this error in the ./debug.txt file!", "info");
|
|
102
|
+
debug.console.debugfile.writeText(error.stack);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
/**Check if a npm dependency exists. */
|
|
110
|
+
#checkDependency(id) {
|
|
111
|
+
try {
|
|
112
|
+
require.resolve(id);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**Get a list of all missing npm dependencies that are required for this plugin. */
|
|
120
|
+
dependenciesInstalled() {
|
|
121
|
+
const missing = [];
|
|
122
|
+
this.data.npmDependencies.forEach((d) => {
|
|
123
|
+
if (!this.#checkDependency(d)) {
|
|
124
|
+
missing.push(d);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return missing;
|
|
128
|
+
}
|
|
129
|
+
/**Get a list of all missing plugins that are required for this plugin. */
|
|
130
|
+
pluginsInstalled(manager) {
|
|
131
|
+
const missing = [];
|
|
132
|
+
this.data.requiredPlugins.forEach((p) => {
|
|
133
|
+
const plugin = manager.get(p);
|
|
134
|
+
if (!plugin || !plugin.enabled) {
|
|
135
|
+
missing.push(p);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return missing;
|
|
139
|
+
}
|
|
140
|
+
/**Get a list of all enabled incompatible plugins that interfere with this plugin. */
|
|
141
|
+
pluginsIncompatible(manager) {
|
|
142
|
+
const incompatible = [];
|
|
143
|
+
this.data.incompatiblePlugins.forEach((p) => {
|
|
144
|
+
const plugin = manager.get(p);
|
|
145
|
+
if (plugin && plugin.enabled) {
|
|
146
|
+
incompatible.push(p);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return incompatible;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.ODPlugin = ODPlugin;
|
|
153
|
+
/**## ODPluginClassManager `class`
|
|
154
|
+
* This is an Open Discord plugin class manager.
|
|
155
|
+
*
|
|
156
|
+
* It manages all managers registered by plugins!
|
|
157
|
+
* Plugins are able to register their own managers, handlers, functions, classes, ... here.
|
|
158
|
+
* By doing this, other plugins are also able to make use of it.
|
|
159
|
+
* This can be useful for plugins that want to extend other plugins.
|
|
160
|
+
*
|
|
161
|
+
* Use `isPluginLoaded()` to check if a plugin has been loaded before trying to access the manager.
|
|
162
|
+
*/
|
|
163
|
+
class ODPluginClassManager extends base_1.ODManager {
|
|
164
|
+
constructor(debug) {
|
|
165
|
+
super(debug, "plugin class");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.ODPluginClassManager = ODPluginClassManager;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ODManager, ODManagerData, ODValidId } from "./base";
|
|
2
|
+
import { ODMessageBuildResult, ODMessageBuildSentResult } from "./builder";
|
|
3
|
+
import { ODDebugger } from "./console";
|
|
4
|
+
import * as discord from "discord.js";
|
|
5
|
+
/**## ODPostManager `class`
|
|
6
|
+
* This is an Open Discord post manager.
|
|
7
|
+
*
|
|
8
|
+
* It manages `ODPosts`'s for you.
|
|
9
|
+
*
|
|
10
|
+
* You can use this to get the logs channel of the bot (or some other static channel/category).
|
|
11
|
+
*/
|
|
12
|
+
export declare class ODPostManager extends ODManager<ODPost<discord.GuildBasedChannel>> {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(debug: ODDebugger);
|
|
15
|
+
add(data: ODPost<discord.GuildBasedChannel>, overwrite?: boolean): boolean;
|
|
16
|
+
/**Initialize the post manager & all posts. */
|
|
17
|
+
init(guild: discord.Guild): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**## ODPost `class`
|
|
20
|
+
* This is an Open Discord post class.
|
|
21
|
+
*
|
|
22
|
+
* A post is just a shortcut to a static discord channel or category.
|
|
23
|
+
* This can be used to get a specific channel over and over again!
|
|
24
|
+
*
|
|
25
|
+
* This class also contains utilities for sending messages via the Open Discord builders.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ODPost<ChannelType extends discord.GuildBasedChannel> extends ODManagerData {
|
|
28
|
+
#private;
|
|
29
|
+
/**Is this post already initialized? */
|
|
30
|
+
ready: boolean;
|
|
31
|
+
/**The discord.js channel */
|
|
32
|
+
channel: ChannelType | null;
|
|
33
|
+
/**The discord channel id */
|
|
34
|
+
channelId: string;
|
|
35
|
+
constructor(id: ODValidId, channelId: string);
|
|
36
|
+
/**Use a specific guild in this class for fetching the channel*/
|
|
37
|
+
useGuild(guild: discord.Guild | null): void;
|
|
38
|
+
/**Change the channel id to another channel! */
|
|
39
|
+
setChannelId(id: string): void;
|
|
40
|
+
/**Initialize the discord.js channel of this post. */
|
|
41
|
+
init(): Promise<null | undefined>;
|
|
42
|
+
/**Send a message to this channel using the Open Discord builder system */
|
|
43
|
+
send(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<true>>;
|
|
44
|
+
}
|