| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package telegram
- import (
- "app/commons/core"
- "fmt"
- tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
- )
- // handleCommand 处理命令
- func handleCommand(msg *tgbotapi.Message) {
- command := msg.Command()
- args := msg.CommandArguments()
- core.Log.Infof("处理命令: /%s %s", command, args)
- switch command {
- case "start":
- handleStartCommand(msg)
- case "help":
- handleHelpCommand(msg)
- case "bind":
- handleBindCommand(msg)
- case "balance":
- handleBalanceCommand(msg)
- case "records":
- handleRecordsCommand(msg)
- case "groupinfo":
- handleGroupInfoCommand(msg)
- default:
- sendTextMessage(msg.Chat.ID, "未知命令,使用 /help 查看帮助")
- }
- }
- // handleStartCommand 处理 /start 命令
- func handleStartCommand(msg *tgbotapi.Message) {
- welcomeText := `🎉 欢迎使用红包机器人!
- 🧧 功能介绍:
- • 群组定期发放红包福利
- • 支持普通红包(固定金额)
- • 支持手气红包(随机金额)
- • 查看抢红包记录
- • 查看余额
- 📝 使用步骤:
- 1️⃣ 使用 /bind 绑定平台账户
- 2️⃣ 等待群内红包发放
- 3️⃣ 点击按钮抢红包
- 💡 快速开始:
- /help - 查看帮助
- /bind - 绑定账户
- /balance - 查看余额
- /records - 查看记录
- 祝你抢红包开心!🎊`
- sendTextMessage(msg.Chat.ID, welcomeText)
- }
- // handleHelpCommand 处理 /help 命令
- func handleHelpCommand(msg *tgbotapi.Message) {
- helpText := `📖 命令帮助
- 🧧 红包相关:
- • 群组定期自动发放红包
- • 点击红包消息下方的按钮即可抢红包
- • 普通红包:每人金额相同
- • 手气红包:每人金额随机
- 👤 账户相关:
- /bind - 绑定平台账户
- /balance - 查看余额
- /records - 查看抢红包记录
- ℹ️ 其他:
- /help - 显示此帮助
- /start - 显示欢迎消息
- /groupinfo - 查看群组信息(仅限群组)
- 💡 提示:
- • 抢红包需要先绑定账户
- • 每个红包只能抢一次
- • 红包24小时内有效
- • 使用 /groupinfo 可以查看群组ID`
- sendTextMessage(msg.Chat.ID, helpText)
- }
- // handleBindCommand 处理 /bind 命令
- func handleBindCommand(msg *tgbotapi.Message) {
- // 生成绑定链接
- bindURL := generateBindURL(msg.From.ID)
- text := fmt.Sprintf(`🔗 绑定平台账户
- 请点击下方链接完成绑定:
- %s
- 💡 提示:
- • 如果未注册,请先注册账户
- • 绑定后即可抢红包
- • 绑定链接仅供本人使用`, bindURL)
- // 创建按钮
- keyboard := tgbotapi.NewInlineKeyboardMarkup(
- tgbotapi.NewInlineKeyboardRow(
- tgbotapi.NewInlineKeyboardButtonURL("🔗 立即绑定", bindURL),
- ),
- )
- sendMessageWithKeyboard(msg.Chat.ID, text, keyboard)
- }
- // handleBalanceCommand 处理 /balance 命令
- func handleBalanceCommand(msg *tgbotapi.Message) {
- // TODO: 调用 API 获取余额
- sendTextMessage(msg.Chat.ID, "💰 余额查询功能开发中...")
- }
- // handleRecordsCommand 处理 /records 命令
- func handleRecordsCommand(msg *tgbotapi.Message) {
- // TODO: 调用 API 获取抢红包记录
- sendTextMessage(msg.Chat.ID, "📊 记录查询功能开发中...")
- }
- // handleGroupInfoCommand 处理 /groupinfo 命令
- func handleGroupInfoCommand(msg *tgbotapi.Message) {
- // 检查是否在群组中
- if msg.Chat.Type != "group" && msg.Chat.Type != "supergroup" {
- sendTextMessage(msg.Chat.ID, "⚠️ 此命令只能在群组中使用")
- return
- }
- // 获取群组信息
- chatType := msg.Chat.Type
- if chatType == "group" {
- chatType = "普通群组"
- } else if chatType == "supergroup" {
- chatType = "超级群组"
- }
- username := msg.Chat.UserName
- if username == "" {
- username = "无"
- } else {
- username = "@" + username
- }
- infoText := fmt.Sprintf(`📊 群组信息
- 🆔 群组ID: <code>%d</code>
- 📝 群组名称: %s
- 🔗 用户名: %s
- 📂 群组类型: %s
- 💡 提示:
- • 点击群组ID可以复制
- • 管理员可以使用此ID配置红包发送`,
- msg.Chat.ID,
- msg.Chat.Title,
- username,
- chatType,
- )
- // 使用 HTML 解析模式发送消息,这样可以点击复制
- sendHTMLMessage(msg.Chat.ID, infoText)
- }
- // generateBindURL 生成绑定链接
- func generateBindURL(telegramID int64) string {
- // TODO: 生成真实的绑定链接
- baseURL := "https://your-domain.com/bind"
- return fmt.Sprintf("%s?telegramId=%d", baseURL, telegramID)
- }
|