增加账户任务错误上限自动解绑

This commit is contained in:
iyear 2020-04-09 16:47:10 +08:00
parent 89fd0a0eee
commit 737d28fd37
2 changed files with 28 additions and 5 deletions

View File

@ -98,10 +98,12 @@ func SignTask() {
data := QueryDataAll(db)
num = len(data)
fmt.Println("Start Sign")
//签到任务
for _, u := range data {
pre := "您的账户: " + u.alias + "\n在任务执行时出现了错误!\n错误:"
access, err := MSGetToken(u.refreshToken, u.clientId, u.clientSecret)
chat, _ := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
//生成解绑按钮
var inlineKeys [][]tb.InlineButton
UnBindBtn := tb.InlineButton{Unique: "un" + u.msId, Text: "点击解绑该账户", Data: u.msId}
@ -114,11 +116,13 @@ func SignTask() {
logger.Println(u.msId+" ", err)
bot.Send(chat, pre+gjson.Get(err.Error(), "error").String(), tmpBtn)
SignErr = append(SignErr, se)
ErrorTimes[u.msId]++
continue
}
if ok, err := OutLookGetMails(access); !ok {
logger.Println(u.msId+" ", err)
bot.Send(chat, pre+gjson.Get(err.Error(), "error").String(), tmpBtn)
ErrorTimes[u.msId]++
SignErr = append(SignErr, se)
continue
}
@ -127,6 +131,7 @@ func SignTask() {
logger.Println(u.msId+" ", err)
bot.Send(chat, pre+err.Error(), tmpBtn)
SignErr = append(SignErr, se)
ErrorTimes[u.msId]++
continue
}
fmt.Println(u.msId + " Sign OK!")
@ -138,12 +143,25 @@ func SignTask() {
isSend = make(map[int64]bool)
//用户任务反馈
for _, u := range data {
if !isSend[u.tgId] {
chat, err := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
if err != nil {
logger.Println("Send Result ERROR", err)
continue
chat, err := bot.ChatByID(strconv.FormatInt(u.tgId, 10))
if err != nil {
logger.Println("Send Result ERROR: ", err)
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})
if err != nil {

View File

@ -33,7 +33,9 @@ var (
UserStatus map[int64]int
UserCid map[int64]string
UserCSecret map[int64]string
ErrorTimes map[string]int //错误次数
BindMaxNum int
ErrMaxTimes int
notice string
admin []int64
)
@ -52,12 +54,14 @@ func init() {
CheckErr(err)
BindMaxNum = viper.GetInt("bindmax")
ErrMaxTimes = viper.GetInt("errlimit")
notice = viper.GetString("notice")
admin = GetAdmin()
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
BindMaxNum = viper.GetInt("bindmax")
ErrMaxTimes = viper.GetInt("errlimit")
notice = viper.GetString("notice")
admin = GetAdmin()
})
@ -65,6 +69,7 @@ func init() {
UserStatus = make(map[int64]int)
UserCid = make(map[int64]string)
UserCSecret = make(map[int64]string)
ErrorTimes = make(map[string]int)
}
func bStart(m *tb.Message) {