From 13de32ae002e4fadd2540f357399b3f9004584a7 Mon Sep 17 00:00:00 2001 From: Dmitry Anderson <4nd3r5z0n@gmail.com> Date: Sat, 19 Oct 2024 12:47:33 +0200 Subject: [PATCH] Setup mode added --- bot/lang/en.ts | 2 +- bot/normal_mode/init.ts | 4 ++-- bot/setup_mode/init.ts | 18 ++++++++++++++++++ config.ts | 2 +- main.ts | 8 ++++---- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bot/lang/en.ts b/bot/lang/en.ts index c061e70..fb9eb18 100644 --- a/bot/lang/en.ts +++ b/bot/lang/en.ts @@ -7,7 +7,7 @@ const pack: LangPack = { captcha: { already_in_chat: "You are already in chat", passed: (invite_link: string) => `Captcha passed! Now u can join to the community: ${invite_link}`, - failed: (timeout_mins: number) => `Капча не пройдена. Вы сможете попробовать снова через ${timeout_mins} минут.`, + failed: (timeout_mins: number) => `U didn't pass the captcha. U can try again after ${timeout_mins} minutes.`, } }, } diff --git a/bot/normal_mode/init.ts b/bot/normal_mode/init.ts index 22f09f8..6145de1 100644 --- a/bot/normal_mode/init.ts +++ b/bot/normal_mode/init.ts @@ -1,7 +1,7 @@ -import { Bot } from "https://deno.land/x/grammy@v1.30.0/mod.ts"; +import { Bot } from "https://deno.land/x/grammy/mod.ts"; import { Kysely } from "npm:kysely"; import { Ctx } from "../ctx.ts"; -import { CompiledConfig } from "../../cfg/exports.ts"; +import { CompiledConfig } from "../../cfg/config.ts"; import { Database } from "../../repo/exports.ts"; diff --git a/bot/setup_mode/init.ts b/bot/setup_mode/init.ts index e69de29..56ba2b9 100644 --- a/bot/setup_mode/init.ts +++ b/bot/setup_mode/init.ts @@ -0,0 +1,18 @@ +import { Bot } from "https://deno.land/x/grammy/mod.ts"; +import { CompiledConfig } from "../../cfg/config.ts"; +import { Ctx } from "../ctx.ts"; + +export const init = (bot: Bot, _: CompiledConfig) => { + bot.command("getchat", ctx => { + if (!ctx.from || !ctx.message) return + if (ctx.message.chat.type != "group" + && ctx.message.chat.type != "supergroup") return + ctx.deleteMessage() + console.log(`Chat ${ctx.message.chat.title} ID: ${ctx.message.chat.id}`) + }) + + bot.command("getme", ctx => { + if (!ctx.from) return + console.log(`User ${ctx.from.first_name} ${ctx.from.last_name} ID: ${ctx.from.id}`) + }) +} \ No newline at end of file diff --git a/config.ts b/config.ts index 263833d..454e9ba 100644 --- a/config.ts +++ b/config.ts @@ -13,7 +13,7 @@ export const DEFAULT_DB_NAME = "mic" export const DEFAULT_DB_PORT = 5432 export const DEFAULT_DB_TLS = false -export const reloadConfig = (): CompiledConfig => { +export const loadConfig = (): CompiledConfig => { const cfg = getConfig() const pgPoolCfg: PoolConfig = { host: cfg.db_name || DEFAULT_DB_HOST, diff --git a/main.ts b/main.ts index 173f0ad..cb90fb2 100644 --- a/main.ts +++ b/main.ts @@ -1,20 +1,20 @@ import { runBot } from "./bot/bot.ts"; import { init as initNormalMode } from "./bot/normal_mode/init.ts" import { setupDB } from "./repo/exports.ts"; -import { reloadConfig } from "./config.ts"; +import { loadConfig } from "./config.ts"; import { BotMode } from "./cfg/bot.ts"; const main = async () => { - const cfg = reloadConfig() + const cfg = loadConfig() const { botCfg } = cfg const { db } = await setupDB(cfg) runBot(botCfg, (bot) => { switch (botCfg.mode) { - case BotMode.setup: + case BotMode.normal: initNormalMode(bot, db, cfg) break; - case BotMode.normal: + case BotMode.setup: break; } })