Skip to content

Commit

Permalink
binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Zemani committed Aug 28, 2024
1 parent 4adb6b6 commit 22579af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/bot/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,17 +37,17 @@ export const createBot = (env: Environment) => {
});

// Initialize KV models for different data types
const userModel = new KVModel<User>("user", anonymous_kv);
const userBlockListModel = new KVModel<BlockList>("blockList", anonymous_kv);
const conversationModel = new KVModel<string>("conversation", anonymous_kv);
const userModel = new KVModel<User>("user", NekonymousKV);
const userBlockListModel = new KVModel<BlockList>("blockList", NekonymousKV);
const conversationModel = new KVModel<string>("conversation", NekonymousKV);
const currentConversationModel = new KVModel<CurrentConversation>(
"currentConversation",
anonymous_kv
NekonymousKV
);
const userIdToUUID = new KVModel<string>("userIdToUUID", anonymous_kv);
const userIdToUUID = new KVModel<string>("userIdToUUID", NekonymousKV);

// Initialize Logger
const logger = new Logger(r2_bucket);
const logger = new Logger(nekonymousr2);

/**
* Handles the /start command.
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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>("user", env.anonymous_kv);
const userModel = new KVModel<User>("user", env.NekonymousKV);

const conversationModel = new KVModel<string>(
"conversation",
env.anonymous_kv
env.NekonymousKV
);
const currentConversationModel = new KVModel<CurrentConversation>(
"currentConversation",
env.anonymous_kv
env.NekonymousKV
);
// Count online users, conversations, and users
onlineUsersCount = await currentConversationModel.count();
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 22579af

Please sign in to comment.