forked from Galactic/galactic-bot
misc fixes n cleanup
This commit is contained in:
parent
07dc68ed1c
commit
e4e012bd72
7
index.js
7
index.js
@ -7,6 +7,7 @@ const { version } = require('./package.json');
|
||||
new BaseClient(options, version)
|
||||
.build();
|
||||
|
||||
// process.on("unhandledRejection", (error) => {
|
||||
// console.error("[index.js] Unhandled promise rejection:", error); //eslint-disable-line no-console
|
||||
// });
|
||||
process.on("unhandledRejection", (error) => {
|
||||
console.error("[index.js] Unhandled promise rejection:", error); //eslint-disable-line no-console
|
||||
throw error;
|
||||
});
|
@ -1,5 +1,6 @@
|
||||
const { Client, Collection } = require('discord.js');
|
||||
const chalk = require('chalk');
|
||||
const { inspect } = require('util');
|
||||
|
||||
const { Intercom, EventHooker, LocaleLoader, Registry, Dispatcher, Resolver, ModerationManager, RateLimiter } = require('./client/');
|
||||
const { Observer, Command, Setting, Inhibitor } = require('./interfaces/');
|
||||
@ -67,9 +68,9 @@ class DiscordClient extends Client {
|
||||
// this.logger.error(`Uncaught exception:\n${err.stack || err}`);
|
||||
// });
|
||||
|
||||
// process.on('unhandledRejection', (err) => {
|
||||
// this.logger.error(`Unhandled rejection:\n${err.stack || err}`);
|
||||
// });
|
||||
process.on('unhandledRejection', (err, reason) => {
|
||||
this.logger.error(`Unhandled rejection:\n${err.stack || err}\n${inspect(reason)}`);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,11 +14,19 @@ class InvokerWrapper {
|
||||
this.client = client;
|
||||
this.target = target; // The wrapped wrapper
|
||||
|
||||
this.type = target instanceof MessageWrapper ? 'message' : 'interaction';
|
||||
this.command = command;
|
||||
this._type = target instanceof MessageWrapper ? 'message' : 'interaction';
|
||||
this._command = command;
|
||||
|
||||
}
|
||||
|
||||
get command() {
|
||||
return this._command;
|
||||
}
|
||||
|
||||
get type() {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this.target.id;
|
||||
}
|
||||
|
@ -43,7 +43,13 @@ class CommandHandler extends Observer {
|
||||
|
||||
const invoker = new InvokerWrapper(this.client, messageWrapper, command);
|
||||
const inhibitors = await this._handleInhibitors(invoker);
|
||||
if (inhibitors.length) return this._generateError(invoker, { type: 'inhibitor', ...inhibitors[0] });
|
||||
const silent = inhibitors.filter((i) => i.inhibitor.silent);
|
||||
const nonsilent = inhibitors.filter((i) => !i.inhibitor.silent);
|
||||
if (silent.length && silent.some((i) => i.inhibitor.id === 'channelIgnore')
|
||||
|| nonsilent.length && nonsilent.some((i) => i.args.missing.includes('SEND_MESSAGES'))
|
||||
|| silent.length && !nonsilent.length) return;
|
||||
|
||||
if (inhibitors.length) return this._generateError(invoker, { type: 'inhibitor', ...inhibitors[0] }).catch(this.logger.error);
|
||||
|
||||
const response = await this._parseMessage(invoker, parameters);
|
||||
// There was an error if _parseResponse return value is truthy, i.e. an error message was sent
|
||||
@ -116,7 +122,7 @@ class CommandHandler extends Observer {
|
||||
const errors = (await Promise.all(promises)).filter((result) => result.error);
|
||||
if (!errors.length) return [];
|
||||
|
||||
return errors.sort((a, b) => a.inhibitor.priority - b.inhibitor.priority);
|
||||
return errors.sort((a, b) => b.inhibitor.priority - a.inhibitor.priority);
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Command extends Component {
|
||||
|
||||
this.slash = Boolean(options.slash);
|
||||
|
||||
this.clientPermissions = options.clientPermissions || [];
|
||||
this.clientPermissions = [...new Set(['SEND_MESSAGES', ...options.clientPermissions || []])];
|
||||
this.memberPermissions = options.memberPermissions || [];
|
||||
|
||||
this._invokes = {
|
||||
|
Loading…
Reference in New Issue
Block a user