From e756436765d956f81721653641990bebc9099402 Mon Sep 17 00:00:00 2001 From: tbxark Date: Wed, 9 Oct 2024 09:43:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=83=A8=E5=88=86class=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0bind=20this?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 25 +++++++++++++++++++++++-- dist/timestamp | 2 +- src/config/env.ts | 5 +++++ src/telegram/api/index.ts | 2 ++ src/telegram/utils/send.ts | 3 +++ src/utils/cache/index.ts | 2 ++ src/utils/router/index.ts | 10 ++++++++++ 8 files changed, 47 insertions(+), 4 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 74bceb75..f8305268 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha":"db772d7","timestamp":1727589780} \ No newline at end of file +{"sha":"b876e24","timestamp":1728438149} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 0bf05ffb..fa5daf74 100644 --- a/dist/index.js +++ b/dist/index.js @@ -211,8 +211,8 @@ const ENV_KEY_MAPPER = { WORKERS_AI_MODEL: "WORKERS_CHAT_MODEL" }; class Environment extends EnvironmentConfig { - BUILD_TIMESTAMP = 1727589780 ; - BUILD_VERSION = "db772d7" ; + BUILD_TIMESTAMP = 1728438149 ; + BUILD_VERSION = "b876e24" ; I18N = loadI18n(); PLUGINS_ENV = {}; USER_CONFIG = createAgentUserConfig(); @@ -220,6 +220,10 @@ class Environment extends EnvironmentConfig { PLUGINS_COMMAND = {}; DATABASE = null; API_GUARD = null; + constructor() { + super(); + this.merge = this.merge.bind(this); + } merge(source) { this.DATABASE = source.DATABASE; this.API_GUARD = source.API_GUARD; @@ -309,6 +313,8 @@ class APIClientBase { while (this.baseURL.endsWith("/")) { this.baseURL = this.baseURL.slice(0, -1); } + this.request = this.request.bind(this); + this.requestJSON = this.requestJSON.bind(this); } uri(method) { return `${this.baseURL}/bot${this.token}/${method}`; @@ -593,6 +599,9 @@ class MessageSender { constructor(token, context) { this.api = createTelegramBotAPI(token); this.context = context; + this.sendRichText = this.sendRichText.bind(this); + this.sendPlainText = this.sendPlainText.bind(this); + this.sendPhoto = this.sendPhoto.bind(this); } static from(token, message) { return new MessageSender(token, new MessageContext(message)); @@ -758,6 +767,8 @@ class Cache { this.maxItems = 10; this.maxAge = 1e3 * 60 * 60; this.cache = {}; + this.set = this.set.bind(this); + this.get = this.get.bind(this); } set(key, value) { this.trim(); @@ -2702,6 +2713,16 @@ class Router { this.routes = routes; this.base = base; Object.assign(this, other); + this.fetch = this.fetch.bind(this); + this.route = this.route.bind(this); + this.get = this.get.bind(this); + this.post = this.post.bind(this); + this.put = this.put.bind(this); + this.delete = this.delete.bind(this); + this.patch = this.patch.bind(this); + this.head = this.head.bind(this); + this.options = this.options.bind(this); + this.all = this.all.bind(this); } parseQueryParams(searchParams) { const query = {}; diff --git a/dist/timestamp b/dist/timestamp index a4eee1dc..c7e21b99 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1727589780 \ No newline at end of file +1728438149 \ No newline at end of file diff --git a/src/config/env.ts b/src/config/env.ts index c77a28a3..0f3b2a56 100644 --- a/src/config/env.ts +++ b/src/config/env.ts @@ -71,6 +71,11 @@ class Environment extends EnvironmentConfig { DATABASE: KVNamespace = null as any; API_GUARD: APIGuard | null = null; + constructor() { + super(); + this.merge = this.merge.bind(this); + } + merge(source: any) { // 全局对象 this.DATABASE = source.DATABASE; diff --git a/src/telegram/api/index.ts b/src/telegram/api/index.ts index 4de7d69c..244886e2 100644 --- a/src/telegram/api/index.ts +++ b/src/telegram/api/index.ts @@ -13,6 +13,8 @@ class APIClientBase { while (this.baseURL.endsWith('/')) { this.baseURL = this.baseURL.slice(0, -1); } + this.request = this.request.bind(this); + this.requestJSON = this.requestJSON.bind(this); } private uri(method: Telegram.BotMethod): string { diff --git a/src/telegram/utils/send.ts b/src/telegram/utils/send.ts index d5cea9db..0a556c3d 100644 --- a/src/telegram/utils/send.ts +++ b/src/telegram/utils/send.ts @@ -30,6 +30,9 @@ export class MessageSender { constructor(token: string, context: MessageContext) { this.api = createTelegramBotAPI(token); this.context = context; + this.sendRichText = this.sendRichText.bind(this); + this.sendPlainText = this.sendPlainText.bind(this); + this.sendPhoto = this.sendPhoto.bind(this); } static from(token: string, message: Telegram.Message): MessageSender { diff --git a/src/utils/cache/index.ts b/src/utils/cache/index.ts index 3f99ee5b..399c3650 100644 --- a/src/utils/cache/index.ts +++ b/src/utils/cache/index.ts @@ -13,6 +13,8 @@ export class Cache { this.maxItems = 10; this.maxAge = 1000 * 60 * 60; this.cache = {}; + this.set = this.set.bind(this); + this.get = this.get.bind(this); } set(key: string, value: T) { diff --git a/src/utils/router/index.ts b/src/utils/router/index.ts index 2f9bdcb5..a6eccd10 100644 --- a/src/utils/router/index.ts +++ b/src/utils/router/index.ts @@ -18,6 +18,16 @@ export class Router { this.routes = routes; this.base = base; Object.assign(this, other); + this.fetch = this.fetch.bind(this); + this.route = this.route.bind(this); + this.get = this.get.bind(this); + this.post = this.post.bind(this); + this.put = this.put.bind(this); + this.delete = this.delete.bind(this); + this.patch = this.patch.bind(this); + this.head = this.head.bind(this); + this.options = this.options.bind(this); + this.all = this.all.bind(this); } private parseQueryParams(searchParams: URLSearchParams): QueryParams {