From 0c31d908ccdd7bf50a4f00cf9bfdb1c348906e62 Mon Sep 17 00:00:00 2001 From: krau <71133316+krau@users.noreply.github.com> Date: Tue, 25 Feb 2025 16:23:24 +0800 Subject: [PATCH] feat: add dir command at init and show dirs in dir command help --- bot/bot.go | 1 + bot/handle_dir.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bot/bot.go b/bot/bot.go index 1eb448f..9e61c2d 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -76,6 +76,7 @@ func Init() { {Command: "silent", Description: "开启/关闭静默模式"}, {Command: "storage", Description: "设置默认存储端"}, {Command: "save", Description: "保存所回复的文件"}, + {Command: "dir", Description: "管理存储文件夹"}, }, }) resultChan <- struct { diff --git a/bot/handle_dir.go b/bot/handle_dir.go index ca98b7d..e14f2c1 100644 --- a/bot/handle_dir.go +++ b/bot/handle_dir.go @@ -14,6 +14,12 @@ import ( func dirCmd(ctx *ext.Context, update *ext.Update) error { args := strings.Split(strings.TrimPrefix(update.EffectiveMessage.Text, "/dir "), " ") if len(args) < 3 { + dirs, err := dao.GetUserDirsByChatID(update.GetUserChat().GetID()) + if err != nil { + logger.L.Errorf("获取用户路径失败: %s", err) + ctx.Reply(update, ext.ReplyTextString("获取用户路径失败"), nil) + return dispatcher.EndGroups + } ctx.Reply(update, ext.ReplyTextStyledTextArray( []styling.StyledTextOption{ styling.Bold("使用方法: /dir <操作> <存储名> <路径>"), @@ -24,6 +30,17 @@ func dirCmd(ctx *ext.Context, update *ext.Update) error { styling.Plain(" - 删除路径\n"), styling.Plain("\n示例:\n"), styling.Code("/dir add local1 path/to/dir"), + styling.Plain("\n\n当前已添加的路径:\n"), + styling.Blockquote(func() string { + var sb strings.Builder + for _, dir := range dirs { + sb.WriteString(dir.StorageName) + sb.WriteString(" - ") + sb.WriteString(dir.Path) + sb.WriteString("\n") + } + return sb.String() + }(), true), }, ), nil) return dispatcher.EndGroups