gramio 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1002,15 +1002,23 @@ class Bot {
1002
1002
  * return context.send(`You message is /start ${context.args}`);
1003
1003
  * });
1004
1004
  */
1005
- command(command, handler, options) {
1006
- if (command.startsWith("/"))
1007
- throw new Error("Do not use / in command name");
1005
+ command(command, handler) {
1006
+ const normalizedCommands = typeof command === "string" ? [command] : Array.from(command);
1007
+ for (const cmd of normalizedCommands) {
1008
+ if (cmd.startsWith("/"))
1009
+ throw new Error(`Do not use / in command name (${cmd})`);
1010
+ }
1008
1011
  return this.on(["message", "business_message"], (context, next) => {
1009
1012
  if (context.entities?.some((entity) => {
1010
1013
  if (entity.type !== "bot_command" || entity.offset > 0) return false;
1011
- const cmd = context.text?.slice(1, entity.length)?.replace(`@${this.info.username}`, "");
1014
+ const cmd = context.text?.slice(1, entity.length)?.replace(
1015
+ this.info?.username ? `@${this.info.username}` : /@[a-zA-Z0-9_]+/,
1016
+ ""
1017
+ );
1012
1018
  context.args = context.text?.slice(entity.length).trim() || null;
1013
- return cmd === command;
1019
+ return normalizedCommands.some(
1020
+ (normalizedCommand) => cmd === normalizedCommand
1021
+ );
1014
1022
  }))
1015
1023
  return handler(context);
1016
1024
  return next();
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { CallbackData } from '@gramio/callback-data';
2
2
  export * from '@gramio/callback-data';
3
3
  import { Context, UpdateName, ContextType, BotLike, Attachment } from '@gramio/contexts';
4
4
  export * from '@gramio/contexts';
5
- import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
5
+ import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji } from '@gramio/types';
6
6
  export * from '@gramio/types';
7
7
  import * as middleware_io from 'middleware-io';
8
8
  import { Composer as Composer$1, Middleware, CaughtMiddlewareHandler, NextMiddleware } from 'middleware-io';
@@ -977,9 +977,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
977
977
  * return context.send(`You message is /start ${context.args}`);
978
978
  * });
979
979
  */
980
- command(command: string, handler: (context: ContextType<typeof this, "message"> & {
980
+ command(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
981
981
  args: string | null;
982
- }) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
982
+ }) => unknown): this;
983
983
  /** Currently not isolated!!! */
984
984
  group(grouped: (bot: typeof this) => AnyBot): typeof this;
985
985
  /**
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { CallbackData } from '@gramio/callback-data';
2
2
  export * from '@gramio/callback-data';
3
3
  import { Context, UpdateName, ContextType, BotLike, Attachment } from '@gramio/contexts';
4
4
  export * from '@gramio/contexts';
5
- import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
5
+ import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramReactionTypeEmojiEmoji } from '@gramio/types';
6
6
  export * from '@gramio/types';
7
7
  import * as middleware_io from 'middleware-io';
8
8
  import { Composer as Composer$1, Middleware, CaughtMiddlewareHandler, NextMiddleware } from 'middleware-io';
@@ -977,9 +977,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
977
977
  * return context.send(`You message is /start ${context.args}`);
978
978
  * });
979
979
  */
980
- command(command: string, handler: (context: ContextType<typeof this, "message"> & {
980
+ command(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
981
981
  args: string | null;
982
- }) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
982
+ }) => unknown): this;
983
983
  /** Currently not isolated!!! */
984
984
  group(grouped: (bot: typeof this) => AnyBot): typeof this;
985
985
  /**
package/dist/index.js CHANGED
@@ -1004,15 +1004,23 @@ class Bot {
1004
1004
  * return context.send(`You message is /start ${context.args}`);
1005
1005
  * });
1006
1006
  */
1007
- command(command, handler, options) {
1008
- if (command.startsWith("/"))
1009
- throw new Error("Do not use / in command name");
1007
+ command(command, handler) {
1008
+ const normalizedCommands = typeof command === "string" ? [command] : Array.from(command);
1009
+ for (const cmd of normalizedCommands) {
1010
+ if (cmd.startsWith("/"))
1011
+ throw new Error(`Do not use / in command name (${cmd})`);
1012
+ }
1010
1013
  return this.on(["message", "business_message"], (context, next) => {
1011
1014
  if (context.entities?.some((entity) => {
1012
1015
  if (entity.type !== "bot_command" || entity.offset > 0) return false;
1013
- const cmd = context.text?.slice(1, entity.length)?.replace(`@${this.info.username}`, "");
1016
+ const cmd = context.text?.slice(1, entity.length)?.replace(
1017
+ this.info?.username ? `@${this.info.username}` : /@[a-zA-Z0-9_]+/,
1018
+ ""
1019
+ );
1014
1020
  context.args = context.text?.slice(entity.length).trim() || null;
1015
- return cmd === command;
1021
+ return normalizedCommands.some(
1022
+ (normalizedCommand) => cmd === normalizedCommand
1023
+ );
1016
1024
  }))
1017
1025
  return handler(context);
1018
1026
  return next();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.4.5",
4
+ "version": "0.4.7",
5
5
  "description": "Powerful, extensible and really type-safe Telegram Bot API framework",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",