spacecommands 1.0.0
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 +21 -0
- package/README.md +519 -0
- package/dist/Command.js +384 -0
- package/dist/CommandHandler.js +339 -0
- package/dist/FeatureHandler.js +89 -0
- package/dist/SlashCommands.js +220 -0
- package/dist/command-checks/channel-specific.js +30 -0
- package/dist/command-checks/guild-only-check.js +24 -0
- package/dist/command-checks/has-entitlement.js +52 -0
- package/dist/command-checks/has-permissions.js +39 -0
- package/dist/command-checks/has-roles.js +69 -0
- package/dist/command-checks/has-valid-arguments.js +54 -0
- package/dist/command-checks/in-cooldown.js +42 -0
- package/dist/command-checks/is-enabled.js +31 -0
- package/dist/command-checks/is-not-test-only.js +8 -0
- package/dist/command-checks/owner-only-check.js +22 -0
- package/dist/commands/channelonly.js +88 -0
- package/dist/commands/command.js +87 -0
- package/dist/commands/help/!ReactionListener.js +217 -0
- package/dist/commands/help/!get-first-embed.js +57 -0
- package/dist/commands/help/help.js +97 -0
- package/dist/commands/language.js +52 -0
- package/dist/commands/prefix.js +42 -0
- package/dist/commands/requiredrole.js +61 -0
- package/dist/commands/slash.js +102 -0
- package/dist/enums/CommandErrors.js +12 -0
- package/dist/enums/Events.js +9 -0
- package/dist/features/message-upsert.js +15 -0
- package/dist/get-all-files.js +25 -0
- package/dist/handlers/AutoModHandler.js +316 -0
- package/dist/handlers/ComponentHandler.js +110 -0
- package/dist/handlers/ContextMenuHandler.js +113 -0
- package/dist/handlers/EntitlementHandler.js +193 -0
- package/dist/handlers/ModalHandler.js +71 -0
- package/dist/handlers/PollHandler.js +230 -0
- package/dist/index.js +339 -0
- package/dist/message-handler.js +118 -0
- package/dist/models/channel-commands.js +49 -0
- package/dist/models/cooldown.js +51 -0
- package/dist/models/disabled-commands.js +45 -0
- package/dist/models/languages.js +46 -0
- package/dist/models/prefixes.js +46 -0
- package/dist/models/required-roles.js +49 -0
- package/dist/mongo.js +25 -0
- package/dist/permissions.js +39 -0
- package/dist/utils/ComponentBuilder.js +144 -0
- package/dist/utils/InteractionCollector.js +80 -0
- package/messages.json +391 -0
- package/package.json +72 -0
- package/typings.d.ts +276 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const events_1 = require("events");
|
|
40
|
+
const FeatureHandler_1 = __importDefault(require("./FeatureHandler"));
|
|
41
|
+
const mongo_1 = __importStar(require("./mongo"));
|
|
42
|
+
const prefixes_1 = __importDefault(require("./models/prefixes"));
|
|
43
|
+
const message_handler_1 = __importDefault(require("./message-handler"));
|
|
44
|
+
const SlashCommands_1 = __importDefault(require("./SlashCommands"));
|
|
45
|
+
const ComponentHandler_1 = __importDefault(require("./handlers/ComponentHandler"));
|
|
46
|
+
const ModalHandler_1 = __importDefault(require("./handlers/ModalHandler"));
|
|
47
|
+
const ContextMenuHandler_1 = __importDefault(require("./handlers/ContextMenuHandler"));
|
|
48
|
+
const EntitlementHandler_1 = __importDefault(require("./handlers/EntitlementHandler"));
|
|
49
|
+
const PollHandler_1 = __importDefault(require("./handlers/PollHandler"));
|
|
50
|
+
const AutoModHandler_1 = __importDefault(require("./handlers/AutoModHandler"));
|
|
51
|
+
const Events_1 = __importDefault(require("./enums/Events"));
|
|
52
|
+
const CommandHandler_1 = __importDefault(require("./CommandHandler"));
|
|
53
|
+
class SpaceCommands extends events_1.EventEmitter {
|
|
54
|
+
_client;
|
|
55
|
+
_defaultPrefix = '!';
|
|
56
|
+
_commandsDir = 'commands';
|
|
57
|
+
_featuresDir = '';
|
|
58
|
+
_mongoConnection = null;
|
|
59
|
+
_displayName = '';
|
|
60
|
+
_prefixes = {};
|
|
61
|
+
_categories = new Map(); // <Category Name, Emoji Icon>
|
|
62
|
+
_hiddenCategories = [];
|
|
63
|
+
_color = null;
|
|
64
|
+
_commandHandler = null;
|
|
65
|
+
_featureHandler = null;
|
|
66
|
+
_tagPeople = true;
|
|
67
|
+
_showWarns = true;
|
|
68
|
+
_delErrMsgCooldown = -1;
|
|
69
|
+
_ignoreBots = true;
|
|
70
|
+
_botOwner = [];
|
|
71
|
+
_testServers = [];
|
|
72
|
+
_defaultLanguage = 'english';
|
|
73
|
+
_ephemeral = true;
|
|
74
|
+
_debug = false;
|
|
75
|
+
_messageHandler = null;
|
|
76
|
+
_slashCommand = null;
|
|
77
|
+
_componentHandler = null;
|
|
78
|
+
_modalHandler = null;
|
|
79
|
+
_contextMenuHandler = null;
|
|
80
|
+
_entitlementHandler = null;
|
|
81
|
+
_pollHandler = null;
|
|
82
|
+
_autoModHandler = null;
|
|
83
|
+
constructor(client, options) {
|
|
84
|
+
super();
|
|
85
|
+
this._client = client;
|
|
86
|
+
this.setUp(client, options);
|
|
87
|
+
}
|
|
88
|
+
async setUp(client, options) {
|
|
89
|
+
if (!client) {
|
|
90
|
+
throw new Error('No Discord JS Client provided as first argument!');
|
|
91
|
+
}
|
|
92
|
+
let { commandsDir = '', commandDir = '', featuresDir = '', featureDir = '', componentsDir, modalsDir, contextMenusDir, messagesPath, mongoUri, showWarns = true, delErrMsgCooldown = -1, defaultLanguage = 'english', ignoreBots = true, dbOptions, testServers, botOwners, disabledDefaultCommands = [], typeScript = false, ephemeral = true, debug = false, } = options || {};
|
|
93
|
+
if (mongoUri) {
|
|
94
|
+
await (0, mongo_1.default)(mongoUri, this, dbOptions);
|
|
95
|
+
this._mongoConnection = (0, mongo_1.getMongoConnection)();
|
|
96
|
+
const results = await prefixes_1.default.find({});
|
|
97
|
+
for (const result of results) {
|
|
98
|
+
const { _id, prefix } = result;
|
|
99
|
+
this._prefixes[_id] = prefix;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (showWarns) {
|
|
104
|
+
console.warn('SpaceCommands > No MongoDB connection URI provided. Some features might not work!');
|
|
105
|
+
}
|
|
106
|
+
this.emit(Events_1.default.DATABASE_CONNECTED, null, '');
|
|
107
|
+
}
|
|
108
|
+
this._commandsDir = commandsDir || commandDir || this._commandsDir;
|
|
109
|
+
this._featuresDir = featuresDir || featureDir || this._featuresDir;
|
|
110
|
+
this._ephemeral = ephemeral;
|
|
111
|
+
this._debug = debug;
|
|
112
|
+
if (this._commandsDir &&
|
|
113
|
+
!(this._commandsDir.includes('/') || this._commandsDir.includes('\\'))) {
|
|
114
|
+
throw new Error("SpaceCommands > The 'commands' directory must be an absolute path. This can be done by using the 'path' module.");
|
|
115
|
+
}
|
|
116
|
+
if (this._featuresDir &&
|
|
117
|
+
!(this._featuresDir.includes('/') || this._featuresDir.includes('\\'))) {
|
|
118
|
+
throw new Error("SpaceCommands > The 'features' directory must be an absolute path. This can be done by using the 'path' module.");
|
|
119
|
+
}
|
|
120
|
+
if (testServers) {
|
|
121
|
+
if (typeof testServers === 'string') {
|
|
122
|
+
testServers = [testServers];
|
|
123
|
+
}
|
|
124
|
+
this._testServers = testServers;
|
|
125
|
+
}
|
|
126
|
+
if (botOwners) {
|
|
127
|
+
if (typeof botOwners === 'string') {
|
|
128
|
+
botOwners = [botOwners];
|
|
129
|
+
}
|
|
130
|
+
this._botOwner = botOwners;
|
|
131
|
+
}
|
|
132
|
+
this._showWarns = showWarns;
|
|
133
|
+
this._delErrMsgCooldown = delErrMsgCooldown;
|
|
134
|
+
this._defaultLanguage = defaultLanguage.toLowerCase();
|
|
135
|
+
this._ignoreBots = ignoreBots;
|
|
136
|
+
if (typeof disabledDefaultCommands === 'string') {
|
|
137
|
+
disabledDefaultCommands = [disabledDefaultCommands];
|
|
138
|
+
}
|
|
139
|
+
this._commandHandler = new CommandHandler_1.default(this, client, this._commandsDir, disabledDefaultCommands, typeScript);
|
|
140
|
+
this._slashCommand = new SlashCommands_1.default(this, true, typeScript);
|
|
141
|
+
this._messageHandler = new message_handler_1.default(this, messagesPath || '');
|
|
142
|
+
this.setCategorySettings([
|
|
143
|
+
{
|
|
144
|
+
name: 'Configuration',
|
|
145
|
+
emoji: '⚙',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'Help',
|
|
149
|
+
emoji: '❓',
|
|
150
|
+
},
|
|
151
|
+
]);
|
|
152
|
+
this._featureHandler = new FeatureHandler_1.default(client, this, this._featuresDir, typeScript);
|
|
153
|
+
this._componentHandler = new ComponentHandler_1.default(this, componentsDir, typeScript);
|
|
154
|
+
this._modalHandler = new ModalHandler_1.default(this, modalsDir, typeScript);
|
|
155
|
+
this._contextMenuHandler = new ContextMenuHandler_1.default(this, contextMenusDir, typeScript);
|
|
156
|
+
this._entitlementHandler = new EntitlementHandler_1.default(this);
|
|
157
|
+
this._pollHandler = new PollHandler_1.default(this);
|
|
158
|
+
this._autoModHandler = new AutoModHandler_1.default(this);
|
|
159
|
+
console.log('SpaceCommands > Your bot is now running.');
|
|
160
|
+
}
|
|
161
|
+
setMongoPath(mongoPath) {
|
|
162
|
+
console.warn('SpaceCommands > .setMongoPath() no longer works as expected. Please pass in your mongo URI as a "mongoUri" property using the options object.');
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
get client() {
|
|
166
|
+
return this._client;
|
|
167
|
+
}
|
|
168
|
+
get displayName() {
|
|
169
|
+
return this._displayName;
|
|
170
|
+
}
|
|
171
|
+
setDisplayName(displayName) {
|
|
172
|
+
this._displayName = displayName;
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
get prefixes() {
|
|
176
|
+
return this._prefixes;
|
|
177
|
+
}
|
|
178
|
+
get defaultPrefix() {
|
|
179
|
+
return this._defaultPrefix;
|
|
180
|
+
}
|
|
181
|
+
setDefaultPrefix(defaultPrefix) {
|
|
182
|
+
this._defaultPrefix = defaultPrefix;
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
getPrefix(guild) {
|
|
186
|
+
return this._prefixes[guild ? guild.id : ''] || this._defaultPrefix;
|
|
187
|
+
}
|
|
188
|
+
setPrefix(guild, prefix) {
|
|
189
|
+
if (guild) {
|
|
190
|
+
this._prefixes[guild.id] = prefix;
|
|
191
|
+
}
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
get categories() {
|
|
195
|
+
return this._categories;
|
|
196
|
+
}
|
|
197
|
+
get hiddenCategories() {
|
|
198
|
+
return this._hiddenCategories;
|
|
199
|
+
}
|
|
200
|
+
get color() {
|
|
201
|
+
return this._color;
|
|
202
|
+
}
|
|
203
|
+
setColor(color) {
|
|
204
|
+
this._color = color;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
getEmoji(category) {
|
|
208
|
+
const emoji = this._categories.get(category) || '';
|
|
209
|
+
if (typeof emoji === 'object') {
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
return `<:${emoji.name}:${emoji.id}>`;
|
|
212
|
+
}
|
|
213
|
+
return emoji;
|
|
214
|
+
}
|
|
215
|
+
getCategory(emoji) {
|
|
216
|
+
let result = '';
|
|
217
|
+
this._categories.forEach((value, key) => {
|
|
218
|
+
// == is intended here
|
|
219
|
+
if (emoji == value) {
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
result = key;
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
setCategorySettings(category) {
|
|
228
|
+
for (let { emoji, name, hidden, customEmoji } of category) {
|
|
229
|
+
if (emoji.startsWith('<:') && emoji.endsWith('>')) {
|
|
230
|
+
customEmoji = true;
|
|
231
|
+
emoji = emoji.split(':')[2];
|
|
232
|
+
emoji = emoji.substring(0, emoji.length - 1);
|
|
233
|
+
}
|
|
234
|
+
let targetEmoji = emoji;
|
|
235
|
+
if (customEmoji) {
|
|
236
|
+
targetEmoji = this._client.emojis.cache.get(emoji);
|
|
237
|
+
}
|
|
238
|
+
if (this.isEmojiUsed(targetEmoji)) {
|
|
239
|
+
console.warn(`SpaceCommands > The emoji "${targetEmoji}" for category "${name}" is already used.`);
|
|
240
|
+
}
|
|
241
|
+
this._categories.set(name, targetEmoji || this.categories.get(name) || '');
|
|
242
|
+
if (hidden) {
|
|
243
|
+
this._hiddenCategories.push(name);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
isEmojiUsed(emoji) {
|
|
249
|
+
if (!emoji) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
let isUsed = false;
|
|
253
|
+
this._categories.forEach((value) => {
|
|
254
|
+
if (value === emoji) {
|
|
255
|
+
isUsed = true;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return isUsed;
|
|
259
|
+
}
|
|
260
|
+
get commandHandler() {
|
|
261
|
+
return this._commandHandler;
|
|
262
|
+
}
|
|
263
|
+
get mongoConnection() {
|
|
264
|
+
return this._mongoConnection;
|
|
265
|
+
}
|
|
266
|
+
isDBConnected() {
|
|
267
|
+
const connection = this.mongoConnection;
|
|
268
|
+
return !!(connection && connection.readyState === 1);
|
|
269
|
+
}
|
|
270
|
+
setTagPeople(tagPeople) {
|
|
271
|
+
this._tagPeople = tagPeople;
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
get tagPeople() {
|
|
275
|
+
return this._tagPeople;
|
|
276
|
+
}
|
|
277
|
+
get showWarns() {
|
|
278
|
+
return this._showWarns;
|
|
279
|
+
}
|
|
280
|
+
get delErrMsgCooldown() {
|
|
281
|
+
return this._delErrMsgCooldown;
|
|
282
|
+
}
|
|
283
|
+
get ignoreBots() {
|
|
284
|
+
return this._ignoreBots;
|
|
285
|
+
}
|
|
286
|
+
get botOwner() {
|
|
287
|
+
return this._botOwner;
|
|
288
|
+
}
|
|
289
|
+
setBotOwner(botOwner) {
|
|
290
|
+
console.log('SpaceCommands > setBotOwner() is deprecated. Please specify your bot owners in the object constructor instead.');
|
|
291
|
+
if (typeof botOwner === 'string') {
|
|
292
|
+
botOwner = [botOwner];
|
|
293
|
+
}
|
|
294
|
+
this._botOwner = botOwner;
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
get testServers() {
|
|
298
|
+
return this._testServers;
|
|
299
|
+
}
|
|
300
|
+
get defaultLanguage() {
|
|
301
|
+
return this._defaultLanguage;
|
|
302
|
+
}
|
|
303
|
+
setDefaultLanguage(defaultLanguage) {
|
|
304
|
+
this._defaultLanguage = defaultLanguage;
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
get ephemeral() {
|
|
308
|
+
return this._ephemeral;
|
|
309
|
+
}
|
|
310
|
+
get debug() {
|
|
311
|
+
return this._debug;
|
|
312
|
+
}
|
|
313
|
+
get messageHandler() {
|
|
314
|
+
return this._messageHandler;
|
|
315
|
+
}
|
|
316
|
+
get slashCommands() {
|
|
317
|
+
return this._slashCommand;
|
|
318
|
+
}
|
|
319
|
+
get componentHandler() {
|
|
320
|
+
return this._componentHandler;
|
|
321
|
+
}
|
|
322
|
+
get modalHandler() {
|
|
323
|
+
return this._modalHandler;
|
|
324
|
+
}
|
|
325
|
+
get contextMenuHandler() {
|
|
326
|
+
return this._contextMenuHandler;
|
|
327
|
+
}
|
|
328
|
+
get entitlementHandler() {
|
|
329
|
+
return this._entitlementHandler;
|
|
330
|
+
}
|
|
331
|
+
get pollHandler() {
|
|
332
|
+
return this._pollHandler;
|
|
333
|
+
}
|
|
334
|
+
get autoModHandler() {
|
|
335
|
+
return this._autoModHandler;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.default = SpaceCommands;
|
|
339
|
+
module.exports = SpaceCommands;
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const languages_1 = __importDefault(require("./models/languages"));
|
|
40
|
+
const defualtMessages = require('../messages.json');
|
|
41
|
+
class MessageHandler {
|
|
42
|
+
_instance;
|
|
43
|
+
_guildLanguages = new Map(); // <Guild ID, Language>
|
|
44
|
+
_languages = [];
|
|
45
|
+
_messages = {};
|
|
46
|
+
constructor(instance, messagePath) {
|
|
47
|
+
this._instance = instance;
|
|
48
|
+
(async () => {
|
|
49
|
+
this._messages = messagePath ? await Promise.resolve(`${messagePath}`).then(s => __importStar(require(s))) : defualtMessages;
|
|
50
|
+
for (const messageId of Object.keys(this._messages)) {
|
|
51
|
+
for (const language of Object.keys(this._messages[messageId])) {
|
|
52
|
+
this._languages.push(language.toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!this._languages.includes(instance.defaultLanguage)) {
|
|
56
|
+
throw new Error(`The current default language defined is not supported.`);
|
|
57
|
+
}
|
|
58
|
+
if (instance.isDBConnected()) {
|
|
59
|
+
const results = await languages_1.default.find();
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
for (const { _id: guildId, language } of results) {
|
|
62
|
+
this._guildLanguages.set(guildId, language);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
}
|
|
67
|
+
languages() {
|
|
68
|
+
return this._languages;
|
|
69
|
+
}
|
|
70
|
+
async setLanguage(guild, language) {
|
|
71
|
+
if (guild) {
|
|
72
|
+
this._guildLanguages.set(guild.id, language);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
getLanguage(guild) {
|
|
76
|
+
if (guild) {
|
|
77
|
+
const result = this._guildLanguages.get(guild.id);
|
|
78
|
+
if (result) {
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return this._instance.defaultLanguage;
|
|
83
|
+
}
|
|
84
|
+
get(guild, messageId, args = {}) {
|
|
85
|
+
const language = this.getLanguage(guild);
|
|
86
|
+
const translations = this._messages[messageId];
|
|
87
|
+
if (!translations) {
|
|
88
|
+
console.error(`SpaceCommands > Could not find the correct message to send for "${messageId}"`);
|
|
89
|
+
return 'Could not find the correct message to send. Please report this to the bot developer.';
|
|
90
|
+
}
|
|
91
|
+
let result = translations[language];
|
|
92
|
+
for (const key of Object.keys(args)) {
|
|
93
|
+
const expression = new RegExp(`{${key}}`, 'g');
|
|
94
|
+
result = result.replace(expression, args[key]);
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
getEmbed(guild, embedId, itemId, args = {}) {
|
|
99
|
+
const language = this.getLanguage(guild);
|
|
100
|
+
const items = this._messages[embedId];
|
|
101
|
+
if (!items) {
|
|
102
|
+
console.error(`SpaceCommands > Could not find the correct item to send for "${embedId}" -> "${itemId}"`);
|
|
103
|
+
return 'Could not find the correct message to send. Please report this to the bot developer.';
|
|
104
|
+
}
|
|
105
|
+
const translations = items[itemId];
|
|
106
|
+
if (!translations) {
|
|
107
|
+
console.error(`SpaceCommands > Could not find the correct message to send for "${embedId}"`);
|
|
108
|
+
return 'Could not find the correct message to send. Please report this to the bot developer.';
|
|
109
|
+
}
|
|
110
|
+
let result = translations[language];
|
|
111
|
+
for (const key of Object.keys(args)) {
|
|
112
|
+
const expression = new RegExp(`{${key}}`, 'g');
|
|
113
|
+
result = result.replace(expression, args[key]);
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.default = MessageHandler;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
const mongoose_1 = __importStar(require("mongoose"));
|
|
36
|
+
const reqString = {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
};
|
|
40
|
+
const schema = new mongoose_1.Schema({
|
|
41
|
+
guildId: reqString,
|
|
42
|
+
command: reqString,
|
|
43
|
+
channels: {
|
|
44
|
+
type: [String],
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const name = 'spacecommands-channel-commands';
|
|
49
|
+
module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
const mongoose_1 = __importStar(require("mongoose"));
|
|
36
|
+
const reqString = {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
};
|
|
40
|
+
const schema = new mongoose_1.Schema({
|
|
41
|
+
// Command-GuildID or Command-GuildID-UserID
|
|
42
|
+
_id: reqString,
|
|
43
|
+
name: reqString,
|
|
44
|
+
type: reqString,
|
|
45
|
+
cooldown: {
|
|
46
|
+
type: Number,
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const name = 'spacecommands-cooldowns';
|
|
51
|
+
module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const mongoose_1 = __importStar(require("mongoose"));
|
|
36
|
+
const reqString = {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
};
|
|
40
|
+
const schema = new mongoose_1.Schema({
|
|
41
|
+
guildId: reqString,
|
|
42
|
+
command: reqString,
|
|
43
|
+
});
|
|
44
|
+
const name = 'spacecommands-disabled-commands';
|
|
45
|
+
module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
const mongoose_1 = __importStar(require("mongoose"));
|
|
36
|
+
const reqString = {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true,
|
|
39
|
+
};
|
|
40
|
+
const schema = new mongoose_1.Schema({
|
|
41
|
+
// GuildID
|
|
42
|
+
_id: reqString,
|
|
43
|
+
language: reqString,
|
|
44
|
+
});
|
|
45
|
+
const name = 'spacecommands-languages';
|
|
46
|
+
module.exports = mongoose_1.default.models[name] || mongoose_1.default.model(name, schema, name);
|