first
This commit is contained in:
62
internal/telegram/handlers_cat.go
Normal file
62
internal/telegram/handlers_cat.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
tele "gopkg.in/telebot.v3"
|
||||
)
|
||||
|
||||
func (b *Bot) handleCatAdd(c tele.Context) error {
|
||||
args := strings.Fields(c.Message().Payload)
|
||||
if len(args) == 0 {
|
||||
return c.Reply("用法: /cat_add <名称> [排序]\n例如: /cat_add iOS 1")
|
||||
}
|
||||
|
||||
name := args[0]
|
||||
order := 0
|
||||
if len(args) > 1 {
|
||||
if o, err := strconv.Atoi(args[1]); err == nil {
|
||||
order = o
|
||||
}
|
||||
}
|
||||
|
||||
if err := b.storage.CreateCategory(name, order); err != nil {
|
||||
return c.Reply(fmt.Sprintf("❌ 创建失败: %v", err))
|
||||
}
|
||||
|
||||
return c.Reply(fmt.Sprintf("✅ 分类 [%s] 已创建 (排序: %d)", name, order))
|
||||
}
|
||||
|
||||
func (b *Bot) handleCatDel(c tele.Context) error {
|
||||
name := strings.TrimSpace(c.Message().Payload)
|
||||
if name == "" {
|
||||
return c.Reply("用法: /cat_del <名称>")
|
||||
}
|
||||
|
||||
if err := b.storage.DeleteCategory(name); err != nil {
|
||||
return c.Reply(fmt.Sprintf("❌ 删除失败: %v", err))
|
||||
}
|
||||
|
||||
return c.Reply(fmt.Sprintf("✅ 分类 [%s] 已删除", name))
|
||||
}
|
||||
|
||||
func (b *Bot) handleCatList(c tele.Context) error {
|
||||
categories, err := b.storage.ListCategories()
|
||||
if err != nil {
|
||||
return c.Reply(fmt.Sprintf("❌ 获取失败: %v", err))
|
||||
}
|
||||
|
||||
if len(categories) == 0 {
|
||||
return c.Reply("📂 暂无分类\n使用 /cat_add <名称> 创建")
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString("📂 分类列表:\n\n")
|
||||
for i, cat := range categories {
|
||||
sb.WriteString(fmt.Sprintf("%d. %s (排序: %d)\n", i+1, cat.Name, cat.Order))
|
||||
}
|
||||
|
||||
return c.Reply(sb.String())
|
||||
}
|
||||
Reference in New Issue
Block a user