Refactor post handling and add command setup for Telegram bot

This commit is contained in:
dela
2026-02-05 00:52:29 +08:00
parent d82badc6e3
commit 8a6859269c
9 changed files with 612 additions and 21 deletions

View File

@@ -55,7 +55,7 @@ func (b *Bot) setupRoutes() {
// Post flow
adminOnly.Handle("/post", b.handlePost)
adminOnly.Handle(tele.OnText, b.handleTextOrForwarded)
adminOnly.Handle(tele.OnText, b.handleTextInput)
// Entry management
adminOnly.Handle("/del", b.handleEntryDel)
@@ -66,15 +66,41 @@ func (b *Bot) setupRoutes() {
// TOC
adminOnly.Handle("/refresh", b.handleRefresh)
// Admin management (super admin only)
superAdminOnly := b.bot.Group()
superAdminOnly.Use(b.SuperAdminMiddleware())
superAdminOnly.Handle("/admin_add", b.handleAdminAdd)
superAdminOnly.Handle("/admin_del", b.handleAdminDel)
superAdminOnly.Handle("/admin_list", b.handleAdminList)
// Callbacks
b.bot.Handle(tele.OnCallback, b.handleCallback)
}
func (b *Bot) Start() {
b.setCommands()
log.Println("Bot started...")
b.bot.Start()
}
func (b *Bot) setCommands() {
commands := []tele.Command{
{Text: "post", Description: "投稿 - 添加频道内容到目录"},
{Text: "list", Description: "列表 - 查看所有条目"},
{Text: "cat_list", Description: "分类列表"},
{Text: "cat_add", Description: "添加分类 <名称> [排序]"},
{Text: "cat_del", Description: "删除分类 <名称>"},
{Text: "del", Description: "删除条目 <ID>"},
{Text: "edit", Description: "编辑标题 <ID> <新标题>"},
{Text: "move", Description: "移动条目 <ID> <新分类>"},
{Text: "refresh", Description: "刷新目录"},
}
if err := b.bot.SetCommands(commands); err != nil {
log.Printf("Failed to set commands: %v", err)
}
}
func (b *Bot) Stop() {
b.bot.Stop()
b.toc.Stop()