gramio 0.4.7 → 0.4.9

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
@@ -428,7 +428,7 @@ class Bot {
428
428
  __Derives;
429
429
  "~" = this._;
430
430
  filters = {
431
- context: (name2) => (context) => context.is(name2)
431
+ context: (name) => (context) => context.is(name)
432
432
  };
433
433
  /** Options provided to instance */
434
434
  options;
@@ -651,18 +651,27 @@ class Bot {
651
651
  return this;
652
652
  }
653
653
  decorate(nameOrRecordValue, value) {
654
- for (const contextName of Object.keys(contexts.contextsMappings)) {
654
+ for (const contextName of Object.keys(
655
+ contexts.contextsMappings
656
+ )) {
655
657
  if (typeof nameOrRecordValue === "string")
656
- Object.defineProperty(contexts.contextsMappings[contextName].prototype, name, {
657
- value
658
- });
658
+ Object.defineProperty(
659
+ contexts.contextsMappings[contextName].prototype,
660
+ nameOrRecordValue,
661
+ {
662
+ value,
663
+ configurable: true
664
+ }
665
+ );
659
666
  else
660
667
  Object.defineProperties(
661
- // @ts-expect-error
662
668
  contexts.contextsMappings[contextName].prototype,
663
669
  Object.keys(nameOrRecordValue).reduce(
664
670
  (acc, key) => {
665
- acc[key] = { value: nameOrRecordValue[key] };
671
+ acc[key] = {
672
+ value: nameOrRecordValue[key],
673
+ configurable: true
674
+ };
666
675
  return acc;
667
676
  },
668
677
  {}
@@ -987,7 +996,7 @@ class Bot {
987
996
  hears(trigger, handler) {
988
997
  return this.on("message", (context, next) => {
989
998
  const text = context.text ?? context.caption;
990
- if (typeof trigger === "string" && text === trigger || // @ts-expect-error
999
+ if (typeof trigger === "string" && text === trigger || Array.isArray(trigger) && text && trigger.includes(text) || // @ts-expect-error
991
1000
  typeof trigger === "function" && trigger(context) || trigger instanceof RegExp && text && trigger.test(text)) {
992
1001
  context.args = trigger instanceof RegExp ? text?.match(trigger) : null;
993
1002
  return handler(context);
package/dist/index.d.cts CHANGED
@@ -967,7 +967,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
967
967
  * if (context.args) await context.send(`Params ${context.args[1]}`);
968
968
  * });
969
969
  */
970
- hears<Ctx = ContextType<typeof this, "message">, Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
970
+ hears<Ctx = ContextType<typeof this, "message">, Trigger extends RegExp | MaybeArray<string> | ((context: Ctx) => boolean) = RegExp | MaybeArray<string> | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
971
971
  args: RegExpMatchArray | null;
972
972
  }) => unknown): this;
973
973
  /**
package/dist/index.d.ts CHANGED
@@ -967,7 +967,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
967
967
  * if (context.args) await context.send(`Params ${context.args[1]}`);
968
968
  * });
969
969
  */
970
- hears<Ctx = ContextType<typeof this, "message">, Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
970
+ hears<Ctx = ContextType<typeof this, "message">, Trigger extends RegExp | MaybeArray<string> | ((context: Ctx) => boolean) = RegExp | MaybeArray<string> | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
971
971
  args: RegExpMatchArray | null;
972
972
  }) => unknown): this;
973
973
  /**
package/dist/index.js CHANGED
@@ -430,7 +430,7 @@ class Bot {
430
430
  __Derives;
431
431
  "~" = this._;
432
432
  filters = {
433
- context: (name2) => (context) => context.is(name2)
433
+ context: (name) => (context) => context.is(name)
434
434
  };
435
435
  /** Options provided to instance */
436
436
  options;
@@ -653,18 +653,27 @@ class Bot {
653
653
  return this;
654
654
  }
655
655
  decorate(nameOrRecordValue, value) {
656
- for (const contextName of Object.keys(contextsMappings)) {
656
+ for (const contextName of Object.keys(
657
+ contextsMappings
658
+ )) {
657
659
  if (typeof nameOrRecordValue === "string")
658
- Object.defineProperty(contextsMappings[contextName].prototype, name, {
659
- value
660
- });
660
+ Object.defineProperty(
661
+ contextsMappings[contextName].prototype,
662
+ nameOrRecordValue,
663
+ {
664
+ value,
665
+ configurable: true
666
+ }
667
+ );
661
668
  else
662
669
  Object.defineProperties(
663
- // @ts-expect-error
664
670
  contextsMappings[contextName].prototype,
665
671
  Object.keys(nameOrRecordValue).reduce(
666
672
  (acc, key) => {
667
- acc[key] = { value: nameOrRecordValue[key] };
673
+ acc[key] = {
674
+ value: nameOrRecordValue[key],
675
+ configurable: true
676
+ };
668
677
  return acc;
669
678
  },
670
679
  {}
@@ -989,7 +998,7 @@ class Bot {
989
998
  hears(trigger, handler) {
990
999
  return this.on("message", (context, next) => {
991
1000
  const text = context.text ?? context.caption;
992
- if (typeof trigger === "string" && text === trigger || // @ts-expect-error
1001
+ if (typeof trigger === "string" && text === trigger || Array.isArray(trigger) && text && trigger.includes(text) || // @ts-expect-error
993
1002
  typeof trigger === "function" && trigger(context) || trigger instanceof RegExp && text && trigger.test(text)) {
994
1003
  context.args = trigger instanceof RegExp ? text?.match(trigger) : null;
995
1004
  return handler(context);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.4.7",
4
+ "version": "0.4.9",
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",