package tgbot import ( "videoweb/pub/common/srvdef" ) //获取群聊id //https://api.telegram.org/bot1803190372:AAGmrrN6xUoh7IKiv4qCVJYdCs8wLt1ffCw/getUpdates var ( //配置 //zhihu app机器人 2048234434:AAF3XoW4iE6vAOmttTT_bofgan_PleKuaEk //zhihu web机器人 1973289619:AAHjCZ8KQOewVfr20foHKlKVwJoulrf_OFc tgToken = "2048234434:AAF3XoW4iE6vAOmttTT_bofgan_PleKuaEk" //程序支付监控群tgids programTgGroupIds = []int64{-778146822} //天行监控组tgids monitorTgGroupIds = []int64{-1001373963166} //管理人员tgid(yl:1652126945) adminTgIds = []int64{1652126945} prefix = "[汁乎App]" 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() }