Files
rootandClaude Opus 4.7 85c0071fd8 feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-16 11:20:04 +08:00

89 lines
1.6 KiB
Go

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()
}