gramio 0.2.3 → 0.2.4

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
@@ -537,7 +537,8 @@ class Bot {
537
537
  constructor(tokenOrOptions, optionsRaw) {
538
538
  const token = typeof tokenOrOptions === "string" ? tokenOrOptions : tokenOrOptions?.token;
539
539
  const options = typeof tokenOrOptions === "object" ? tokenOrOptions : optionsRaw;
540
- if (!token || typeof token !== "string")
540
+ if (!token) throw new Error("Token is required!");
541
+ if (typeof token !== "string")
541
542
  throw new Error(`Token is ${typeof token} but it should be a string!`);
542
543
  this.options = {
543
544
  ...options,
@@ -953,12 +954,14 @@ class Bot {
953
954
  if (!context.data) return next();
954
955
  if (typeof trigger === "string" && context.data !== trigger)
955
956
  return next();
956
- if (trigger instanceof callbackData.CallbackData && !trigger.regexp().test(context.data))
957
- return next();
958
- if (trigger instanceof RegExp && !trigger.test(context.data))
959
- return next();
960
- if (trigger instanceof callbackData.CallbackData)
957
+ if (trigger instanceof RegExp) {
958
+ if (!trigger.test(context.data)) return next();
959
+ context.queryData = context.data.match(trigger);
960
+ }
961
+ if (trigger instanceof callbackData.CallbackData) {
962
+ if (!trigger.regexp().test(context.data)) return next();
961
963
  context.queryData = trigger.unpack(context.data);
964
+ }
962
965
  return handler(context);
963
966
  });
964
967
  }
package/dist/index.d.cts CHANGED
@@ -889,7 +889,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
889
889
  * ```
890
890
  */
891
891
  callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: Omit<ContextType<typeof this, "callback_query">, "data"> & Derives["global"] & Derives["callback_query"] & {
892
- queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : RegExpMatchArray | null;
892
+ queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
893
893
  }) => unknown): this;
894
894
  /** Register handler to `chosen_inline_result` update */
895
895
  chosenInlineResult<Ctx = ContextType<typeof this, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
package/dist/index.d.ts CHANGED
@@ -889,7 +889,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
889
889
  * ```
890
890
  */
891
891
  callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: Omit<ContextType<typeof this, "callback_query">, "data"> & Derives["global"] & Derives["callback_query"] & {
892
- queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : RegExpMatchArray | null;
892
+ queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
893
893
  }) => unknown): this;
894
894
  /** Register handler to `chosen_inline_result` update */
895
895
  chosenInlineResult<Ctx = ContextType<typeof this, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
package/dist/index.js CHANGED
@@ -539,7 +539,8 @@ class Bot {
539
539
  constructor(tokenOrOptions, optionsRaw) {
540
540
  const token = typeof tokenOrOptions === "string" ? tokenOrOptions : tokenOrOptions?.token;
541
541
  const options = typeof tokenOrOptions === "object" ? tokenOrOptions : optionsRaw;
542
- if (!token || typeof token !== "string")
542
+ if (!token) throw new Error("Token is required!");
543
+ if (typeof token !== "string")
543
544
  throw new Error(`Token is ${typeof token} but it should be a string!`);
544
545
  this.options = {
545
546
  ...options,
@@ -955,12 +956,14 @@ class Bot {
955
956
  if (!context.data) return next();
956
957
  if (typeof trigger === "string" && context.data !== trigger)
957
958
  return next();
958
- if (trigger instanceof CallbackData && !trigger.regexp().test(context.data))
959
- return next();
960
- if (trigger instanceof RegExp && !trigger.test(context.data))
961
- return next();
962
- if (trigger instanceof CallbackData)
959
+ if (trigger instanceof RegExp) {
960
+ if (!trigger.test(context.data)) return next();
961
+ context.queryData = context.data.match(trigger);
962
+ }
963
+ if (trigger instanceof CallbackData) {
964
+ if (!trigger.regexp().test(context.data)) return next();
963
965
  context.queryData = trigger.unpack(context.data);
966
+ }
964
967
  return handler(context);
965
968
  });
966
969
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.2.3",
4
+ "version": "0.2.4",
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",