Skip to content

Commit

Permalink
More async support in Command *Message functions (abalabahaha#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 authored Mar 24, 2021
1 parent 2f0c5d5 commit fb440b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare namespace Eris {
type CommandGenerator = CommandGeneratorFunction | MessageContent | MessageContent[] | CommandGeneratorFunction[];
type CommandGeneratorFunction = (msg: Message, args: string[]) => GeneratorFunctionReturn;
type GeneratorFunctionReturn = Promise<MessageContent> | Promise<void> | MessageContent | void;
type GenericCheckFunction<T> = (msg: Message) => T;
type GenericCheckFunction<T> = (msg: Message) => T | Promise<T>;
type ReactionButtonsFilterFunction = (msg: Message, emoji: Emoji, userID: string) => boolean;
type ReactionButtonsGeneratorFunction = (msg: Message, args: string[], userID: string) => GeneratorFunctionReturn;
type ReactionButtonsGenerator = ReactionButtonsGeneratorFunction | MessageContent | MessageContent[] | ReactionButtonsGeneratorFunction[];
Expand Down
16 changes: 8 additions & 8 deletions lib/command/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Command {

async executeCommand(msg, args) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, true));
const response = await this.hooks.postCheck(msg, args, true);
if(response) {
msg = response.msg || msg;
args = response.args || args;
Expand Down Expand Up @@ -315,7 +315,7 @@ class Command {
const shouldDelete = this.deleteCommand && msg.channel.guild && msg.channel.permissionsOf(msg._client.user.id).has("manageMessages");

if(this.hooks.preCommand) {
const response = await Promise.resolve(this.hooks.preCommand(msg, args));
const response = await this.hooks.preCommand(msg, args);
if(response) {
msg = response.msg || msg;
args = response.args || args;
Expand All @@ -325,14 +325,14 @@ class Command {
let reply;
if(this.cooldown !== 0 && !this.cooldownCheck(msg)) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, true));
const response = await this.hooks.postCheck(msg, args, true);
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
}
if(this.cooldownMessage && (!this.cooldownReturns || this.cooldownAmounts[msg.author.id] <= this.cooldownReturns)) {
reply = typeof this.cooldownMessage === "function" ? this.cooldownMessage(msg) : this.cooldownMessage;
reply = typeof this.cooldownMessage === "function" ? await this.cooldownMessage(msg) : this.cooldownMessage;
if(reply) {
msg.channel.createMessage(reply);
}
Expand All @@ -341,7 +341,7 @@ class Command {
}
if(!await this.permissionCheck(msg)) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, false));
const response = await this.hooks.postCheck(msg, args, false);
if(response) {
msg = response.msg || msg;
args = response.args || args;
Expand All @@ -351,7 +351,7 @@ class Command {
if(shouldDelete) {
msg.delete();
}
reply = typeof this.permissionMessage === "function" ? this.permissionMessage(msg) : this.permissionMessage;
reply = typeof this.permissionMessage === "function" ? await this.permissionMessage(msg) : this.permissionMessage;
if(reply) {
msg.channel.createMessage(reply);
}
Expand All @@ -363,13 +363,13 @@ class Command {
}
if(this.argsRequired) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, true));
const response = await this.hooks.postCheck(msg, args, true);
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
}
reply = typeof this.invalidUsageMessage === "function" ? this.invalidUsageMessage(msg) : this.invalidUsageMessage;
reply = typeof this.invalidUsageMessage === "function" ? await this.invalidUsageMessage(msg) : this.invalidUsageMessage;
if(reply) {
msg.channel.createMessage(reply.replace(/%prefix%/g, msg.prefix).replace(/%label%/g, this.fullLabel));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/command/CommandClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class CommandClient extends Client {
if(msg.command.errorMessage) {
try {
if(typeof msg.command.errorMessage === "function") {
const reply = msg.command.errorMessage(msg, err);
const reply = await msg.command.errorMessage(msg, err);
if(reply !== undefined) {
newMsg = await this.createMessage(msg.channel.id, reply);
}
Expand Down

0 comments on commit fb440b2

Please sign in to comment.