From 78426c89eaa53f2231c3111b29623a7449051eb2 Mon Sep 17 00:00:00 2001 From: chuangcaleb Date: Sat, 27 Apr 2024 19:24:49 +0800 Subject: [PATCH] refac: move sendmessage into its own dir --- .gitignore | 3 ++- src/bot/features/index.ts | 1 + .../sendmessage}/index.ts | 0 .../sendmessage}/sendmessage.conversation.ts | 21 +++++++------------ .../features/{ => sendmessage}/sendmessage.ts | 2 +- src/bot/index.ts | 4 ++-- 6 files changed, 13 insertions(+), 18 deletions(-) rename src/bot/{conversations => features/sendmessage}/index.ts (100%) rename src/bot/{conversations => features/sendmessage}/sendmessage.conversation.ts (58%) rename src/bot/features/{ => sendmessage}/sendmessage.ts (86%) diff --git a/.gitignore b/.gitignore index b557e62..83ba852 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,5 @@ data/ *.db *.db-journal -.vscode/ \ No newline at end of file +.vscode/ +**mock** \ No newline at end of file diff --git a/src/bot/features/index.ts b/src/bot/features/index.ts index 77f2609..c28a062 100644 --- a/src/bot/features/index.ts +++ b/src/bot/features/index.ts @@ -2,3 +2,4 @@ export * from "./admin.js"; export * from "./language.js"; export * from "./unhandled.js"; export * from "./welcome.js"; +export * from "./sendmessage/index.js"; diff --git a/src/bot/conversations/index.ts b/src/bot/features/sendmessage/index.ts similarity index 100% rename from src/bot/conversations/index.ts rename to src/bot/features/sendmessage/index.ts diff --git a/src/bot/conversations/sendmessage.conversation.ts b/src/bot/features/sendmessage/sendmessage.conversation.ts similarity index 58% rename from src/bot/conversations/sendmessage.conversation.ts rename to src/bot/features/sendmessage/sendmessage.conversation.ts index 2ac7b5c..1307120 100644 --- a/src/bot/conversations/sendmessage.conversation.ts +++ b/src/bot/features/sendmessage/sendmessage.conversation.ts @@ -1,6 +1,7 @@ import { Conversation, createConversation } from "@grammyjs/conversations"; import { Context } from "~/bot/context.js"; import { i18n } from "~/bot/i18n.js"; +import { REGISTRY } from "./mock-data.js"; export const SENDMESSAGE_CONVERSATION = "sendmessage"; @@ -9,28 +10,20 @@ export function sendmessageConversation() { async (conversation: Conversation, ctx: Context) => { await conversation.run(i18n); + // Get message await ctx.reply("Please tell me the message you want to send"); - ctx = await conversation.waitFor("message::bold", { + const messageCtx = await conversation.waitFor("message::bold", { otherwise: async (ctxx) => { ctxx.reply("please send bold"); await conversation.skip({ drop: true }); }, }); - ctx.reply(ctx.message?.text as string); + const message = messageCtx.message?.text ?? ""; - // while (true) { - // ctx = await conversation.wait(); - - // if (ctx.has("message:text")) { - // ctx.chatAction = "typing"; - // await conversation.sleep(1000); - - // await ctx.reply(`Hello, ${ctx.message.text}!`); - // } else { - // await ctx.reply("Please send me your name"); - // } - // } + // Get targets + await ctx.reply("Please select the students"); + ctx.api.sendMessage(REGISTRY.Chuang, message); }, SENDMESSAGE_CONVERSATION ); diff --git a/src/bot/features/sendmessage.ts b/src/bot/features/sendmessage/sendmessage.ts similarity index 86% rename from src/bot/features/sendmessage.ts rename to src/bot/features/sendmessage/sendmessage.ts index b454bbd..35754f0 100644 --- a/src/bot/features/sendmessage.ts +++ b/src/bot/features/sendmessage/sendmessage.ts @@ -1,7 +1,7 @@ import { Composer } from "grammy"; import type { Context } from "~/bot/context.js"; import { logHandle } from "~/bot/helpers/logging.js"; -import { SENDMESSAGE_CONVERSATION } from "../conversations/sendmessage.conversation.js"; +import { SENDMESSAGE_CONVERSATION } from "./sendmessage.conversation.js"; const composer = new Composer(); diff --git a/src/bot/index.ts b/src/bot/index.ts index 1e1207f..55fd4d9 100644 --- a/src/bot/index.ts +++ b/src/bot/index.ts @@ -19,8 +19,8 @@ import { i18n, isMultipleLocales } from "~/bot/i18n.js"; import { updateLogger } from "~/bot/middlewares/index.js"; import { config } from "~/config.js"; import { logger } from "~/logger.js"; -import { sendmessageConversation } from "./conversations/sendmessage.conversation.js"; -import { sendmessageFeature } from "./features/sendmessage.js"; +import { sendmessageConversation } from "./features/sendmessage/sendmessage.conversation.js"; +import { sendmessageFeature } from "./features/sendmessage/sendmessage.js"; type Options = { sessionStorage?: StorageAdapter;