package tgbot import ( "hkdj-web-server/pub/common/srvdef" ) //获取群聊id var ( //配置 tgToken = "" programTgGroupIds = []int64{} monitorTgGroupIds = []int64{} adminTgIds = []int64{} prefix = "[花魁NET]" tgBot *TgBot = nil ) func InitTgBot(token string, prefixStr string) *srvdef.SrvErr { if tgBot != nil { return nil } if prefixStr != "" { prefix = prefixStr } tgBot = NewTelegramBot(token) if serr := tgBot.Init(); nil != serr { return serr } //SendToAll("支付监控测试", "Test") return nil } func ReleaseTgBot() { if tgBot == nil { return } tgBot.Release() } // SendToAdmins 发到管理人员 func SendToAdmins(title string, info string) { sendTo(adminTgIds, title, info) } // SendToProgram 发到程序 func SendToProgram(title string, info string) { sendTo(programTgGroupIds, title, info) } // SendToMonitor 发到监控群组 func SendToMonitor(title string, info string) { sendTo(monitorTgGroupIds, title, info) } // SendToProgram 发到所有 func SendToAll(title string, info string) { groupIds := programTgGroupIds groupIds = append(groupIds, monitorTgGroupIds...) //groupIds = append(groupIds, adminTgIds...) sendTo(groupIds, title, info) } func sendTo(ids []int64, title string, info string) { if tgBot == nil { return } //异步发送 go func() { msg := prefix + "\n" + title + "\n" + info tgBot.Send(ids, msg) }() } func RegisterCommands(commands []*BotCmd) { if tgBot == nil { return } tgBot.RegisterCommands(commands) } func Receive() { if tgBot == nil { return } tgBot.Receive() }