add 增加查询次数限制等各种命令限制
This commit is contained in:
parent
8121a59f86
commit
a5cad67635
@ -15,6 +15,7 @@ ApiToken: #为空默认随机禁用
|
||||
Wskey: # 填空默认禁用wskey转换 需要的填true
|
||||
SMSAddress:
|
||||
IsAddFriend: #填写true或者false false
|
||||
Lim: #填写1-N 代表限制次数
|
||||
theme:
|
||||
static: ./static
|
||||
master:
|
||||
|
||||
36
models/SendLimit.go
Normal file
36
models/SendLimit.go
Normal file
@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Limit struct {
|
||||
ID int `gorm:"column:ID;primaryKey"`
|
||||
Number int
|
||||
ActiveAt string
|
||||
typ int
|
||||
num int
|
||||
}
|
||||
|
||||
func getLimit(uid int, typ int) bool {
|
||||
u := &Limit{}
|
||||
db.Where("number = ? and typ = ? and ActiveAt = ?", uid, typ, time.Now().Format("2006-01-02")).First(&u)
|
||||
if Config.Lim == 0 {
|
||||
return true
|
||||
}
|
||||
if u.ID != 0 {
|
||||
if u.num < Config.Lim {
|
||||
db.Updates(&Limit{
|
||||
num: u.num + 1,
|
||||
}).Where("ID = ?", u.ID)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
u.ActiveAt = time.Now().Format("2006-01-02")
|
||||
u.typ = typ
|
||||
u.Number = uid
|
||||
u.num = 1
|
||||
db.Create(u)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -149,140 +148,6 @@ var codeSignals = []CodeSignal{
|
||||
// return `{"url":"` + "http://www.baidu.com" + `","img":"` + s.Data.QqLoginQrcode.Bytes + `"}`
|
||||
// },
|
||||
//},
|
||||
{
|
||||
Command: []string{`raw ^(\d{11})$`},
|
||||
Handle: func(s *Sender) interface{} {
|
||||
if num := 5; len(codes) >= num {
|
||||
return fmt.Sprintf("%v坑位全部在使用中,请排队。", num)
|
||||
}
|
||||
id := "qq" + strconv.Itoa(s.UserID)
|
||||
if _, ok := codes[id]; ok {
|
||||
return "你已在登录中。"
|
||||
}
|
||||
go func() {
|
||||
c := make(chan string, 1)
|
||||
codes[id] = c
|
||||
defer delete(codes, id)
|
||||
var sess = new(Session)
|
||||
phone := s.Contents[0]
|
||||
logs.Info(phone)
|
||||
s.Reply("请稍后,正在模拟环境...")
|
||||
if err := sess.Phone(phone); err != nil {
|
||||
s.Reply(err.Error())
|
||||
return
|
||||
}
|
||||
send := false
|
||||
login := false
|
||||
verify := false
|
||||
success := false
|
||||
sms_code := ""
|
||||
for {
|
||||
query, _ := sess.query()
|
||||
if query.PageStatus == "SESSION_EXPIRED" {
|
||||
s.Reply("登录超时")
|
||||
return
|
||||
}
|
||||
if query.SessionTimeOut == 0 {
|
||||
if success {
|
||||
return
|
||||
}
|
||||
s.Reply("登录超时")
|
||||
return
|
||||
}
|
||||
if query.CanClickLogin && !login {
|
||||
s.Reply("正在登录...")
|
||||
if err := sess.login(phone, sms_code); err != nil {
|
||||
s.Reply(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if query.PageStatus == "VERIFY_FAILED_MAX" {
|
||||
s.Reply("验证码错误次数过多,请重新获取。")
|
||||
return
|
||||
}
|
||||
if query.PageStatus == "VERIFY_CODE_MAX" {
|
||||
s.Reply("对不起,短信验证码请求频繁,请稍后再试。")
|
||||
return
|
||||
}
|
||||
if query.PageStatus == "REQUIRE_VERIFY" && !verify {
|
||||
verify = true
|
||||
s.Reply("正在自动验证...")
|
||||
if err := sess.crackCaptcha(); err != nil {
|
||||
s.Reply(err.Error())
|
||||
return
|
||||
}
|
||||
s.Reply("验证通过。")
|
||||
s.Reply("请输入验证码______")
|
||||
select {
|
||||
case sms_code = <-c:
|
||||
s.Reply("正在提交验证码...")
|
||||
if err := sess.SmsCode(sms_code); err != nil {
|
||||
s.Reply(err.Error())
|
||||
return
|
||||
}
|
||||
s.Reply("验证码提交成功。")
|
||||
case <-time.After(60 * time.Second):
|
||||
s.Reply("验证码超时。")
|
||||
return
|
||||
|
||||
}
|
||||
}
|
||||
if query.CanSendAuth && !send {
|
||||
if err := sess.sendAuthCode(); err != nil {
|
||||
s.Reply(err.Error())
|
||||
return
|
||||
}
|
||||
send = true
|
||||
}
|
||||
if !query.CanSendAuth && query.AuthCodeCountDown > 0 {
|
||||
|
||||
}
|
||||
if query.AuthCodeCountDown == -1 && send {
|
||||
|
||||
}
|
||||
if query.PageStatus == "SUCCESS_CK" && !success {
|
||||
//Sender <- &Faker{
|
||||
// Message: fmt.Sprintf("pt_key=%v;pt_pin=%v;", query.Ck.PtKey, query.Ck.PtPin),
|
||||
// UserID: s.GetUserID(),
|
||||
// Type: s.GetImType(),
|
||||
//}
|
||||
s.Reply(fmt.Sprintf("登录成功,%v秒后可以登录下一个账号。", query.SessionTimeOut))
|
||||
success = true
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Command: []string{"登录"},
|
||||
Handle: func(s *Sender) interface{} {
|
||||
logs.Info("进入流程")
|
||||
if num := 5; len(codes) >= num {
|
||||
return fmt.Sprintf("%v坑位全部在使用中,请排队(稍后再试)。", num)
|
||||
}
|
||||
id := "qq" + strconv.Itoa(s.UserID)
|
||||
if _, ok := codes[id]; ok {
|
||||
return "你已在登录中。"
|
||||
}
|
||||
s.Reply("请输入手机号___________")
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Command: []string{`raw ^(\d{6})$`},
|
||||
Handle: func(s *Sender) interface{} {
|
||||
if code, ok := codes["qq"+fmt.Sprint(s.UserID)]; ok {
|
||||
//code <- s.Get()
|
||||
logs.Info(code)
|
||||
} else {
|
||||
s.Reply("验证码不存在或过期了,请重新登录。")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Command: []string{"sign", "打卡", "签到"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
@ -426,9 +291,13 @@ var codeSignals = []CodeSignal{
|
||||
{
|
||||
Command: []string{"查询", "query"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
sender.handleJdCookies(func(ck *JdCookie) {
|
||||
sender.Reply(ck.Query())
|
||||
})
|
||||
if getLimit(sender.UserID, 1) {
|
||||
sender.handleJdCookies(func(ck *JdCookie) {
|
||||
sender.Reply(ck.Query())
|
||||
})
|
||||
} else {
|
||||
sender.Reply("超过今日查询次数")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
@ -459,7 +328,7 @@ var codeSignals = []CodeSignal{
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Command: []string{"设置管理员"},
|
||||
Admin: true,
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
@ -477,123 +346,123 @@ var codeSignals = []CodeSignal{
|
||||
return "已取消管理员"
|
||||
},
|
||||
},
|
||||
/*
|
||||
{
|
||||
Command: []string{"我要钱", "给点钱", "我干", "给我钱", "给我", "我要"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
cost := Int(sender.JoinContens())
|
||||
if cost <= 0 {
|
||||
cost = 1
|
||||
}
|
||||
if !sender.IsAdmin {
|
||||
if cost > 1 {
|
||||
return "你只能获得1互助值"
|
||||
} else {
|
||||
AddCoin(sender.UserID)
|
||||
return "太可怜了,给你1互助值"
|
||||
/*
|
||||
{
|
||||
Command: []string{"我要钱", "给点钱", "我干", "给我钱", "给我", "我要"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
cost := Int(sender.JoinContens())
|
||||
if cost <= 0 {
|
||||
cost = 1
|
||||
}
|
||||
} else {
|
||||
AdddCoin(sender.UserID, cost)
|
||||
sender.Reply(fmt.Sprintf("你获得%d枚互助值。", cost))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Command: []string{"梭哈", "拼了", "梭了"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
u := &User{}
|
||||
cost := GetCoin(sender.UserID)
|
||||
|
||||
if cost <= 0 || cost > 10000 {
|
||||
cost = 1
|
||||
}
|
||||
|
||||
if err := db.Where("number = ?", sender.UserID).First(u).Error; err != nil || u.Coin < cost {
|
||||
return "互助值不足,先去打卡吧。"
|
||||
} else {
|
||||
sender.Reply(fmt.Sprintf("你使用%d枚互助值。", cost))
|
||||
}
|
||||
baga := 0
|
||||
if u.Coin > 100000 {
|
||||
baga = u.Coin
|
||||
cost = u.Coin
|
||||
}
|
||||
r := time.Now().Nanosecond() % 10
|
||||
if r < 7 || baga > 0 {
|
||||
sender.Reply(fmt.Sprintf("很遗憾你失去了%d枚互助值。", cost))
|
||||
cost = -cost
|
||||
} else {
|
||||
if r == 9 {
|
||||
cost *= 4
|
||||
sender.Reply(fmt.Sprintf("恭喜你4倍暴击获得%d枚互助值,20秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 20)
|
||||
if !sender.IsAdmin {
|
||||
if cost > 1 {
|
||||
return "你只能获得1互助值"
|
||||
} else {
|
||||
AddCoin(sender.UserID)
|
||||
return "太可怜了,给你1互助值"
|
||||
}
|
||||
} else {
|
||||
sender.Reply(fmt.Sprintf("很幸运你获得%d枚互助值,10秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 10)
|
||||
AdddCoin(sender.UserID, cost)
|
||||
sender.Reply(fmt.Sprintf("你获得%d枚互助值。", cost))
|
||||
}
|
||||
sender.Reply(fmt.Sprintf("%d枚互助值已到账。", cost))
|
||||
}
|
||||
db.Model(u).Update("coin", gorm.Expr(fmt.Sprintf("coin + %d", cost)))
|
||||
return nil
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
//{
|
||||
// Command: []string{"按许愿币更新排名"},
|
||||
// Admin: true,
|
||||
// Handle: func(sender *Sender) interface{} {
|
||||
// cookies:= GetJdCookies()
|
||||
// for i := range cookies {
|
||||
// cookie := cookies[i]
|
||||
// if cookie.QQ {
|
||||
//
|
||||
// }
|
||||
// cookie.Update(Priority,cookie.)
|
||||
// }
|
||||
// sender.handleJdCookies(func(ck *JdCookie) {
|
||||
// sender.Reply(ck.Query())
|
||||
// })
|
||||
// return "已更新排行"
|
||||
// },
|
||||
//},
|
||||
{
|
||||
Command: []string{"赌一把"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
{
|
||||
Command: []string{"梭哈", "拼了", "梭了"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
u := &User{}
|
||||
cost := GetCoin(sender.UserID)
|
||||
|
||||
cost := Int(sender.JoinContens())
|
||||
if cost <= 0 || cost > 10000 {
|
||||
cost = 1
|
||||
}
|
||||
u := &User{}
|
||||
if err := db.Where("number = ?", sender.UserID).First(u).Error; err != nil || u.Coin < cost {
|
||||
return "互助值不足,先去打卡吧。"
|
||||
}
|
||||
baga := 0
|
||||
if u.Coin > 100000 {
|
||||
baga = u.Coin
|
||||
cost = u.Coin
|
||||
}
|
||||
r := time.Now().Nanosecond() % 10
|
||||
if r < 6 || baga > 0 {
|
||||
sender.Reply(fmt.Sprintf("很遗憾你失去了%d枚互助值。", cost))
|
||||
cost = -cost
|
||||
} else {
|
||||
if r == 9 {
|
||||
cost *= 2
|
||||
sender.Reply(fmt.Sprintf("恭喜你幸运暴击获得%d枚互助值,20秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 20)
|
||||
} else {
|
||||
sender.Reply(fmt.Sprintf("很幸运你获得%d枚互助值,10秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 10)
|
||||
if cost <= 0 || cost > 10000 {
|
||||
cost = 1
|
||||
}
|
||||
sender.Reply(fmt.Sprintf("%d枚互助值已到账。", cost))
|
||||
}
|
||||
db.Model(u).Update("coin", gorm.Expr(fmt.Sprintf("coin + %d", cost)))
|
||||
return nil
|
||||
|
||||
if err := db.Where("number = ?", sender.UserID).First(u).Error; err != nil || u.Coin < cost {
|
||||
return "互助值不足,先去打卡吧。"
|
||||
} else {
|
||||
sender.Reply(fmt.Sprintf("你使用%d枚互助值。", cost))
|
||||
}
|
||||
baga := 0
|
||||
if u.Coin > 100000 {
|
||||
baga = u.Coin
|
||||
cost = u.Coin
|
||||
}
|
||||
r := time.Now().Nanosecond() % 10
|
||||
if r < 7 || baga > 0 {
|
||||
sender.Reply(fmt.Sprintf("很遗憾你失去了%d枚互助值。", cost))
|
||||
cost = -cost
|
||||
} else {
|
||||
if r == 9 {
|
||||
cost *= 4
|
||||
sender.Reply(fmt.Sprintf("恭喜你4倍暴击获得%d枚互助值,20秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 20)
|
||||
} else {
|
||||
sender.Reply(fmt.Sprintf("很幸运你获得%d枚互助值,10秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 10)
|
||||
}
|
||||
sender.Reply(fmt.Sprintf("%d枚互助值已到账。", cost))
|
||||
}
|
||||
db.Model(u).Update("coin", gorm.Expr(fmt.Sprintf("coin + %d", cost)))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
*/
|
||||
|
||||
//{
|
||||
// Command: []string{"按许愿币更新排名"},
|
||||
// Admin: true,
|
||||
// Handle: func(sender *Sender) interface{} {
|
||||
// cookies:= GetJdCookies()
|
||||
// for i := range cookies {
|
||||
// cookie := cookies[i]
|
||||
// if cookie.QQ {
|
||||
//
|
||||
// }
|
||||
// cookie.Update(Priority,cookie.)
|
||||
// }
|
||||
// sender.handleJdCookies(func(ck *JdCookie) {
|
||||
// sender.Reply(ck.Query())
|
||||
// })
|
||||
// return "已更新排行"
|
||||
// },
|
||||
//},
|
||||
{
|
||||
Command: []string{"赌一把"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
|
||||
cost := Int(sender.JoinContens())
|
||||
if cost <= 0 || cost > 10000 {
|
||||
cost = 1
|
||||
}
|
||||
u := &User{}
|
||||
if err := db.Where("number = ?", sender.UserID).First(u).Error; err != nil || u.Coin < cost {
|
||||
return "互助值不足,先去打卡吧。"
|
||||
}
|
||||
baga := 0
|
||||
if u.Coin > 100000 {
|
||||
baga = u.Coin
|
||||
cost = u.Coin
|
||||
}
|
||||
r := time.Now().Nanosecond() % 10
|
||||
if r < 6 || baga > 0 {
|
||||
sender.Reply(fmt.Sprintf("很遗憾你失去了%d枚互助值。", cost))
|
||||
cost = -cost
|
||||
} else {
|
||||
if r == 9 {
|
||||
cost *= 2
|
||||
sender.Reply(fmt.Sprintf("恭喜你幸运暴击获得%d枚互助值,20秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 20)
|
||||
} else {
|
||||
sender.Reply(fmt.Sprintf("很幸运你获得%d枚互助值,10秒后自动转入余额。", cost))
|
||||
time.Sleep(time.Second * 10)
|
||||
}
|
||||
sender.Reply(fmt.Sprintf("%d枚互助值已到账。", cost))
|
||||
}
|
||||
db.Model(u).Update("coin", gorm.Expr(fmt.Sprintf("coin + %d", cost)))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
*/
|
||||
{
|
||||
Command: []string{"许愿", "愿望", "wish", "hope", "want"},
|
||||
Handle: func(sender *Sender) interface{} {
|
||||
|
||||
@ -40,6 +40,7 @@ type Yaml struct {
|
||||
TGURL string `yaml:"TGURL"`
|
||||
SMSAddress string `yaml:"SMSAddress"`
|
||||
IsAddFriend bool `yaml:"IsAddFriend"`
|
||||
Lim int `yaml:"Lim"`
|
||||
Node string
|
||||
Npm string
|
||||
Python string
|
||||
|
||||
@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -242,7 +241,6 @@ func (ck *JdCookie) OutPool() (string, error) {
|
||||
if tx.Where(fmt.Sprintf("%s = '%s' and %s = '%s'", PtPin, ck.PtPin, LoseAt, "")).First(jp).Error != nil {
|
||||
us[Available] = False
|
||||
us[PtKey] = ""
|
||||
logs.Info("开始禁用")
|
||||
} else {
|
||||
us[Available] = True
|
||||
us[PtKey] = jp.PtKey
|
||||
|
||||
Loading…
Reference in New Issue
Block a user