Skip to content

Commit

Permalink
chore: some fixes and hears now handle caption too
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Sep 16, 2024
1 parent 3b29ceb commit bac2063
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gramio",
"type": "commonjs",
"version": "0.0.49",
"version": "0.0.50",
"description": "Powerful, extensible and really type-safe Telegram Bot API framework",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
21 changes: 8 additions & 13 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ export class Bot<
const res = await fetch(url);

if (path) {
if(!res.body) throw new Error("Response without body (should be never throw)")
if (!res.body)
throw new Error("Response without body (should be never throw)");

await fs.writeFile(path, Readable.fromWeb(res.body));

Expand Down Expand Up @@ -974,9 +975,7 @@ export class Bot<
(typeof trigger === "string" && context.query === trigger) ||
// @ts-expect-error
(typeof trigger === "function" && trigger(context)) ||
(trigger instanceof RegExp &&
context.query &&
trigger.test(context.query))
(trigger instanceof RegExp && trigger.test(context.query))
) {
//@ts-expect-error
context.args =
Expand Down Expand Up @@ -1049,9 +1048,7 @@ export class Bot<
(typeof trigger === "string" && context.query === trigger) ||
// @ts-expect-error
(typeof trigger === "function" && trigger(context)) ||
(trigger instanceof RegExp &&
context.query &&
trigger.test(context.query))
(trigger instanceof RegExp && trigger.test(context.query))
) {
//@ts-expect-error
context.args =
Expand Down Expand Up @@ -1082,17 +1079,15 @@ export class Bot<
handler: (context: Ctx & { args: RegExpMatchArray | null }) => unknown,
) {
return this.on("message", (context, next) => {
const text = context.text ?? context.caption;
if (
(typeof trigger === "string" && context.text === trigger) ||
(typeof trigger === "string" && text === trigger) ||
// @ts-expect-error
(typeof trigger === "function" && trigger(context)) ||
(trigger instanceof RegExp &&
context.text &&
trigger.test(context.text))
(trigger instanceof RegExp && text && trigger.test(text))
) {
//@ts-expect-error
context.args =
trigger instanceof RegExp ? context.text?.match(trigger) : null;
context.args = trigger instanceof RegExp ? text?.match(trigger) : null;

// TODO: remove
//@ts-expect-error
Expand Down

0 comments on commit bac2063

Please sign in to comment.