mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 04:26:38 +08:00
docs: simplify deployment docs and restrict telegram group commands
This commit is contained in:
@@ -96,14 +96,20 @@ func TestTelegramTargetChatIDsUsesLegacyPrivateChatID(t *testing.T) {
|
||||
|
||||
func TestRegisterTelegramBotCommands(t *testing.T) {
|
||||
var gotPath string
|
||||
var payload struct {
|
||||
var payloads []struct {
|
||||
Commands []telegramBotCommand `json:"commands"`
|
||||
Scope map[string]any `json:"scope"`
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotPath = r.URL.Path
|
||||
var payload struct {
|
||||
Commands []telegramBotCommand `json:"commands"`
|
||||
Scope map[string]any `json:"scope"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode payload: %v", err)
|
||||
}
|
||||
payloads = append(payloads, payload)
|
||||
_, _ = w.Write([]byte(`{"ok":true}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
@@ -118,9 +124,55 @@ func TestRegisterTelegramBotCommands(t *testing.T) {
|
||||
if gotPath != "/bot123456:ABC/setMyCommands" {
|
||||
t.Fatalf("path = %q", gotPath)
|
||||
}
|
||||
if len(payload.Commands) == 0 || payload.Commands[0].Command != "start" {
|
||||
t.Fatalf("commands not registered: %#v", payload.Commands)
|
||||
if len(payloads) < 3 {
|
||||
t.Fatalf("expected default/private/group command registrations, got %d", len(payloads))
|
||||
}
|
||||
if len(payloads[0].Commands) == 0 || payloads[0].Commands[0].Command != "start" {
|
||||
t.Fatalf("commands not registered: %#v", payloads[0].Commands)
|
||||
}
|
||||
var groupCommands []telegramBotCommand
|
||||
for _, payload := range payloads {
|
||||
if payload.Scope["type"] == "all_group_chats" {
|
||||
groupCommands = payload.Commands
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(groupCommands) == 0 {
|
||||
t.Fatal("group command scope was not registered")
|
||||
}
|
||||
for _, command := range groupCommands {
|
||||
if command.Command == "users" || command.Command == "status" || command.Command == "cleanup" || command.Command == "register" || command.Command == "redeem" {
|
||||
t.Fatalf("group commands must not expose private/admin command %q", command.Command)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTelegramCommandMenusSeparateGroupAndAdminCommands(t *testing.T) {
|
||||
groupNames := telegramCommandNames(telegramGroupBotCommandMenu())
|
||||
for _, forbidden := range []string{"status", "search", "downloads", "stats", "users", "cleanup", "cleanup_rule", "register", "redeem"} {
|
||||
if groupNames[forbidden] {
|
||||
t.Fatalf("group menu should not expose %s", forbidden)
|
||||
}
|
||||
}
|
||||
for _, required := range []string{"start", "menu", "help", "account", "signin", "devices", "kick", "hideadult"} {
|
||||
if !groupNames[required] {
|
||||
t.Fatalf("group menu should include %s", required)
|
||||
}
|
||||
}
|
||||
adminNames := telegramCommandNames(telegramAdminBotCommandMenu())
|
||||
for _, required := range []string{"users", "status", "cleanup_rule"} {
|
||||
if !adminNames[required] {
|
||||
t.Fatalf("admin menu should include %s", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func telegramCommandNames(commands []telegramBotCommand) map[string]bool {
|
||||
names := make(map[string]bool, len(commands))
|
||||
for _, command := range commands {
|
||||
names[command.Command] = true
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func TestTelegramProxyCandidatesDefaultLocalFallbacks(t *testing.T) {
|
||||
|
||||
@@ -251,12 +251,31 @@ func telegramCommandName(text string) string {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func telegramIsGroupChat(chatType string) bool {
|
||||
return chatType != "" && chatType != "private"
|
||||
}
|
||||
|
||||
func telegramGroupPrivateAdminHint() string {
|
||||
return "管理命令请私聊 Bot 使用 <code>/menu</code> 或对应管理员命令,避免在群组公开管理面板。"
|
||||
}
|
||||
|
||||
func telegramGroupPrivateUserHint(action string) string {
|
||||
action = strings.TrimSpace(action)
|
||||
if action == "" {
|
||||
action = "此操作"
|
||||
}
|
||||
return action + "包含账号凭据或敏感信息,请私聊 Bot 操作;群组内仅开放账号状态、签到、设备与成人目录开关。"
|
||||
}
|
||||
|
||||
// cmdStart 处理 /start 命令。
|
||||
func (s *TelegramBotService) cmdStart(ctx context.Context, msg *TelegramMessage, args []string) telegramCommandReply {
|
||||
name := msg.From.FirstName
|
||||
if msg.From.Username != "" {
|
||||
name = "@" + msg.From.Username
|
||||
}
|
||||
if telegramIsGroupChat(msg.Chat.Type) && len(args) > 0 {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("绑定账号")}
|
||||
}
|
||||
if len(args) == 0 {
|
||||
if binding := s.telegramBinding(ctx, msg.From.ID); binding != nil {
|
||||
user, _ := s.repo.User.FindByID(ctx, binding.UserID)
|
||||
@@ -420,6 +439,21 @@ func (s *TelegramBotService) cmdRegistrationToggle(ctx context.Context, args []s
|
||||
// cmdHelp 处理 /help 命令。
|
||||
func (s *TelegramBotService) cmdHelp(ctx context.Context, msg *TelegramMessage) string {
|
||||
channel := s.findChannelForMessage(ctx, msg)
|
||||
if telegramIsGroupChat(msg.Chat.Type) {
|
||||
adminHint := ""
|
||||
if s.telegramUserIsAdmin(ctx, channel, msg.From.ID) {
|
||||
adminHint = "\n\n管理员命令和管理面板请私聊 Bot 使用,避免在群组公开。"
|
||||
}
|
||||
return "<b>MediaStationGo 群组可用命令</b>\n\n" +
|
||||
"<b>/menu</b> — 打开群组自助菜单\n" +
|
||||
"<b>/account</b> — 查看账号状态\n" +
|
||||
"<b>/signin</b> — 签到\n" +
|
||||
"<b>/devices</b> — 查看登录设备\n" +
|
||||
"<b>/kick all|编号</b> — 踢下线设备\n" +
|
||||
"<b>/hideadult on|off</b> — 隐藏或显示成人目录\n\n" +
|
||||
"绑定、注册、兑换、改名、改密等包含敏感信息的操作请私聊 Bot。" +
|
||||
adminHint
|
||||
}
|
||||
if !s.telegramUserIsAdmin(ctx, channel, msg.From.ID) {
|
||||
register := ""
|
||||
if s.openRegEnabled(ctx) {
|
||||
|
||||
@@ -134,6 +134,74 @@ func TestTelegramRegisterRespectsAdminToggle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTelegramGroupHidesAdminPanelFromRegularUsers(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
_, bot := newBotTestService(t)
|
||||
channel := &model.NotifyChannel{Name: "Telegram", Type: "telegram", Enabled: true, Config: `{"group_chat_id":"-100123","admin_user_ids":"9001"}`}
|
||||
msg := &TelegramMessage{
|
||||
From: TelegramUser{ID: 9002, Username: "viewer", FirstName: "Viewer"},
|
||||
Chat: TelegramChat{ID: -100123, Type: "supergroup"},
|
||||
}
|
||||
|
||||
menu := bot.mainMenu(ctx, channel, msg)
|
||||
if strings.Contains(menu.Text, "管理员") || telegramReplyHasButtonPrefix(menu, "adm_") {
|
||||
t.Fatalf("regular group user must not see admin panel: text=%q buttons=%#v", menu.Text, menu.Buttons)
|
||||
}
|
||||
|
||||
reply, err := bot.executeCommand(ctx, channel, msg, "/users")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reply.Text != "" || len(reply.Buttons) != 0 {
|
||||
t.Fatalf("regular group user admin command should be ignored, got %#v", reply)
|
||||
}
|
||||
|
||||
reply, err = bot.executeCommand(ctx, channel, msg, "/start viewer secret-pass")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(reply.Text, "请私聊 Bot") {
|
||||
t.Fatalf("group credential command should point to private chat, got %q", reply.Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTelegramGroupAdminMenuDoesNotExposeButtonsInGroup(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
_, bot := newBotTestService(t)
|
||||
channel := &model.NotifyChannel{Name: "Telegram", Type: "telegram", Enabled: true, Config: `{"group_chat_id":"-100123","admin_user_ids":"9001"}`}
|
||||
msg := &TelegramMessage{
|
||||
From: TelegramUser{ID: 9001, Username: "admin", FirstName: "Admin"},
|
||||
Chat: TelegramChat{ID: -100123, Type: "group"},
|
||||
}
|
||||
|
||||
menu := bot.mainMenu(ctx, channel, msg)
|
||||
if telegramReplyHasButtonPrefix(menu, "adm_") {
|
||||
t.Fatalf("admin group menu must not expose admin buttons publicly: %#v", menu.Buttons)
|
||||
}
|
||||
if !strings.Contains(menu.Text, "请私聊 Bot") {
|
||||
t.Fatalf("admin group menu should tell admins to use private chat, got %q", menu.Text)
|
||||
}
|
||||
|
||||
reply, handled := bot.handleMenuCallback(ctx, channel, msg, "adm_users")
|
||||
if !handled {
|
||||
t.Fatal("admin callback should be handled")
|
||||
}
|
||||
if !strings.Contains(reply.Text, "请私聊 Bot") || telegramReplyHasButtonPrefix(reply, "adm_") {
|
||||
t.Fatalf("group admin callback should not render admin panel publicly: %#v", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func telegramReplyHasButtonPrefix(reply telegramCommandReply, prefix string) bool {
|
||||
for _, row := range reply.Buttons {
|
||||
for _, button := range row {
|
||||
if strings.HasPrefix(button.Data, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestTelegramStartClearsStaleUserBinding(t *testing.T) {
|
||||
repos, auth, _, _ := newAuthTestServices(t)
|
||||
if err := repos.DB.Create(&model.TelegramBinding{
|
||||
|
||||
@@ -16,31 +16,32 @@ type telegramCommandDefinition struct {
|
||||
Aliases []string
|
||||
AdminOnly bool
|
||||
AdminOnlyText string
|
||||
GroupAllowed bool
|
||||
Handle telegramCommandHandler
|
||||
}
|
||||
|
||||
func (s *TelegramBotService) telegramCommandDefinitions(ctx context.Context, channel *model.NotifyChannel, msg *TelegramMessage) []telegramCommandDefinition {
|
||||
adminOnly := "此命令仅管理员可用。"
|
||||
return []telegramCommandDefinition{
|
||||
{Aliases: []string{"/start"}, Handle: func(args []string) (telegramCommandReply, error) {
|
||||
{Aliases: []string{"/start"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) {
|
||||
if len(args) == 0 {
|
||||
return s.mainMenu(ctx, channel, msg), nil
|
||||
}
|
||||
return s.cmdStart(ctx, msg, args), nil
|
||||
}},
|
||||
{Aliases: []string{"/menu"}, Handle: func(args []string) (telegramCommandReply, error) { return s.mainMenu(ctx, channel, msg), nil }},
|
||||
{Aliases: []string{"/cancel"}, Handle: func(args []string) (telegramCommandReply, error) {
|
||||
{Aliases: []string{"/menu"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) { return s.mainMenu(ctx, channel, msg), nil }},
|
||||
{Aliases: []string{"/cancel"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) {
|
||||
s.takePending(int64(msg.From.ID))
|
||||
return telegramCommandReply{Text: "已取消当前操作。"}, nil
|
||||
}},
|
||||
{Aliases: []string{"/help"}, Handle: func(args []string) (telegramCommandReply, error) {
|
||||
{Aliases: []string{"/help"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) {
|
||||
return telegramCommandReply{Text: s.cmdHelp(ctx, msg)}, nil
|
||||
}},
|
||||
{Aliases: []string{"/hideadult", "/hide_adult", "/adult"}, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdHideAdult(ctx, msg, args), nil }},
|
||||
{Aliases: []string{"/account", "/me"}, Handle: func(args []string) (telegramCommandReply, error) { return s.replyAccount(ctx, msg), nil }},
|
||||
{Aliases: []string{"/signin", "/checkin"}, Handle: func(args []string) (telegramCommandReply, error) { return s.replySignIn(ctx, msg), nil }},
|
||||
{Aliases: []string{"/devices"}, Handle: func(args []string) (telegramCommandReply, error) { return s.replyDevices(ctx, msg), nil }},
|
||||
{Aliases: []string{"/kick"}, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdKick(ctx, msg, args), nil }},
|
||||
{Aliases: []string{"/hideadult", "/hide_adult", "/adult"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdHideAdult(ctx, msg, args), nil }},
|
||||
{Aliases: []string{"/account", "/me"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) { return s.replyAccount(ctx, msg), nil }},
|
||||
{Aliases: []string{"/signin", "/checkin"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) { return s.replySignIn(ctx, msg), nil }},
|
||||
{Aliases: []string{"/devices"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) { return s.replyDevices(ctx, msg), nil }},
|
||||
{Aliases: []string{"/kick"}, GroupAllowed: true, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdKick(ctx, msg, args), nil }},
|
||||
{Aliases: []string{"/setname", "/rename"}, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSetName(ctx, msg, args), nil }},
|
||||
{Aliases: []string{"/setpass", "/passwd", "/password"}, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdSetPass(ctx, msg, args), nil }},
|
||||
{Aliases: []string{"/redeem"}, Handle: func(args []string) (telegramCommandReply, error) { return s.cmdRedeem(ctx, channel, msg, args), nil }},
|
||||
@@ -102,6 +103,12 @@ func (s *TelegramBotService) executeCommand(ctx context.Context, channel *model.
|
||||
if !ok {
|
||||
return telegramCommandReply{Text: fmt.Sprintf("未知命令: %s\n\n输入 /help 查看可用命令列表。", cmd)}, nil
|
||||
}
|
||||
if telegramIsGroupChat(msg.Chat.Type) && !def.GroupAllowed {
|
||||
if def.AdminOnly && s.telegramUserIsAdmin(ctx, channel, msg.From.ID) {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateAdminHint()}, nil
|
||||
}
|
||||
return telegramCommandReply{}, nil
|
||||
}
|
||||
if def.AdminOnly && !s.telegramUserIsAdmin(ctx, channel, msg.From.ID) {
|
||||
return telegramCommandReply{Text: def.AdminOnlyText}, nil
|
||||
}
|
||||
@@ -133,6 +140,10 @@ type telegramBotCommand struct {
|
||||
}
|
||||
|
||||
func telegramBotCommandMenu() []telegramBotCommand {
|
||||
return telegramPrivateBotCommandMenu()
|
||||
}
|
||||
|
||||
func telegramPrivateBotCommandMenu() []telegramBotCommand {
|
||||
return []telegramBotCommand{
|
||||
{Command: "start", Description: "绑定账号或打开主菜单"},
|
||||
{Command: "menu", Description: "打开功能菜单"},
|
||||
@@ -144,22 +155,62 @@ func telegramBotCommandMenu() []telegramBotCommand {
|
||||
{Command: "hideadult", Description: "隐藏/显示成人媒体库"},
|
||||
{Command: "redeem", Description: "兑换注册码或续期码"},
|
||||
{Command: "register", Description: "注册新账号"},
|
||||
{Command: "status", Description: "系统运行状态(管理员)"},
|
||||
{Command: "search", Description: "搜索媒体库(管理员)"},
|
||||
{Command: "downloads", Description: "下载列表(管理员)"},
|
||||
{Command: "stats", Description: "媒体库统计(管理员)"},
|
||||
{Command: "users", Description: "用户管理(管理员)"},
|
||||
{Command: "cleanup", Description: "删号规则巡检(管理员)"},
|
||||
{Command: "cleanup_rule", Description: "保号规则管理(管理员)"},
|
||||
}
|
||||
}
|
||||
|
||||
func telegramGroupBotCommandMenu() []telegramBotCommand {
|
||||
return []telegramBotCommand{
|
||||
{Command: "start", Description: "打开群组自助菜单"},
|
||||
{Command: "menu", Description: "打开群组自助菜单"},
|
||||
{Command: "help", Description: "查看群组可用命令"},
|
||||
{Command: "account", Description: "查看账号状态"},
|
||||
{Command: "signin", Description: "签到"},
|
||||
{Command: "devices", Description: "查看登录设备"},
|
||||
{Command: "kick", Description: "踢下线设备"},
|
||||
{Command: "hideadult", Description: "隐藏/显示成人媒体库"},
|
||||
}
|
||||
}
|
||||
|
||||
func telegramAdminBotCommandMenu() []telegramBotCommand {
|
||||
commands := append([]telegramBotCommand{}, telegramPrivateBotCommandMenu()...)
|
||||
commands = append(commands,
|
||||
telegramBotCommand{Command: "status", Description: "系统运行状态(管理员)"},
|
||||
telegramBotCommand{Command: "search", Description: "搜索媒体库(管理员)"},
|
||||
telegramBotCommand{Command: "downloads", Description: "下载列表(管理员)"},
|
||||
telegramBotCommand{Command: "stats", Description: "媒体库统计(管理员)"},
|
||||
telegramBotCommand{Command: "users", Description: "用户管理(管理员)"},
|
||||
telegramBotCommand{Command: "cleanup", Description: "删号规则巡检(管理员)"},
|
||||
telegramBotCommand{Command: "cleanup_rule", Description: "保号规则管理(管理员)"},
|
||||
)
|
||||
return commands
|
||||
}
|
||||
|
||||
func registerTelegramBotCommands(ctx context.Context, cfg map[string]string) error {
|
||||
if strings.TrimSpace(cfg["bot_token"]) == "" {
|
||||
return nil
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"commands": telegramBotCommandMenu(),
|
||||
normalizeTelegramConfig(cfg)
|
||||
if err := telegramSetBotCommands(ctx, cfg, telegramPrivateBotCommandMenu(), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := telegramSetBotCommands(ctx, cfg, telegramPrivateBotCommandMenu(), map[string]interface{}{"type": "all_private_chats"}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := telegramSetBotCommands(ctx, cfg, telegramGroupBotCommandMenu(), map[string]interface{}{"type": "all_group_chats"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
adminCommands := telegramAdminBotCommandMenu()
|
||||
for _, adminID := range telegramConfiguredUserIDs(cfg["admin_user_ids"]) {
|
||||
_ = telegramSetBotCommands(ctx, cfg, adminCommands, map[string]interface{}{"type": "chat", "chat_id": adminID})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func telegramSetBotCommands(ctx context.Context, cfg map[string]string, commands []telegramBotCommand, scope map[string]interface{}) error {
|
||||
payload := map[string]interface{}{"commands": commands}
|
||||
if scope != nil {
|
||||
payload["scope"] = scope
|
||||
}
|
||||
return telegramPostJSON(ctx, cfg, "setMyCommands", payload, 15*time.Second)
|
||||
}
|
||||
|
||||
@@ -55,11 +55,36 @@ func (s *TelegramBotService) boundUser(ctx context.Context, telegramUserID int)
|
||||
// extra management section.
|
||||
func (s *TelegramBotService) mainMenu(ctx context.Context, channel *model.NotifyChannel, msg *TelegramMessage) telegramCommandReply {
|
||||
isAdmin := s.telegramUserIsAdmin(ctx, channel, msg.From.ID)
|
||||
isGroup := telegramIsGroupChat(msg.Chat.Type)
|
||||
user := s.boundUser(ctx, msg.From.ID)
|
||||
|
||||
var rows [][]telegramInlineButton
|
||||
var header string
|
||||
|
||||
if isGroup {
|
||||
if user == nil {
|
||||
header = "<b>MediaStationGo 群组自助菜单</b>\n\n你还没有绑定媒体中心账号。绑定、注册、兑换等包含敏感信息的操作请私聊 Bot。"
|
||||
} else {
|
||||
adult := map[bool]string{true: "已隐藏", false: "已显示"}[user.HideAdult]
|
||||
header = fmt.Sprintf("<b>MediaStationGo 群组自助菜单</b>\n\n账号:<b>%s</b>\n到期:<b>%s</b>\n成人目录:<b>%s</b>",
|
||||
user.Username, formatExpiry(user.ExpiredAt), adult)
|
||||
rows = append(rows,
|
||||
[]telegramInlineButton{
|
||||
{Text: "👤 我的账号", Data: "act_account"},
|
||||
{Text: "📅 签到", Data: "act_signin"},
|
||||
},
|
||||
[]telegramInlineButton{
|
||||
{Text: "📱 我的设备", Data: "act_devices"},
|
||||
{Text: map[bool]string{true: "🔞 显示成人目录", false: "🔞 隐藏成人目录"}[user.HideAdult], Data: "adult_toggle"},
|
||||
},
|
||||
)
|
||||
}
|
||||
if isAdmin {
|
||||
header += "\n\n" + telegramGroupPrivateAdminHint()
|
||||
}
|
||||
return telegramCommandReply{Text: header, Buttons: rows}
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
header = "<b>MediaStationGo</b>\n\n你还没有绑定媒体中心账号。"
|
||||
rows = append(rows, []telegramInlineButton{{Text: "🔗 绑定账号", Data: "act_bind"}})
|
||||
@@ -109,6 +134,7 @@ func (s *TelegramBotService) mainMenu(ctx context.Context, channel *model.Notify
|
||||
// handleMenuCallback routes inline-button taps. Returns (reply, handled).
|
||||
func (s *TelegramBotService) handleMenuCallback(ctx context.Context, channel *model.NotifyChannel, msg *TelegramMessage, data string) (telegramCommandReply, bool) {
|
||||
isAdmin := s.telegramUserIsAdmin(ctx, channel, msg.From.ID)
|
||||
isGroup := telegramIsGroupChat(msg.Chat.Type)
|
||||
|
||||
switch {
|
||||
case data == "noop":
|
||||
@@ -116,17 +142,29 @@ func (s *TelegramBotService) handleMenuCallback(ctx context.Context, channel *mo
|
||||
case data == "menu_main":
|
||||
return s.mainMenu(ctx, channel, msg), true
|
||||
case data == "act_bind":
|
||||
if isGroup {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("绑定账号")}, true
|
||||
}
|
||||
return telegramCommandReply{Text: "请发送:<code>/start 用户名 密码</code> 绑定已有账号。"}, true
|
||||
case data == "act_register":
|
||||
if isGroup {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("注册账号")}, true
|
||||
}
|
||||
if !s.openRegEnabled(ctx) {
|
||||
return telegramCommandReply{Text: "注册功能未开放,请联系管理员。"}, true
|
||||
}
|
||||
s.setPending(int64(msg.From.ID), "register")
|
||||
return telegramCommandReply{Text: "请发送新账号的 <b>用户名 密码</b>(空格分隔),例如:<code>alice mypass123</code>"}, true
|
||||
case data == "act_redeem_register":
|
||||
if isGroup {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("兑换码注册")}, true
|
||||
}
|
||||
s.setPending(int64(msg.From.ID), "redeem_register")
|
||||
return telegramCommandReply{Text: "请发送你的<b>注册兑换码</b>,例如:<code>ABCD2345EFGH</code>\n(兑换后会要求设置用户名密码)"}, true
|
||||
case data == "act_redeem_renew":
|
||||
if isGroup {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("兑换码续期")}, true
|
||||
}
|
||||
s.setPending(int64(msg.From.ID), "redeem_renew")
|
||||
return telegramCommandReply{Text: "请发送你的<b>续期兑换码</b>,将为当前绑定账号续期。"}, true
|
||||
case data == "act_account":
|
||||
@@ -136,9 +174,15 @@ func (s *TelegramBotService) handleMenuCallback(ctx context.Context, channel *mo
|
||||
case data == "act_devices":
|
||||
return s.replyDevices(ctx, msg), true
|
||||
case data == "act_setname":
|
||||
if isGroup {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("修改用户名")}, true
|
||||
}
|
||||
s.setPending(int64(msg.From.ID), "setname")
|
||||
return telegramCommandReply{Text: "请发送:<code>当前密码 新用户名</code>。"}, true
|
||||
case data == "act_setpass":
|
||||
if isGroup {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateUserHint("修改密码")}, true
|
||||
}
|
||||
s.setPending(int64(msg.From.ID), "setpass")
|
||||
return telegramCommandReply{Text: "请发送:<code>当前密码 新密码</code>(新密码至少 6 位)。"}, true
|
||||
case strings.HasPrefix(data, "kick:"):
|
||||
@@ -146,6 +190,12 @@ func (s *TelegramBotService) handleMenuCallback(ctx context.Context, channel *mo
|
||||
}
|
||||
|
||||
// ── 管理员专属 ──
|
||||
if isGroup {
|
||||
if isAdmin {
|
||||
return telegramCommandReply{Text: telegramGroupPrivateAdminHint()}, true
|
||||
}
|
||||
return telegramCommandReply{}, true
|
||||
}
|
||||
if !isAdmin {
|
||||
return telegramCommandReply{Text: "此功能仅管理员可用。"}, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user