diff --git a/src/composer.ts b/src/composer.ts index 319cbed9..5cf1f0ca 100644 --- a/src/composer.ts +++ b/src/composer.ts @@ -108,7 +108,7 @@ function generateBotErrorMessage(error: unknown) { msg += `: ${error}`; break; case "string": - msg += `: ${String(error).substr(0, 50)}`; + msg += `: ${String(error).substring(0, 50)}`; break; default: msg += "!"; @@ -384,24 +384,22 @@ export class Composer implements MiddlewareObj { if (cmd.startsWith("/")) { throw new Error( `Do not include '/' when registering command handlers (use '${ - cmd.substr(1) + cmd.substring(1) }' not '${cmd}')`, ); } const set = cmd.indexOf("@") === -1 ? noAtCommands : atCommands; set.add(cmd); }); - return this.on(":entities:bot_command").filter( + return this.on("message:entities:bot_command").filter( (ctx): ctx is CommandContext => { - const msg = ctx.message ?? ctx.channelPost; - const txt = msg.text ?? msg.caption; - const entities = msg.entities ?? msg.caption_entities; - return entities.some((e) => { + const txt = ctx.message.text; + return ctx.message.entities.some((e) => { if (e.type !== "bot_command") return false; if (e.offset !== 0) return false; const cmd = txt.substring(1, e.length); if (noAtCommands.has(cmd) || atCommands.has(cmd)) { - ctx.match = txt.substr(cmd.length + 1).trimStart(); + ctx.match = txt.substring(cmd.length + 1).trimStart(); return true; } const index = cmd.indexOf("@"); @@ -410,7 +408,7 @@ export class Composer implements MiddlewareObj { if (atTarget !== ctx.me.username) return false; const atCommand = cmd.substring(0, index); if (noAtCommands.has(atCommand)) { - ctx.match = txt.substr(cmd.length + 1).trimStart(); + ctx.match = txt.substring(cmd.length + 1).trimStart(); return true; } return false; @@ -833,7 +831,7 @@ type HearsContext = Filter< >; type CommandContext = Filter< C & { match: string }, - ":entities:bot_command" + "message:entities:bot_command" >; function match( diff --git a/src/core/client.ts b/src/core/client.ts index 7a55a192..30ad2c48 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -216,7 +216,7 @@ class ApiClient { if (this.options.apiRoot.endsWith("/")) { throw new Error( `Remove the trailing '/' from the 'apiRoot' option (use '${ - this.options.apiRoot.substr( + this.options.apiRoot.substring( 0, this.options.apiRoot.length - 1, )