diff --git a/internal/service/telegram_api_test.go b/internal/service/telegram_api_test.go index 55784c5..ed0fafa 100644 --- a/internal/service/telegram_api_test.go +++ b/internal/service/telegram_api_test.go @@ -184,8 +184,8 @@ func TestTelegramCommandMenusSeparateGroupAndAdminCommands(t *testing.T) { } } for _, command := range adminCommands { - if strings.Contains(command.Description, "Sakura") { - t.Fatalf("admin menu command %s should not mention Sakura: %q", command.Command, command.Description) + if strings.Contains(command.Description, "Mgo 兼容") { + t.Fatalf("admin menu command %s should use native Mgo wording: %q", command.Command, command.Description) } } } diff --git a/internal/service/telegram_bot.go b/internal/service/telegram_bot.go index 7751ad0..326b670 100644 --- a/internal/service/telegram_bot.go +++ b/internal/service/telegram_bot.go @@ -534,7 +534,7 @@ func (s *TelegramBotService) cmdHelp(ctx context.Context, msg *TelegramMessage) "/search 关键词 — 搜索媒体库\n" + "/downloads — 下载列表\n" + "/stats — 媒体库统计\n\n" + - "Mgo 兼容 Sakura 管理命令:\n" + + "Mgo 管理命令:\n" + "用户:/ucr /uinfo /rmemby /only_rm_record /renewall\n" + "审计:/userip /auditip /auditdevice /auditclient /udeviceid\n" + "清理:/syncunbound /syncgroupm /check_ex /deleted /low_activity\n" + diff --git a/internal/service/telegram_bot_user_test.go b/internal/service/telegram_bot_user_test.go index d4a59d1..d208d03 100644 --- a/internal/service/telegram_bot_user_test.go +++ b/internal/service/telegram_bot_user_test.go @@ -230,7 +230,7 @@ func TestTelegramPollingChannelHintWinsForPrivateMessages(t *testing.T) { } } -func TestTelegramSakuraCompatibleUserCommands(t *testing.T) { +func TestTelegramMgoCompatibleUserCommands(t *testing.T) { ctx := t.Context() repos, bot := newBotTestService(t) user := &model.User{Username: "viewer", PasswordHash: "hash", Role: "user", IsActive: true} diff --git a/internal/service/telegram_commands.go b/internal/service/telegram_commands.go index 8beb424..5226cc7 100644 --- a/internal/service/telegram_commands.go +++ b/internal/service/telegram_commands.go @@ -75,64 +75,64 @@ func (s *TelegramBotService) telegramCommandDefinitions(ctx context.Context, cha {Aliases: []string{"/downloads"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdDownloads(ctx) }}, {Aliases: []string{"/stats"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdStats(ctx) }}, {Aliases: []string{"/renew"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdUserRenew(ctx, args), nil }}, - {Aliases: []string{"/ucr"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraCreateUser(ctx, args), nil }}, - {Aliases: []string{"/uinfo"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraUserInfo(ctx, args), nil }}, - {Aliases: []string{"/rmemby", "/urm", "/only_rm_emby"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraDeleteUser(ctx, args), nil }}, - {Aliases: []string{"/only_rm_record"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraOnlyRemoveRecord(ctx, args), nil }}, - {Aliases: []string{"/userip"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraUserIP(ctx, args), nil }}, + {Aliases: []string{"/ucr"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoCreateUser(ctx, args), nil }}, + {Aliases: []string{"/uinfo"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoUserInfo(ctx, args), nil }}, + {Aliases: []string{"/rmemby", "/urm", "/only_rm_emby"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoDeleteUser(ctx, args), nil }}, + {Aliases: []string{"/only_rm_record"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoOnlyRemoveRecord(ctx, args), nil }}, + {Aliases: []string{"/userip"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoUserIP(ctx, args), nil }}, {Aliases: []string{"/udeviceid"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraAuditDevices(ctx, "udeviceid", args), nil + return s.cmdMgoAuditDevices(ctx, "udeviceid", args), nil }}, {Aliases: []string{"/auditip"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraAuditDevices(ctx, "auditip", args), nil + return s.cmdMgoAuditDevices(ctx, "auditip", args), nil }}, {Aliases: []string{"/auditdevice"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraAuditDevices(ctx, "auditdevice", args), nil + return s.cmdMgoAuditDevices(ctx, "auditdevice", args), nil }}, {Aliases: []string{"/auditclient"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraAuditDevices(ctx, "auditclient", args), nil + return s.cmdMgoAuditDevices(ctx, "auditclient", args), nil }}, - {Aliases: []string{"/renewall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraRenewAll(ctx, args), nil }}, - {Aliases: []string{"/callall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraCallAll(ctx, channel, args), nil }}, - {Aliases: []string{"/syncunbound"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraSyncUnbound(ctx, args), nil }}, + {Aliases: []string{"/renewall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoRenewAll(ctx, args), nil }}, + {Aliases: []string{"/callall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoCallAll(ctx, channel, args), nil }}, + {Aliases: []string{"/syncunbound"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoSyncUnbound(ctx, args), nil }}, {Aliases: []string{"/syncgroupm"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraSyncGroup(ctx, channel, args), nil + return s.cmdMgoSyncGroup(ctx, channel, args), nil }}, {Aliases: []string{"/kick_not_emby"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraUnsupported("群内无号用户清理", "/syncgroupm 可检查已绑定账号是否仍在群内;Telegram Bot API 无法枚举全部群成员,因此不能可靠找出“在群但无号”的用户。"), nil + return s.cmdMgoUnsupported("群内无号用户清理", "/syncgroupm 可检查已绑定账号是否仍在群内;Telegram Bot API 无法枚举全部群成员,因此不能可靠找出“在群但无号”的用户。"), nil }}, - {Aliases: []string{"/scan_embyname"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraScanNames(ctx), nil }}, - {Aliases: []string{"/check_ex"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraCheckExpired(ctx, args), nil }}, + {Aliases: []string{"/scan_embyname"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoScanNames(ctx), nil }}, + {Aliases: []string{"/check_ex"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoCheckExpired(ctx, args), nil }}, {Aliases: []string{"/deleted", "/low_activity"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdCleanup(ctx, []string{"run"}), nil }}, - {Aliases: []string{"/uranks"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraRanks(ctx, 0, true), nil }}, + {Aliases: []string{"/uranks"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoRanks(ctx, 0, true), nil }}, {Aliases: []string{"/days_ranks"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraRanks(ctx, 24*time.Hour, false), nil + return s.cmdMgoRanks(ctx, 24*time.Hour, false), nil }}, {Aliases: []string{"/week_ranks"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraRanks(ctx, 7*24*time.Hour, false), nil + return s.cmdMgoRanks(ctx, 7*24*time.Hour, false), nil }}, - {Aliases: []string{"/embyadmin"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraAdminRole(ctx, args), nil }}, - {Aliases: []string{"/unbanall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraBanAll(ctx, true, args), nil }}, - {Aliases: []string{"/banall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraBanAll(ctx, false, args), nil }}, + {Aliases: []string{"/embyadmin"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoAdminRole(ctx, args), nil }}, + {Aliases: []string{"/unbanall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoBanAll(ctx, true, args), nil }}, + {Aliases: []string{"/banall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoBanAll(ctx, false, args), nil }}, {Aliases: []string{"/embylibs_unblockall", "/extraembylibs_unblockall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraMediaAccessAll(ctx, true), nil + return s.cmdMgoMediaAccessAll(ctx, true), nil }}, {Aliases: []string{"/embylibs_blockall", "/extraembylibs_blockall"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraMediaAccessAll(ctx, false), nil + return s.cmdMgoMediaAccessAll(ctx, false), nil }}, {Aliases: []string{"/proadmin"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraBotAdmin(ctx, channel, args, true), nil + return s.cmdMgoBotAdmin(ctx, channel, args, true), nil }}, {Aliases: []string{"/revadmin"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraBotAdmin(ctx, channel, args, false), nil + return s.cmdMgoBotAdmin(ctx, channel, args, false), nil }}, - {Aliases: []string{"/backup_db"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraBackupDB(ctx), nil }}, - {Aliases: []string{"/restore_from_db"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSakuraRestoreDB(ctx, args), nil }}, + {Aliases: []string{"/backup_db"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoBackupDB(ctx), nil }}, + {Aliases: []string{"/restore_from_db"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdMgoRestoreDB(ctx, args), nil }}, {Aliases: []string{"/prouser"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraProtectedUser(ctx, args, true), nil + return s.cmdMgoProtectedUser(ctx, args, true), nil }}, {Aliases: []string{"/revuser"}, AdminOnly: true, AdminOnlyText: adminOnly, Handle: func(args []string) (telegramCommandReply, error) { - return s.cmdSakuraProtectedUser(ctx, args, false), nil + return s.cmdMgoProtectedUser(ctx, args, false), nil }}, } } diff --git a/internal/service/telegram_sakura.go b/internal/service/telegram_mgo_compat.go similarity index 90% rename from internal/service/telegram_sakura.go rename to internal/service/telegram_mgo_compat.go index 426c4b1..a4f91ce 100644 --- a/internal/service/telegram_sakura.go +++ b/internal/service/telegram_mgo_compat.go @@ -12,7 +12,7 @@ import ( "github.com/ShukeBta/MediaStationGo/internal/model" ) -func (s *TelegramBotService) cmdSakuraCreateUser(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoCreateUser(ctx context.Context, args []string) telegramCommandReply { if len(args) < 2 { return telegramCommandReply{Text: "用法:/ucr 用户名 密码 [天数],天数 0 表示永久。"} } @@ -37,11 +37,11 @@ func (s *TelegramBotService) cmdSakuraCreateUser(ctx context.Context, args []str return telegramCommandReply{Text: fmt.Sprintf("已创建用户:%s\n到期:%s", user.Username, formatExpiry(s.userExpiry(ctx, user.ID)))} } -func (s *TelegramBotService) cmdSakuraUserInfo(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoUserInfo(ctx context.Context, args []string) telegramCommandReply { if len(args) == 0 { return telegramCommandReply{Text: "用法:/uinfo 用户名"} } - user := s.findSakuraUser(ctx, args[0]) + user := s.findMgoBotUser(ctx, args[0]) if user == nil { return telegramCommandReply{Text: "未找到用户。"} } @@ -62,11 +62,11 @@ func (s *TelegramBotService) cmdSakuraUserInfo(ctx context.Context, args []strin )} } -func (s *TelegramBotService) cmdSakuraDeleteUser(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoDeleteUser(ctx context.Context, args []string) telegramCommandReply { if len(args) < 2 || !strings.EqualFold(args[len(args)-1], "confirm") { return telegramCommandReply{Text: "删除用户需要确认:/rmemby 用户名 confirm 或 /urm 用户名 confirm"} } - user := s.findSakuraUser(ctx, args[0]) + user := s.findMgoBotUser(ctx, args[0]) if user == nil { return telegramCommandReply{Text: "未找到用户。"} } @@ -80,7 +80,7 @@ func (s *TelegramBotService) cmdSakuraDeleteUser(ctx context.Context, args []str return telegramCommandReply{Text: fmt.Sprintf("已删除用户 %s。", user.Username)} } -func (s *TelegramBotService) cmdSakuraOnlyRemoveRecord(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoOnlyRemoveRecord(ctx context.Context, args []string) telegramCommandReply { if len(args) == 0 { return telegramCommandReply{Text: "用法:/only_rm_record tg:123456 或 /only_rm_record 用户名,只删除 Telegram 绑定记录。"} } @@ -96,7 +96,7 @@ func (s *TelegramBotService) cmdSakuraOnlyRemoveRecord(ctx context.Context, args return telegramCommandReply{Text: "删除绑定失败:" + err.Error()} } } else { - user := s.findSakuraUser(ctx, target) + user := s.findMgoBotUser(ctx, target) if user == nil { return telegramCommandReply{Text: "未找到用户。"} } @@ -109,11 +109,11 @@ func (s *TelegramBotService) cmdSakuraOnlyRemoveRecord(ctx context.Context, args return telegramCommandReply{Text: fmt.Sprintf("已删除 Telegram 绑定记录:%d 条。", removed)} } -func (s *TelegramBotService) cmdSakuraUserIP(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoUserIP(ctx context.Context, args []string) telegramCommandReply { if len(args) == 0 { return telegramCommandReply{Text: "用法:/userip 用户名"} } - user := s.findSakuraUser(ctx, args[0]) + user := s.findMgoBotUser(ctx, args[0]) if user == nil { return telegramCommandReply{Text: "未找到用户。"} } @@ -134,7 +134,7 @@ func (s *TelegramBotService) cmdSakuraUserIP(ctx context.Context, args []string) return telegramCommandReply{Text: "" + user.Username + " 的设备/IP\n\n" + strings.Join(out, "\n") + ""} } -func (s *TelegramBotService) cmdSakuraAuditDevices(ctx context.Context, mode string, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoAuditDevices(ctx context.Context, mode string, args []string) telegramCommandReply { if len(args) == 0 { return telegramCommandReply{Text: fmt.Sprintf("用法:/%s 关键词", mode)} } @@ -175,7 +175,7 @@ func (s *TelegramBotService) cmdSakuraAuditDevices(ctx context.Context, mode str return telegramCommandReply{Text: "审计结果\n\n" + strings.Join(out, "\n") + ""} } -func (s *TelegramBotService) cmdSakuraRenewAll(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoRenewAll(ctx context.Context, args []string) telegramCommandReply { if len(args) < 2 || !strings.EqualFold(args[len(args)-1], "confirm") { return telegramCommandReply{Text: "批量续期需要确认:/renewall 天数 confirm"} } @@ -199,7 +199,7 @@ func (s *TelegramBotService) cmdSakuraRenewAll(ctx context.Context, args []strin return telegramCommandReply{Text: fmt.Sprintf("批量续期完成:%d 个普通用户。", count)} } -func (s *TelegramBotService) cmdSakuraBanAll(ctx context.Context, active bool, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoBanAll(ctx context.Context, active bool, args []string) telegramCommandReply { if len(args) == 0 || !strings.EqualFold(args[len(args)-1], "confirm") { action := "banall" if active { @@ -235,7 +235,7 @@ func (s *TelegramBotService) cmdSakuraBanAll(ctx context.Context, active bool, a return telegramCommandReply{Text: fmt.Sprintf("已禁用普通用户:%d 个。", count)} } -func (s *TelegramBotService) cmdSakuraCallAll(ctx context.Context, channel *model.NotifyChannel, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoCallAll(ctx context.Context, channel *model.NotifyChannel, args []string) telegramCommandReply { message := strings.TrimSpace(strings.Join(args, " ")) if message == "" { return telegramCommandReply{Text: "用法:/callall 消息内容"} @@ -259,7 +259,7 @@ func (s *TelegramBotService) cmdSakuraCallAll(ctx context.Context, channel *mode return telegramCommandReply{Text: fmt.Sprintf("群发完成:成功发送 %d 个绑定用户。", sent)} } -func (s *TelegramBotService) cmdSakuraSyncUnbound(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoSyncUnbound(ctx context.Context, args []string) telegramCommandReply { var users []model.User if err := s.repo.DB.WithContext(ctx). Where("role <> ?", "admin"). @@ -293,7 +293,7 @@ func (s *TelegramBotService) cmdSakuraSyncUnbound(ctx context.Context, args []st return telegramCommandReply{Text: fmt.Sprintf("未绑定 Bot 的普通用户:%d 个。\n%s\n\n如需删除:/syncunbound delete confirm", len(users), telegramInlineCodeList(names))} } -func (s *TelegramBotService) cmdSakuraCheckExpired(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoCheckExpired(ctx context.Context, args []string) telegramCommandReply { now := time.Now() var users []model.User if err := s.repo.DB.WithContext(ctx).Where("expired_at IS NOT NULL AND expired_at < ?", now).Order("expired_at asc").Find(&users).Error; err != nil { @@ -324,7 +324,7 @@ func (s *TelegramBotService) cmdSakuraCheckExpired(ctx context.Context, args []s return telegramCommandReply{Text: fmt.Sprintf("过期用户:%d 个。\n%s\n\n如需禁用:/check_ex disable confirm", len(users), telegramInlineCodeList(lines))} } -func (s *TelegramBotService) cmdSakuraScanNames(ctx context.Context) telegramCommandReply { +func (s *TelegramBotService) cmdMgoScanNames(ctx context.Context) telegramCommandReply { var rows []struct { Username string Count int64 @@ -344,7 +344,7 @@ func (s *TelegramBotService) cmdSakuraScanNames(ctx context.Context) telegramCom return telegramCommandReply{Text: "同名用户记录\n" + telegramInlineCodeList(out)} } -func (s *TelegramBotService) cmdSakuraRanks(ctx context.Context, window time.Duration, byDuration bool) telegramCommandReply { +func (s *TelegramBotService) cmdMgoRanks(ctx context.Context, window time.Duration, byDuration bool) telegramCommandReply { since := time.Now().Add(-window) title := "播放次数排行" selectExpr := "COUNT(*) AS score" @@ -382,11 +382,11 @@ func (s *TelegramBotService) cmdSakuraRanks(ctx context.Context, window time.Dur return telegramCommandReply{Text: "" + title + "\n\n" + strings.Join(out, "\n") + ""} } -func (s *TelegramBotService) cmdSakuraAdminRole(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoAdminRole(ctx context.Context, args []string) telegramCommandReply { if len(args) < 2 { return telegramCommandReply{Text: "用法:/embyadmin 用户名 on|off"} } - user := s.findSakuraUser(ctx, args[0]) + user := s.findMgoBotUser(ctx, args[0]) if user == nil { return telegramCommandReply{Text: "未找到用户。"} } @@ -409,7 +409,7 @@ func (s *TelegramBotService) cmdSakuraAdminRole(ctx context.Context, args []stri return telegramCommandReply{Text: fmt.Sprintf("已将 %s 角色设置为 %s。", user.Username, role)} } -func (s *TelegramBotService) cmdSakuraMediaAccessAll(ctx context.Context, allow bool) telegramCommandReply { +func (s *TelegramBotService) cmdMgoMediaAccessAll(ctx context.Context, allow bool) telegramCommandReply { users, err := s.repo.User.List(ctx) if err != nil { return telegramCommandReply{Text: "读取用户失败:" + err.Error()} @@ -443,7 +443,7 @@ func (s *TelegramBotService) cmdSakuraMediaAccessAll(ctx context.Context, allow return telegramCommandReply{Text: fmt.Sprintf("已为普通用户%s媒体播放权限:%d 个。", state, updated)} } -func (s *TelegramBotService) cmdSakuraBotAdmin(ctx context.Context, channel *model.NotifyChannel, args []string, add bool) telegramCommandReply { +func (s *TelegramBotService) cmdMgoBotAdmin(ctx context.Context, channel *model.NotifyChannel, args []string, add bool) telegramCommandReply { if channel == nil { return telegramCommandReply{Text: "Telegram 渠道不存在。"} } @@ -489,11 +489,11 @@ func (s *TelegramBotService) cmdSakuraBotAdmin(ctx context.Context, channel *mod return telegramCommandReply{Text: "已移除 Bot 管理员:" + tgID + ""} } -func (s *TelegramBotService) cmdSakuraProtectedUser(ctx context.Context, args []string, protect bool) telegramCommandReply { +func (s *TelegramBotService) cmdMgoProtectedUser(ctx context.Context, args []string, protect bool) telegramCommandReply { if len(args) == 0 || strings.EqualFold(args[0], "list") { - return s.cmdSakuraProtectedUserList(ctx) + return s.cmdMgoProtectedUserList(ctx) } - user := s.findSakuraUser(ctx, args[0]) + user := s.findMgoBotUser(ctx, args[0]) if user == nil { return telegramCommandReply{Text: "未找到用户。"} } @@ -512,7 +512,7 @@ func (s *TelegramBotService) cmdSakuraProtectedUser(ctx context.Context, args [] return telegramCommandReply{Text: fmt.Sprintf("已移出保护名单:%s。", user.Username)} } -func (s *TelegramBotService) cmdSakuraProtectedUserList(ctx context.Context) telegramCommandReply { +func (s *TelegramBotService) cmdMgoProtectedUserList(ctx context.Context) telegramCommandReply { ids := ProtectedUserIDSet(ctx, s.repo) if len(ids) == 0 { return telegramCommandReply{Text: "保护名单为空。管理员和默认管理员始终自动保护。"} @@ -529,7 +529,7 @@ func (s *TelegramBotService) cmdSakuraProtectedUserList(ctx context.Context) tel return telegramCommandReply{Text: fmt.Sprintf("保护名单:%d 个。\n%s", len(names), telegramInlineCodeList(names))} } -func (s *TelegramBotService) cmdSakuraBackupDB(ctx context.Context) telegramCommandReply { +func (s *TelegramBotService) cmdMgoBackupDB(ctx context.Context) telegramCommandReply { if s.backup == nil { return telegramCommandReply{Text: "备份服务暂不可用。"} } @@ -540,7 +540,7 @@ func (s *TelegramBotService) cmdSakuraBackupDB(ctx context.Context) telegramComm return telegramCommandReply{Text: fmt.Sprintf("数据库备份完成:%s\n大小:%d bytes", info.Filename, info.Size)} } -func (s *TelegramBotService) cmdSakuraRestoreDB(ctx context.Context, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoRestoreDB(ctx context.Context, args []string) telegramCommandReply { if s.backup == nil { return telegramCommandReply{Text: "备份服务暂不可用。"} } @@ -571,7 +571,7 @@ func (s *TelegramBotService) cmdSakuraRestoreDB(ctx context.Context, args []stri return telegramCommandReply{Text: "数据库已从备份恢复,请重启 MediaStationGo 后生效。"} } -func (s *TelegramBotService) cmdSakuraSyncGroup(ctx context.Context, channel *model.NotifyChannel, args []string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoSyncGroup(ctx context.Context, channel *model.NotifyChannel, args []string) telegramCommandReply { chatIDs := s.telegramMembershipChatIDs(channel) if len(chatIDs) == 0 { return telegramCommandReply{Text: "未配置可校验成员的群组/频道 ID。请在 Telegram 通知渠道设置 group_chat_id 或 channel_chat_id。"} @@ -652,7 +652,7 @@ func (s *TelegramBotService) telegramMembershipChatIDs(channel *model.NotifyChan return out } -func (s *TelegramBotService) cmdSakuraUnsupported(name, replacement string) telegramCommandReply { +func (s *TelegramBotService) cmdMgoUnsupported(name, replacement string) telegramCommandReply { text := fmt.Sprintf("%s 已识别,但当前 Telegram Bot API 无法完整复刻该行为。", name) if replacement != "" { text += "\n请使用:" + replacement @@ -660,7 +660,7 @@ func (s *TelegramBotService) cmdSakuraUnsupported(name, replacement string) tele return telegramCommandReply{Text: text} } -func (s *TelegramBotService) findSakuraUser(ctx context.Context, target string) *model.User { +func (s *TelegramBotService) findMgoBotUser(ctx context.Context, target string) *model.User { target = strings.TrimSpace(strings.TrimPrefix(target, "@")) if target == "" { return nil diff --git a/internal/service/telegram_sakura_test.go b/internal/service/telegram_mgo_compat_test.go similarity index 97% rename from internal/service/telegram_sakura_test.go rename to internal/service/telegram_mgo_compat_test.go index 26c2923..bf3abee 100644 --- a/internal/service/telegram_sakura_test.go +++ b/internal/service/telegram_mgo_compat_test.go @@ -11,7 +11,7 @@ import ( "github.com/ShukeBta/MediaStationGo/internal/model" ) -func TestSakuraUserManagementAndAuditCommands(t *testing.T) { +func TestMgoBotUserManagementAndAuditCommands(t *testing.T) { ctx := t.Context() repos, bot := newBotTestService(t) if err := repos.User.Create(ctx, &model.User{Username: "root", PasswordHash: "x", Role: "admin", IsActive: true}); err != nil { @@ -66,7 +66,7 @@ func TestSakuraUserManagementAndAuditCommands(t *testing.T) { } } -func TestSakuraBatchAndPermissionCommands(t *testing.T) { +func TestMgoBotBatchAndPermissionCommands(t *testing.T) { ctx := t.Context() repos, bot := newBotTestService(t) channel := &model.NotifyChannel{Name: "Telegram", Type: "telegram", Enabled: true, Config: `{"admin_user_ids":"9501"}`} @@ -135,7 +135,7 @@ func TestSakuraBatchAndPermissionCommands(t *testing.T) { } } -func TestSakuraSyncExpiryAndBotAdminCommands(t *testing.T) { +func TestMgoBotSyncExpiryAndBotAdminCommands(t *testing.T) { ctx := t.Context() repos, bot := newBotTestService(t) channel := &model.NotifyChannel{Name: "Telegram", Type: "telegram", Enabled: true, Config: `{"admin_user_ids":"9601"}`} @@ -176,7 +176,7 @@ func TestSakuraSyncExpiryAndBotAdminCommands(t *testing.T) { } } -func TestSakuraProtectedUsersAndBackupCommands(t *testing.T) { +func TestMgoBotProtectedUsersAndBackupCommands(t *testing.T) { ctx := t.Context() repos, bot := newBotTestService(t) cfg := &config.Config{} @@ -245,7 +245,7 @@ func TestSakuraProtectedUsersAndBackupCommands(t *testing.T) { } } -func TestSakuraAliasesAndSyncGroupGuards(t *testing.T) { +func TestMgoBotAliasesAndSyncGroupGuards(t *testing.T) { ctx := t.Context() repos, bot := newBotTestService(t) if err := repos.User.Create(ctx, &model.User{Username: "root", PasswordHash: "x", Role: "admin", IsActive: true}); err != nil {