增加账户任务错误上限自动解绑
This commit is contained in:
parent
89fd0a0eee
commit
737d28fd37
28
control.go
28
control.go
@ -98,10 +98,12 @@ func SignTask() {
|
|||||||
data := QueryDataAll(db)
|
data := QueryDataAll(db)
|
||||||
num = len(data)
|
num = len(data)
|
||||||
fmt.Println("Start Sign")
|
fmt.Println("Start Sign")
|
||||||
|
//签到任务
|
||||||
for _, u := range data {
|
for _, u := range data {
|
||||||
pre := "您的账户: " + u.alias + "\n在任务执行时出现了错误!\n错误:"
|
pre := "您的账户: " + u.alias + "\n在任务执行时出现了错误!\n错误:"
|
||||||
access, err := MSGetToken(u.refreshToken, u.clientId, u.clientSecret)
|
access, err := MSGetToken(u.refreshToken, u.clientId, u.clientSecret)
|
||||||
chat, _ := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
|
chat, _ := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
|
||||||
|
|
||||||
//生成解绑按钮
|
//生成解绑按钮
|
||||||
var inlineKeys [][]tb.InlineButton
|
var inlineKeys [][]tb.InlineButton
|
||||||
UnBindBtn := tb.InlineButton{Unique: "un" + u.msId, Text: "点击解绑该账户", Data: u.msId}
|
UnBindBtn := tb.InlineButton{Unique: "un" + u.msId, Text: "点击解绑该账户", Data: u.msId}
|
||||||
@ -114,11 +116,13 @@ func SignTask() {
|
|||||||
logger.Println(u.msId+" ", err)
|
logger.Println(u.msId+" ", err)
|
||||||
bot.Send(chat, pre+gjson.Get(err.Error(), "error").String(), tmpBtn)
|
bot.Send(chat, pre+gjson.Get(err.Error(), "error").String(), tmpBtn)
|
||||||
SignErr = append(SignErr, se)
|
SignErr = append(SignErr, se)
|
||||||
|
ErrorTimes[u.msId]++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ok, err := OutLookGetMails(access); !ok {
|
if ok, err := OutLookGetMails(access); !ok {
|
||||||
logger.Println(u.msId+" ", err)
|
logger.Println(u.msId+" ", err)
|
||||||
bot.Send(chat, pre+gjson.Get(err.Error(), "error").String(), tmpBtn)
|
bot.Send(chat, pre+gjson.Get(err.Error(), "error").String(), tmpBtn)
|
||||||
|
ErrorTimes[u.msId]++
|
||||||
SignErr = append(SignErr, se)
|
SignErr = append(SignErr, se)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -127,6 +131,7 @@ func SignTask() {
|
|||||||
logger.Println(u.msId+" ", err)
|
logger.Println(u.msId+" ", err)
|
||||||
bot.Send(chat, pre+err.Error(), tmpBtn)
|
bot.Send(chat, pre+err.Error(), tmpBtn)
|
||||||
SignErr = append(SignErr, se)
|
SignErr = append(SignErr, se)
|
||||||
|
ErrorTimes[u.msId]++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Println(u.msId + " Sign OK!")
|
fmt.Println(u.msId + " Sign OK!")
|
||||||
@ -138,12 +143,25 @@ func SignTask() {
|
|||||||
isSend = make(map[int64]bool)
|
isSend = make(map[int64]bool)
|
||||||
//用户任务反馈
|
//用户任务反馈
|
||||||
for _, u := range data {
|
for _, u := range data {
|
||||||
if !isSend[u.tgId] {
|
chat, err := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
|
||||||
chat, err := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
|
if err != nil {
|
||||||
if err != nil {
|
logger.Println("Send Result ERROR: ", err)
|
||||||
logger.Println("Send Result ERROR", err)
|
continue
|
||||||
continue
|
}
|
||||||
|
//错误上限账户清退
|
||||||
|
if ErrorTimes[u.msId] == ErrMaxTimes {
|
||||||
|
logger.Println(u.msId + " Error Limit")
|
||||||
|
if ok, err := DelData(db, u.msId); !ok {
|
||||||
|
logger.Println(err)
|
||||||
|
} else {
|
||||||
|
_, err = bot.Send(chat, "您的账户因达到错误上限而被自动解绑\n后会有期!\n\n别名: "+u.alias+"\nclient_id: "+u.clientId+"\nclient_secret: "+u.clientSecret)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if !isSend[u.tgId] {
|
||||||
//静默发送,过多消息很烦
|
//静默发送,过多消息很烦
|
||||||
_, err = bot.Send(chat, "任务反馈\n时间: "+time.Now().Format("2006-01-02 15:04:05")+"\n结果: "+strconv.Itoa(SignOk[u.tgId])+"/"+strconv.Itoa(GetBindNum(u.tgId)), &tb.SendOptions{DisableNotification: true})
|
_, err = bot.Send(chat, "任务反馈\n时间: "+time.Now().Format("2006-01-02 15:04:05")+"\n结果: "+strconv.Itoa(SignOk[u.tgId])+"/"+strconv.Itoa(GetBindNum(u.tgId)), &tb.SendOptions{DisableNotification: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -33,7 +33,9 @@ var (
|
|||||||
UserStatus map[int64]int
|
UserStatus map[int64]int
|
||||||
UserCid map[int64]string
|
UserCid map[int64]string
|
||||||
UserCSecret map[int64]string
|
UserCSecret map[int64]string
|
||||||
|
ErrorTimes map[string]int //错误次数
|
||||||
BindMaxNum int
|
BindMaxNum int
|
||||||
|
ErrMaxTimes int
|
||||||
notice string
|
notice string
|
||||||
admin []int64
|
admin []int64
|
||||||
)
|
)
|
||||||
@ -52,12 +54,14 @@ func init() {
|
|||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
|
|
||||||
BindMaxNum = viper.GetInt("bindmax")
|
BindMaxNum = viper.GetInt("bindmax")
|
||||||
|
ErrMaxTimes = viper.GetInt("errlimit")
|
||||||
notice = viper.GetString("notice")
|
notice = viper.GetString("notice")
|
||||||
admin = GetAdmin()
|
admin = GetAdmin()
|
||||||
|
|
||||||
viper.WatchConfig()
|
viper.WatchConfig()
|
||||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||||
BindMaxNum = viper.GetInt("bindmax")
|
BindMaxNum = viper.GetInt("bindmax")
|
||||||
|
ErrMaxTimes = viper.GetInt("errlimit")
|
||||||
notice = viper.GetString("notice")
|
notice = viper.GetString("notice")
|
||||||
admin = GetAdmin()
|
admin = GetAdmin()
|
||||||
})
|
})
|
||||||
@ -65,6 +69,7 @@ func init() {
|
|||||||
UserStatus = make(map[int64]int)
|
UserStatus = make(map[int64]int)
|
||||||
UserCid = make(map[int64]string)
|
UserCid = make(map[int64]string)
|
||||||
UserCSecret = make(map[int64]string)
|
UserCSecret = make(map[int64]string)
|
||||||
|
ErrorTimes = make(map[string]int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bStart(m *tb.Message) {
|
func bStart(m *tb.Message) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user