forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package statg
|
||||
|
||||
import (
|
||||
"stat/common/tgbot"
|
||||
"stat/common/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
Bot *tgbot.TgBot
|
||||
RchssendBot *tgbot.TgBot
|
||||
)
|
||||
|
||||
type BotTokens struct {
|
||||
Madou string `json:"madou"`
|
||||
Zhihu string `json:"zhihu"`
|
||||
Bili string `json:"bili"`
|
||||
Xcb string `json:"xcb"`
|
||||
Dev string `json:"dev"`
|
||||
Rchssend string `json:"rchssend"`
|
||||
}
|
||||
|
||||
type BotChats struct {
|
||||
Broadcast []int64 `json:"broadcast"` // 广播群
|
||||
Command []int64 `json:"command"` // 命令群
|
||||
Monitor []int64 `json:"monitor"` // 监控群
|
||||
Download []int64 `json:"download"` // 下载监控
|
||||
Domain []int64 `json:"domain"` // 域名监控群
|
||||
Develop []int64 `json:"develop"` // 开发调试群
|
||||
Private []int64 `json:"private"` // 私聊用户列表
|
||||
BlocStat []int64 `json:"blocStat"` // 集团统计群
|
||||
Advertise []int64 `json:"advertise"` // 广告监控群
|
||||
ChannelApk []int64 `json:"channelApk"` // 渠道包生成群
|
||||
Project []int64 `json:"project"` // 来自项目的消息
|
||||
AdvsSend []int64 `json:"advssend"` //广告群
|
||||
Rchssend []int64 `json:"rchssend"` //广告群
|
||||
}
|
||||
|
||||
type BotConfig struct {
|
||||
Tokens BotTokens `json:"tokens"`
|
||||
Chats BotChats `json:"chats"`
|
||||
Allow map[int64][]string `json:"allow"` // 原本不允许使用命令的群,额外允许使用指定命令
|
||||
}
|
||||
|
||||
// 数据库初始化好以后调用
|
||||
func InitBot() {
|
||||
|
||||
defer func() {
|
||||
utils.RecoverError(nil)
|
||||
}()
|
||||
|
||||
chats := &tgbot.TgChats{
|
||||
BroadcastChats: Conf.BotConfig.Chats.Broadcast,
|
||||
CommandChats: Conf.BotConfig.Chats.Command,
|
||||
MonitorChats: Conf.BotConfig.Chats.Monitor,
|
||||
DownloadChats: Conf.BotConfig.Chats.Download,
|
||||
DomainChats: Conf.BotConfig.Chats.Domain,
|
||||
DevelopChats: Conf.BotConfig.Chats.Develop,
|
||||
PrivateUsers: Conf.BotConfig.Chats.Private,
|
||||
BlocStats: Conf.BotConfig.Chats.BlocStat,
|
||||
Advertise: Conf.BotConfig.Chats.Advertise,
|
||||
ChannelApk: Conf.BotConfig.Chats.ChannelApk,
|
||||
Project: Conf.BotConfig.Chats.Project,
|
||||
AdvsSend: Conf.BotConfig.Chats.AdvsSend,
|
||||
//Rchssend: Conf.BotConfig.Chats.Rchssend,
|
||||
}
|
||||
|
||||
chat0s := &tgbot.TgChats{
|
||||
Rchssend: Conf.BotConfig.Chats.Rchssend,
|
||||
}
|
||||
|
||||
if Conf.ServerIndex.IsBili() {
|
||||
Bot, _ = tgbot.NewTgBot(Conf.BotConfig.Tokens.Bili, chats, Conf.BotConfig.Allow)
|
||||
RchssendBot, _ = tgbot.NewTgBot(Conf.BotConfig.Tokens.Rchssend, chat0s, Conf.BotConfig.Allow)
|
||||
} else if Conf.ServerIndex.IsMadou() {
|
||||
Bot, _ = tgbot.NewTgBot(Conf.BotConfig.Tokens.Madou, chats, Conf.BotConfig.Allow)
|
||||
} else if Conf.ServerIndex.IsZhihu() {
|
||||
Bot, _ = tgbot.NewTgBot(Conf.BotConfig.Tokens.Zhihu, chats, Conf.BotConfig.Allow)
|
||||
} else if Conf.ServerIndex.IsXcb() {
|
||||
Bot, _ = tgbot.NewTgBot(Conf.BotConfig.Tokens.Xcb, chats, Conf.BotConfig.Allow)
|
||||
} else {
|
||||
Bot, _ = tgbot.NewTgBot(Conf.BotConfig.Tokens.Dev, chats, Conf.BotConfig.Allow)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package statg
|
||||
|
||||
import (
|
||||
"stat/common/config"
|
||||
"stat/common/enum/consts"
|
||||
"stat/common/httputil"
|
||||
"stat/common/log"
|
||||
|
||||
"github.com/dchest/captcha"
|
||||
)
|
||||
|
||||
var (
|
||||
Conf GlobalConfig
|
||||
ProxyCfg *httputil.ProxyCfg
|
||||
VerifyIMGStore captcha.Store
|
||||
Tgbotsend string
|
||||
)
|
||||
|
||||
type ChartsConfig struct {
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
}
|
||||
|
||||
type GlobalConfig struct {
|
||||
ServerIndex ServerIndex `json:"serverIndex"` //1:麻豆,2:逼哩,3:知乎
|
||||
RunMod consts.RunMod `json:"runMod"`
|
||||
Pprof bool `json:"pprof"`
|
||||
JwtKey string `json:"jwtKey"`
|
||||
InnerKey string `json:"innerKey"`
|
||||
InnerServers map[ServerIndex]string `json:"innerServers"`
|
||||
Kafka struct {
|
||||
Url string `json:"url"`
|
||||
Group string `json:"group"`
|
||||
} `json:"kafka"`
|
||||
Mongo struct {
|
||||
Url string `json:"url"`
|
||||
} `json:"mongo"`
|
||||
Redis struct {
|
||||
Url string `json:"url"`
|
||||
} `json:"redis"`
|
||||
Limit struct {
|
||||
Ip struct {
|
||||
Capacity int64 `json:"capacity"`
|
||||
Rate int64 `json:"rate"`
|
||||
} `json:"ip"`
|
||||
} `json:"limit"`
|
||||
URL struct {
|
||||
PackageUrl string `json:"packageUrl"`
|
||||
BiliPackageUrl string `json:"biliPackageUrl"`
|
||||
HuanqiuPackageUrl string `json:"huanqiuPackageUrl"`
|
||||
ManhuaPackageUrl string `json:"manhuaPackageUrl"`
|
||||
} `json:"url"`
|
||||
ProxyUrl struct {
|
||||
File string `json:"file"`
|
||||
FileRes string `json:"fileRes"`
|
||||
} `json:"proxyUrl"`
|
||||
KafkaServer bool `json:"kafkaServer"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
IsVersion bool `json:"versionServer"`
|
||||
ImgUploadUrl string `json:"imgUploadUrl"`
|
||||
LandPageCDN string `json:"landPageCDN"`
|
||||
BotConfig BotConfig `json:"botConfig"`
|
||||
TgbotSend string `json:"tgbotSend"`
|
||||
ApkGenEnable bool `json:"apkGenEnable"`
|
||||
ChartsConfig ChartsConfig `json:"chartsConfig"`
|
||||
AppConfig Endpoints `json:"appConfig"`
|
||||
}
|
||||
|
||||
func LoadConfig(path string) error {
|
||||
err := config.LoadJSON(path, &Conf)
|
||||
if err != nil {
|
||||
log.Fatal("加载本地配置失败", log.E(err))
|
||||
return err
|
||||
}
|
||||
// set default value
|
||||
if Conf.Limit.Ip.Capacity <= 0 {
|
||||
Conf.Limit.Ip.Capacity = 300
|
||||
}
|
||||
if Conf.Limit.Ip.Rate <= 0 {
|
||||
Conf.Limit.Ip.Rate = 5
|
||||
}
|
||||
if Conf.ChartsConfig.Width <= 0 {
|
||||
Conf.ChartsConfig.Width = 1600
|
||||
}
|
||||
if Conf.ChartsConfig.Height <= 0 {
|
||||
Conf.ChartsConfig.Height = 400
|
||||
}
|
||||
Tgbotsend = Conf.TgbotSend
|
||||
// app config
|
||||
GlobalEndpoints = Conf.AppConfig
|
||||
for _, item := range GlobalEndpoints {
|
||||
GlobalIndexEndpoints[item.OwnerIndex] = append(GlobalIndexEndpoints[item.OwnerIndex], item)
|
||||
GlobalAppIdEndpoints[item.AppId] = item
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package statg
|
||||
|
||||
type ServerIndex int32
|
||||
|
||||
const (
|
||||
ServerIndexNone ServerIndex = 0
|
||||
ServerIndexMadou ServerIndex = 1
|
||||
ServerIndexBili ServerIndex = 2
|
||||
ServerIndexZhihu ServerIndex = 3
|
||||
ServerIndexXcb ServerIndex = 4
|
||||
)
|
||||
|
||||
func (s ServerIndex) IsMadou() bool {
|
||||
return s == ServerIndexMadou
|
||||
}
|
||||
|
||||
func (s ServerIndex) IsBili() bool {
|
||||
return s == ServerIndexBili
|
||||
}
|
||||
|
||||
func (s ServerIndex) IsZhihu() bool {
|
||||
return s == ServerIndexZhihu
|
||||
}
|
||||
|
||||
func (s ServerIndex) IsXcb() bool {
|
||||
return s == ServerIndexXcb
|
||||
}
|
||||
|
||||
func (s ServerIndex) Name() string {
|
||||
switch s {
|
||||
case ServerIndexMadou:
|
||||
return "麻豆"
|
||||
case ServerIndexBili:
|
||||
return "逼哩"
|
||||
case ServerIndexZhihu:
|
||||
return "知乎"
|
||||
case ServerIndexXcb:
|
||||
return "咻车"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package statg
|
||||
|
||||
type Endpoint struct {
|
||||
AppId int32 `json:"appId"` // APPID
|
||||
NameFull string `json:"nameFull"` // APP全名
|
||||
NameShort string `json:"nameShort"` // APP短名
|
||||
NameEn string `json:"nameEn"` // 名字英文缩写
|
||||
ServerUrl string `json:"serverUrl"` // APP服务器地址
|
||||
H5Origin string `json:"h5Origin"` // H5原地址
|
||||
H5Target string `json:"h5Target"` // H5目标地址
|
||||
H5Config string `json:"h5Config"` // H5配置文件
|
||||
BotStat bool `json:"hourStat"` // 参与机器人统计
|
||||
BotRank bool `json:"hourReport"` // 参与机器人排名
|
||||
OwnerIndex ServerIndex `json:"ownerIndex"` // 所属服务器编号
|
||||
}
|
||||
|
||||
type Endpoints []*Endpoint
|
||||
type IndexEndpoints map[ServerIndex]Endpoints
|
||||
type AppIdEndpoints map[int32]*Endpoint
|
||||
|
||||
func (s Endpoints) GetIndexEndpoints(index ServerIndex) Endpoints {
|
||||
ret := make(Endpoints, 0)
|
||||
for _, endpoint := range s {
|
||||
if endpoint.OwnerIndex == index {
|
||||
ret = append(ret, endpoint)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (s Endpoints) GetBotStatEndpoints() Endpoints {
|
||||
ret := make(Endpoints, 0)
|
||||
for _, endpoint := range s {
|
||||
if endpoint.BotStat {
|
||||
ret = append(ret, endpoint)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (s Endpoints) GetBotRankEndpoints() Endpoints {
|
||||
ret := make(Endpoints, 0)
|
||||
for _, endpoint := range s {
|
||||
if endpoint.BotRank {
|
||||
ret = append(ret, endpoint)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (s Endpoints) ExistsByAppId(appId int32) bool {
|
||||
for _, endpoint := range s {
|
||||
if endpoint.AppId == appId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Endpoints) GetEndpointByAppId(appId int32) *Endpoint {
|
||||
for _, endpoint := range s {
|
||||
if endpoint.AppId == appId {
|
||||
return endpoint
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Endpoints) GetAppShortNameById(appId int32) string {
|
||||
for _, endpoint := range s {
|
||||
if endpoint.AppId == appId {
|
||||
return endpoint.NameShort
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var (
|
||||
GlobalEndpoints = make(Endpoints, 0)
|
||||
GlobalIndexEndpoints = make(IndexEndpoints)
|
||||
GlobalAppIdEndpoints = make(AppIdEndpoints)
|
||||
)
|
||||
Reference in New Issue
Block a user