Comparing version
@@ -5,3 +5,3 @@ import { CallbackData } from '@gramio/callback-data'; | ||
export * from '@gramio/contexts'; | ||
import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types'; | ||
import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji } from '@gramio/types'; | ||
export * from '@gramio/types'; | ||
@@ -981,5 +981,5 @@ import * as middleware_io from 'middleware-io'; | ||
*/ | ||
command(command: string, handler: (context: ContextType<typeof this, "message"> & { | ||
command(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & { | ||
args: string | null; | ||
}) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this; | ||
}) => unknown): this; | ||
/** Currently not isolated!!! */ | ||
@@ -986,0 +986,0 @@ group(grouped: (bot: typeof this) => AnyBot): typeof this; |
@@ -1007,11 +1007,19 @@ import fs from 'node:fs/promises'; | ||
*/ | ||
command(command, handler, options) { | ||
if (command.startsWith("/")) | ||
throw new Error("Do not use / in command name"); | ||
command(command, handler) { | ||
const normalizedCommands = typeof command === "string" ? [command] : Array.from(command); | ||
for (const cmd of normalizedCommands) { | ||
if (cmd.startsWith("/")) | ||
throw new Error(`Do not use / in command name (${cmd})`); | ||
} | ||
return this.on(["message", "business_message"], (context, next) => { | ||
if (context.entities?.some((entity) => { | ||
if (entity.type !== "bot_command" || entity.offset > 0) return false; | ||
const cmd = context.text?.slice(1, entity.length)?.replace(`@${this.info.username}`, ""); | ||
const cmd = context.text?.slice(1, entity.length)?.replace( | ||
this.info?.username ? `@${this.info.username}` : /@[a-zA-Z0-9_]+/, | ||
"" | ||
); | ||
context.args = context.text?.slice(entity.length).trim() || null; | ||
return cmd === command; | ||
return normalizedCommands.some( | ||
(normalizedCommand) => cmd === normalizedCommand | ||
); | ||
})) | ||
@@ -1018,0 +1026,0 @@ return handler(context); |
{ | ||
"name": "gramio", | ||
"type": "module", | ||
"version": "0.4.5", | ||
"version": "0.4.7", | ||
"description": "Powerful, extensible and really type-safe Telegram Bot API framework", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.cjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
174487
0.2%3800
0.42%