Fix types in SlashCommands which assumed something was a promise but it wasn't

pull/21833/head
Michael Telatynski 2021-06-17 11:37:06 +01:00
parent 782adbc41e
commit cce4ccb157
1 changed files with 13 additions and 9 deletions

View File

@ -150,6 +150,10 @@ function success(promise?: Promise<any>) {
return {promise}; return {promise};
} }
function successSync(value: any) {
return success(Promise.resolve(value));
}
/* Disable the "unexpected this" error for these commands - all of the run /* Disable the "unexpected this" error for these commands - all of the run
* functions are called with `this` bound to the Command instance. * functions are called with `this` bound to the Command instance.
*/ */
@ -160,7 +164,7 @@ export const Commands = [
args: '<message>', args: '<message>',
description: _td('Sends the given message as a spoiler'), description: _td('Sends the given message as a spoiler'),
runFn: function(roomId, message) { runFn: function(roomId, message) {
return success(ContentHelpers.makeHtmlMessage( return successSync(ContentHelpers.makeHtmlMessage(
message, message,
`<span data-mx-spoiler>${message}</span>`, `<span data-mx-spoiler>${message}</span>`,
)); ));
@ -176,7 +180,7 @@ export const Commands = [
if (args) { if (args) {
message = message + ' ' + args; message = message + ' ' + args;
} }
return success(ContentHelpers.makeTextMessage(message)); return successSync(ContentHelpers.makeTextMessage(message));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -189,7 +193,7 @@ export const Commands = [
if (args) { if (args) {
message = message + ' ' + args; message = message + ' ' + args;
} }
return success(ContentHelpers.makeTextMessage(message)); return successSync(ContentHelpers.makeTextMessage(message));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -202,7 +206,7 @@ export const Commands = [
if (args) { if (args) {
message = message + ' ' + args; message = message + ' ' + args;
} }
return success(ContentHelpers.makeTextMessage(message)); return successSync(ContentHelpers.makeTextMessage(message));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -215,7 +219,7 @@ export const Commands = [
if (args) { if (args) {
message = message + ' ' + args; message = message + ' ' + args;
} }
return success(ContentHelpers.makeTextMessage(message)); return successSync(ContentHelpers.makeTextMessage(message));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -224,7 +228,7 @@ export const Commands = [
args: '<message>', args: '<message>',
description: _td('Sends a message as plain text, without interpreting it as markdown'), description: _td('Sends a message as plain text, without interpreting it as markdown'),
runFn: function(roomId, messages) { runFn: function(roomId, messages) {
return success(ContentHelpers.makeTextMessage(messages)); return successSync(ContentHelpers.makeTextMessage(messages));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -233,7 +237,7 @@ export const Commands = [
args: '<message>', args: '<message>',
description: _td('Sends a message as html, without interpreting it as markdown'), description: _td('Sends a message as html, without interpreting it as markdown'),
runFn: function(roomId, messages) { runFn: function(roomId, messages) {
return success(ContentHelpers.makeHtmlMessage(messages, messages)); return successSync(ContentHelpers.makeHtmlMessage(messages, messages));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -978,7 +982,7 @@ export const Commands = [
args: '<message>', args: '<message>',
runFn: function(roomId, args) { runFn: function(roomId, args) {
if (!args) return reject(this.getUserId()); if (!args) return reject(this.getUserId());
return success(ContentHelpers.makeHtmlMessage(args, textToHtmlRainbow(args))); return successSync(ContentHelpers.makeHtmlMessage(args, textToHtmlRainbow(args)));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),
@ -988,7 +992,7 @@ export const Commands = [
args: '<message>', args: '<message>',
runFn: function(roomId, args) { runFn: function(roomId, args) {
if (!args) return reject(this.getUserId()); if (!args) return reject(this.getUserId());
return success(ContentHelpers.makeHtmlEmote(args, textToHtmlRainbow(args))); return successSync(ContentHelpers.makeHtmlEmote(args, textToHtmlRainbow(args)));
}, },
category: CommandCategories.messages, category: CommandCategories.messages,
}), }),