diff --git a/simplecommands/plugin.json b/simplecommands/plugin.json index 77a53b4..2ac76b3 100644 --- a/simplecommands/plugin.json +++ b/simplecommands/plugin.json @@ -3,7 +3,7 @@ "name": "simplecommands", "description": "Official Simplistic Commands API for Squeebot 3", "tags": ["handler", "commands", "api"], - "version": "1.0.0", + "version": "1.1.0", "dependencies": ["control?", "permissions?"], "npmDependencies": [] } diff --git a/simplecommands/plugin.ts b/simplecommands/plugin.ts index d6c28d1..d426b53 100644 --- a/simplecommands/plugin.ts +++ b/simplecommands/plugin.ts @@ -6,7 +6,7 @@ import { DependencyUnload } from '@squeebot/core/lib/plugin'; -import { EMessageType, IMessage } from '@squeebot/core/lib/types'; +import { EMessageType, IMessage, MessageResolver } from '@squeebot/core/lib/types'; import { fullIDMatcher } from '@squeebot/core/lib/common'; @@ -28,7 +28,12 @@ interface CommandSpec { hidden?: boolean; permissions?: string[]; tempargv?: any[]; - execute(msg: IMessage, command: CommandSpec, prefix: string, ...args: any[]): Promise; + execute( + msg: IMessage, + msr: MessageResolver, + command: CommandSpec, + prefix: string, + ...args: any[]): Promise; } interface RateLimit { @@ -156,7 +161,11 @@ class SqueebotCommandsAPIPlugin extends Plugin { return permitted; } - public async handlePrefix(msg: IMessage, prefix: string, plugins: string[]): Promise { + public async handlePrefix( + msg: IMessage, + prefix: string, + plugins: string[], + msr: MessageResolver): Promise { const text = msg.text; const separate = text.split(' '); if (separate[0].indexOf(prefix) === 0) { @@ -220,7 +229,7 @@ class SqueebotCommandsAPIPlugin extends Plugin { argv.unshift(plugins); } - const success = await spec.execute(msg, spec, prefix, ...argv); + const success = await spec.execute(msg, msr, spec, prefix, ...argv); if (success) { break; } @@ -229,7 +238,11 @@ class SqueebotCommandsAPIPlugin extends Plugin { // Done } - public async handleKeywords(msg: IMessage, keyword: string, plugins: string[]): Promise { + public async handleKeywords( + msg: IMessage, + keyword: string, + plugins: string[], + msr: MessageResolver): Promise { const text = msg.text.toLowerCase(); // Only pass command specs which have `match` and match rooms @@ -292,7 +305,7 @@ class SqueebotCommandsAPIPlugin extends Plugin { // Start executing for (const spec of permitted) { - const success = await spec.execute(msg, spec, keyword, + const success = await spec.execute(msg, msr, spec, keyword, ...(spec.tempargv ? spec.tempargv : [])); if (success) { break; @@ -303,7 +316,7 @@ class SqueebotCommandsAPIPlugin extends Plugin { } @EventListener('message') - public digest(msg: IMessage, chan: IChannel): void { + public digest(msg: IMessage, chan: IChannel, msr: MessageResolver): void { if (msg.type !== EMessageType.message) { return; } @@ -321,7 +334,7 @@ class SqueebotCommandsAPIPlugin extends Plugin { if (keywords && keywords.length) { for (const kw of keywords) { if (text.toLowerCase().match(kw) != null) { - this.handleKeywords(msg, kw, allowedPlugins).catch(e => + this.handleKeywords(msg, kw, allowedPlugins, msr).catch(e => logger.error('[%s] Command handler threw an error:', this.name, e.stack)); return; } @@ -355,7 +368,7 @@ class SqueebotCommandsAPIPlugin extends Plugin { return; } - this.handlePrefix(msg, prefix, allowedPlugins).catch(e => + this.handlePrefix(msg, prefix, allowedPlugins, msr).catch(e => logger.error('[%s] Command handler threw an error:', this.name, e.stack)); } @@ -557,7 +570,12 @@ class SqueebotCommandsAPIPlugin extends Plugin { aliases: ['commands'], usage: '[]', description: 'Show command usage or list all available commands', - execute: async (msg: IMessage, spec: CommandSpec, prefix: string, ...args: any[]): Promise => { + execute: async ( + msg: IMessage, + msr: MessageResolver, + spec: CommandSpec, + prefix: string, + ...args: any[]): Promise => { this.helpCommand(msg, prefix, args); return true; } @@ -569,7 +587,12 @@ class SqueebotCommandsAPIPlugin extends Plugin { aliases: ['alias'], usage: '', description: 'Show the list of aliases for command', - execute: async (msg: IMessage, spec: CommandSpec, prefix: string, ...args: any[]): Promise => { + execute: async ( + msg: IMessage, + msr: MessageResolver, + spec: CommandSpec, + prefix: string, + ...args: any[]): Promise => { this.aliasesCommand(msg, prefix, args); return true; } diff --git a/squeebot.repo.json b/squeebot.repo.json index 03ede66..e75f897 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -11,7 +11,7 @@ }, { "name": "simplecommands", - "version": "1.0.0" + "version": "1.1.0" } ], "typescript": true