From 22579afcbaf6f9aeac1bcddc25e671fd54cd55e8 Mon Sep 17 00:00:00 2001 From: Ali Zemani Date: Wed, 28 Aug 2024 12:14:10 +0330 Subject: [PATCH] binding --- src/bot/bot.ts | 16 ++++++++-------- src/index.ts | 14 +++++++------- src/types.ts | 4 ++-- wrangler.toml | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/bot/bot.ts b/src/bot/bot.ts index 013a612..2d9312c 100644 --- a/src/bot/bot.ts +++ b/src/bot/bot.ts @@ -25,9 +25,9 @@ import { export const createBot = (env: Environment) => { const { SECRET_TELEGRAM_API_TOKEN, - anonymous_kv, + NekonymousKV, BOT_INFO, - r2_bucket, + nekonymousr2, APP_SECURE_KEY, } = env; @@ -37,17 +37,17 @@ export const createBot = (env: Environment) => { }); // Initialize KV models for different data types - const userModel = new KVModel("user", anonymous_kv); - const userBlockListModel = new KVModel("blockList", anonymous_kv); - const conversationModel = new KVModel("conversation", anonymous_kv); + const userModel = new KVModel("user", NekonymousKV); + const userBlockListModel = new KVModel("blockList", NekonymousKV); + const conversationModel = new KVModel("conversation", NekonymousKV); const currentConversationModel = new KVModel( "currentConversation", - anonymous_kv + NekonymousKV ); - const userIdToUUID = new KVModel("userIdToUUID", anonymous_kv); + const userIdToUUID = new KVModel("userIdToUUID", NekonymousKV); // Initialize Logger - const logger = new Logger(r2_bucket); + const logger = new Logger(nekonymousr2); /** * Handles the /start command. diff --git a/src/index.ts b/src/index.ts index 7675b26..40a75b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,8 +12,8 @@ import { convertToPersianNumbers } from "./utils/tools"; export interface Environment { SECRET_TELEGRAM_API_TOKEN: string; - anonymous_kv: KVNamespace; - r2_bucket: R2Bucket; + NekonymousKV: KVNamespace; + nekonymousr2: R2Bucket; BOT_INFO: string; BOT_NAME: string; APP_SECURE_KEY: string; @@ -61,9 +61,9 @@ router.get( let conversationsCount; let usersCount; - if (env.r2_bucket) { + if (env.nekonymousr2) { // Initialize the Logger with the R2 bucket - const logger = new Logger(env.r2_bucket); + const logger = new Logger(env.nekonymousr2); const startDate = new Date(); startDate.setDate(startDate.getDate() - 7); // 7 days ago @@ -85,15 +85,15 @@ router.get( ).length; // Assuming each "new_conversation" log represents a conversation usersCount = logs.filter((log) => log.action === "new_user").length; } else { - const userModel = new KVModel("user", env.anonymous_kv); + const userModel = new KVModel("user", env.NekonymousKV); const conversationModel = new KVModel( "conversation", - env.anonymous_kv + env.NekonymousKV ); const currentConversationModel = new KVModel( "currentConversation", - env.anonymous_kv + env.NekonymousKV ); // Count online users, conversations, and users onlineUsersCount = await currentConversationModel.count(); diff --git a/src/types.ts b/src/types.ts index eebc5d4..754e71b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,8 +37,8 @@ export interface BlockList { */ export interface Environment { SECRET_TELEGRAM_API_TOKEN: string; - anonymous_kv: KVNamespace; - r2_bucket: R2Bucket; + NekonymousKV: KVNamespace; + nekonymousr2: R2Bucket; BOT_INFO: string; BOT_NAME: string; APP_SECURE_KEY: string; diff --git a/wrangler.toml b/wrangler.toml index 0d827ed..356774a 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -5,11 +5,11 @@ compatibility_date = "2024-08-19" workers_dev = true kv_namespaces = [ - { binding = "nekonymous", id = "42628bc70b644ea7903d7f3cd723b279" }, + { binding = "NekonymousKV", id = "de26a1b398614383a2b9702fafaa8824" }, ] r2_buckets = [ - { binding = "r2_bucket", bucket_name = "nekonymous"} + { binding = "nekonymousr2", bucket_name = "nekonymousr2"} ] [placement] mode = "smart"