2021-08-15 09:48:05 +08:00
|
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
"os"
|
|
|
|
|
|
"regexp"
|
|
|
|
|
|
"strings"
|
2021-08-28 09:52:25 +08:00
|
|
|
|
"time"
|
2021-08-15 09:48:05 +08:00
|
|
|
|
|
|
|
|
|
|
"github.com/beego/beego/v2/client/httplib"
|
|
|
|
|
|
"github.com/beego/beego/v2/core/logs"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2021-08-19 11:23:27 +08:00
|
|
|
|
var SendQQ = func(a int64, b interface{}) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-08-20 12:05:57 +08:00
|
|
|
|
var SendQQGroup = func(a int64, b int64, c interface{}) {
|
2021-08-19 11:39:09 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2021-08-15 09:48:05 +08:00
|
|
|
|
var ListenQQPrivateMessage = func(uid int64, msg string) {
|
|
|
|
|
|
SendQQ(uid, handleMessage(msg, "qq", int(uid)))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ListenQQGroupMessage = func(gid int64, uid int64, msg string) {
|
|
|
|
|
|
if gid == Config.QQGroupID {
|
|
|
|
|
|
if Config.QbotPublicMode {
|
2021-08-19 16:14:05 +08:00
|
|
|
|
SendQQGroup(gid, uid, handleMessage(msg, "qqg", int(uid), int(gid)))
|
2021-08-15 09:48:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
SendQQ(uid, handleMessage(msg, "qq", int(uid)))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var replies = map[string]string{}
|
|
|
|
|
|
|
|
|
|
|
|
func InitReplies() {
|
|
|
|
|
|
f, err := os.Open(ExecPath + "/conf/reply.php")
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
data, _ := ioutil.ReadAll(f)
|
|
|
|
|
|
ss := regexp.MustCompile("`([^`]+)`\\s*=>\\s*`([^`]+)`").FindAllStringSubmatch(string(data), -1)
|
|
|
|
|
|
for _, s := range ss {
|
|
|
|
|
|
replies[s[1]] = s[2]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if _, ok := replies["壁纸"]; !ok {
|
|
|
|
|
|
replies["壁纸"] = "https://acg.toubiec.cn/random.php"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-28 09:52:25 +08:00
|
|
|
|
var handleMessage = func(msgs ...interface{}) interface{} {
|
|
|
|
|
|
msg := msgs[0].(string)
|
|
|
|
|
|
args := strings.Split(msg, " ")
|
|
|
|
|
|
head := args[0]
|
|
|
|
|
|
contents := args[1:]
|
|
|
|
|
|
sender := &Sender{
|
|
|
|
|
|
UserID: msgs[2].(int),
|
|
|
|
|
|
Type: msgs[1].(string),
|
|
|
|
|
|
Contents: contents,
|
2021-08-19 08:40:38 +08:00
|
|
|
|
}
|
2021-08-19 21:39:56 +08:00
|
|
|
|
if len(msgs) >= 4 {
|
2021-08-28 09:52:25 +08:00
|
|
|
|
sender.ChatID = msgs[3].(int)
|
2021-08-15 09:48:05 +08:00
|
|
|
|
}
|
2021-08-28 09:52:25 +08:00
|
|
|
|
if sender.Type == "tgg" {
|
|
|
|
|
|
sender.MessageID = msgs[4].(int)
|
|
|
|
|
|
sender.Username = msgs[5].(string)
|
|
|
|
|
|
sender.ReplySenderUserID = msgs[6].(int)
|
2021-08-15 09:48:05 +08:00
|
|
|
|
}
|
2021-08-28 09:52:25 +08:00
|
|
|
|
if sender.UserID == Config.TelegramUserID || sender.UserID == int(Config.QQID) {
|
|
|
|
|
|
sender.IsAdmin = true
|
2021-08-19 08:40:38 +08:00
|
|
|
|
}
|
2021-08-28 09:52:25 +08:00
|
|
|
|
for i := range codeSignals {
|
|
|
|
|
|
for j := range codeSignals[i].Command {
|
|
|
|
|
|
if codeSignals[i].Command[j] == head {
|
|
|
|
|
|
return func() interface{} {
|
|
|
|
|
|
if codeSignals[i].Admin && !sender.IsAdmin {
|
|
|
|
|
|
return "你没有权限操作"
|
|
|
|
|
|
}
|
|
|
|
|
|
return codeSignals[i].Handle(sender)
|
|
|
|
|
|
}()
|
|
|
|
|
|
}
|
2021-08-15 09:48:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
switch msg {
|
|
|
|
|
|
default:
|
2021-09-01 17:31:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
if strings.Contains(msg, "wskey=") {
|
2021-09-04 17:05:25 +08:00
|
|
|
|
rsp := cmd(fmt.Sprintf(`python3 test.py "%s"`, msg), &Sender{})
|
|
|
|
|
|
logs.Info(rsp)
|
2021-09-04 08:35:08 +08:00
|
|
|
|
ss1 := regexp.MustCompile(`pin=([^;=\s]+);wskey=([^;=\s]+)`).FindAllStringSubmatch(msg, -1)
|
2021-09-05 07:32:46 +08:00
|
|
|
|
if strings.Contains(rsp, "错误") {
|
|
|
|
|
|
logs.Error("wskey错误")
|
|
|
|
|
|
} else {
|
2021-09-04 08:47:55 +08:00
|
|
|
|
|
2021-09-05 07:32:46 +08:00
|
|
|
|
if len(ss1) > 0 {
|
|
|
|
|
|
for _, s := range ss1 {
|
|
|
|
|
|
ck := JdCookie{
|
|
|
|
|
|
PtPin: s[1],
|
|
|
|
|
|
PtKey: rsp,
|
|
|
|
|
|
WsKey: s[2],
|
|
|
|
|
|
}
|
2021-09-06 16:05:55 +08:00
|
|
|
|
|
|
|
|
|
|
ss := regexp.MustCompile(`pt_key=([^;=\s]+);pt_pin=([^;=\s]+)`).FindAllStringSubmatch(rsp, -1)
|
|
|
|
|
|
for _, s1 := range ss {
|
|
|
|
|
|
ck.PtPin = s1[2]
|
|
|
|
|
|
ck.PtKey = s1[1]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if sender.IsQQ() {
|
|
|
|
|
|
ck.QQ = sender.UserID
|
|
|
|
|
|
} else if sender.IsTG() {
|
|
|
|
|
|
ck.Telegram = sender.UserID
|
|
|
|
|
|
}
|
|
|
|
|
|
if nck, err := GetJdCookie(ck.PtPin); err == nil {
|
|
|
|
|
|
nck.InPool(ck.PtKey)
|
|
|
|
|
|
if nck.WsKey == "" || len(nck.WsKey) == 0 {
|
|
|
|
|
|
nck.Updates(JdCookie{
|
|
|
|
|
|
WsKey: ck.WsKey,
|
|
|
|
|
|
})
|
|
|
|
|
|
msg := fmt.Sprintf("写入WsKey,并更新账号%s", ck.PtPin)
|
|
|
|
|
|
(&JdCookie{}).Push(msg)
|
|
|
|
|
|
logs.Info(msg)
|
|
|
|
|
|
} else {
|
2021-09-07 00:21:14 +08:00
|
|
|
|
if nck.WsKey == ck.WsKey {
|
|
|
|
|
|
msg := fmt.Sprintf("重复写入")
|
|
|
|
|
|
sender.Reply(fmt.Sprintf(msg))
|
|
|
|
|
|
(&JdCookie{}).Push(msg)
|
|
|
|
|
|
logs.Info(msg)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
nck.Updates(JdCookie{
|
|
|
|
|
|
WsKey: ck.WsKey,
|
|
|
|
|
|
})
|
|
|
|
|
|
msg := fmt.Sprintf("写入WsKey,并更新账号%s", ck.PtPin)
|
|
|
|
|
|
sender.Reply(fmt.Sprintf(msg))
|
|
|
|
|
|
(&JdCookie{}).Push(msg)
|
|
|
|
|
|
logs.Info(msg)
|
|
|
|
|
|
}
|
2021-09-04 18:50:52 +08:00
|
|
|
|
}
|
2021-09-04 08:35:08 +08:00
|
|
|
|
} else {
|
2021-09-05 09:38:19 +08:00
|
|
|
|
NewJdCookie(&ck)
|
2021-09-07 00:27:14 +08:00
|
|
|
|
msg := fmt.Sprintf("添加账号,用户名:%s", ck.PtPin)
|
2021-09-07 09:08:23 +08:00
|
|
|
|
sender.Reply(fmt.Sprintf(msg))
|
2021-09-04 08:35:08 +08:00
|
|
|
|
logs.Info(msg)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-05 07:32:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
Save <- &JdCookie{}
|
|
|
|
|
|
}()
|
|
|
|
|
|
return nil
|
2021-09-04 00:32:07 +08:00
|
|
|
|
}
|
2021-09-01 17:31:22 +08:00
|
|
|
|
}
|
2021-09-05 07:32:46 +08:00
|
|
|
|
|
2021-09-01 17:31:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-17 12:27:24 +08:00
|
|
|
|
{ //tyt
|
2021-08-19 17:10:23 +08:00
|
|
|
|
ss := regexp.MustCompile(`packetId=(\S+)(&|&)currentActId`).FindStringSubmatch(msg)
|
2021-08-17 12:27:24 +08:00
|
|
|
|
if len(ss) > 0 {
|
2021-08-28 09:52:25 +08:00
|
|
|
|
if !sender.IsAdmin {
|
|
|
|
|
|
coin := GetCoin(sender.UserID)
|
|
|
|
|
|
if coin < 8 {
|
|
|
|
|
|
return "推一推需要8个许愿币。"
|
|
|
|
|
|
}
|
|
|
|
|
|
RemCoin(sender.UserID, 8)
|
|
|
|
|
|
sender.Reply("推一推即将开始,已扣除8个许愿币。")
|
2021-08-21 20:27:59 +08:00
|
|
|
|
}
|
2021-08-28 09:52:25 +08:00
|
|
|
|
runTask(&Task{Path: "jd_tyt.js", Envs: []Env{
|
|
|
|
|
|
{Name: "tytpacketId", Value: ss[1]},
|
|
|
|
|
|
}}, sender)
|
2021-08-17 12:27:24 +08:00
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-15 09:48:05 +08:00
|
|
|
|
{ //
|
|
|
|
|
|
ss := regexp.MustCompile(`pt_key=([^;=\s]+);pt_pin=([^;=\s]+)`).FindAllStringSubmatch(msg, -1)
|
2021-08-28 09:52:25 +08:00
|
|
|
|
|
2021-08-15 09:48:05 +08:00
|
|
|
|
if len(ss) > 0 {
|
2021-08-28 09:52:25 +08:00
|
|
|
|
|
2021-08-15 09:48:05 +08:00
|
|
|
|
xyb := 0
|
|
|
|
|
|
for _, s := range ss {
|
|
|
|
|
|
ck := JdCookie{
|
|
|
|
|
|
PtKey: s[1],
|
|
|
|
|
|
PtPin: s[2],
|
|
|
|
|
|
}
|
|
|
|
|
|
if CookieOK(&ck) {
|
|
|
|
|
|
xyb++
|
2021-08-28 09:52:25 +08:00
|
|
|
|
if sender.IsQQ() {
|
|
|
|
|
|
ck.QQ = sender.UserID
|
|
|
|
|
|
} else if sender.IsTG() {
|
|
|
|
|
|
ck.Telegram = sender.UserID
|
2021-08-15 09:48:05 +08:00
|
|
|
|
}
|
2021-08-19 21:51:45 +08:00
|
|
|
|
if HasKey(ck.PtKey) {
|
2021-08-28 09:52:25 +08:00
|
|
|
|
sender.Reply(fmt.Sprintf("重复提交"))
|
2021-08-15 09:48:05 +08:00
|
|
|
|
} else {
|
2021-08-19 21:51:45 +08:00
|
|
|
|
if nck, err := GetJdCookie(ck.PtPin); err == nil {
|
|
|
|
|
|
nck.InPool(ck.PtKey)
|
|
|
|
|
|
msg := fmt.Sprintf("更新账号,%s", ck.PtPin)
|
2021-09-06 16:05:55 +08:00
|
|
|
|
if sender.IsQQ() {
|
|
|
|
|
|
ck.Update(QQ, ck.QQ)
|
2021-09-04 18:50:52 +08:00
|
|
|
|
}
|
2021-09-07 09:08:23 +08:00
|
|
|
|
sender.Reply(fmt.Sprintf(msg))
|
2021-08-19 21:51:45 +08:00
|
|
|
|
(&JdCookie{}).Push(msg)
|
|
|
|
|
|
logs.Info(msg)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if Cdle {
|
|
|
|
|
|
ck.Hack = True
|
|
|
|
|
|
}
|
|
|
|
|
|
NewJdCookie(&ck)
|
2021-09-07 00:27:14 +08:00
|
|
|
|
msg := fmt.Sprintf("添加账号,账号名:%s", ck.PtPin)
|
2021-09-06 16:05:55 +08:00
|
|
|
|
if sender.IsQQ() {
|
|
|
|
|
|
ck.Update(QQ, ck.QQ)
|
2021-09-04 18:50:52 +08:00
|
|
|
|
}
|
2021-09-07 09:08:23 +08:00
|
|
|
|
sender.Reply(fmt.Sprintf(msg))
|
2021-08-19 21:51:45 +08:00
|
|
|
|
logs.Info(msg)
|
2021-08-19 10:40:42 +08:00
|
|
|
|
}
|
2021-08-15 09:48:05 +08:00
|
|
|
|
}
|
2021-08-19 22:12:01 +08:00
|
|
|
|
} else {
|
2021-09-04 18:50:52 +08:00
|
|
|
|
sender.Reply(fmt.Sprintf("无效,东币-1,余额%d", RemCoin(sender.UserID, 1)))
|
2021-08-15 09:48:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
Save <- &JdCookie{}
|
|
|
|
|
|
}()
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
2021-08-28 09:52:25 +08:00
|
|
|
|
o := findShareCode(msg)
|
|
|
|
|
|
if o != "" {
|
2021-08-15 09:48:05 +08:00
|
|
|
|
return "导入互助码成功"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for k, v := range replies {
|
|
|
|
|
|
if regexp.MustCompile(k).FindString(msg) != "" {
|
2021-08-28 09:52:25 +08:00
|
|
|
|
if strings.Contains(msg, "妹") && time.Now().Unix()%10 == 0 {
|
|
|
|
|
|
v = "https://pics4.baidu.com/feed/d833c895d143ad4bfee5f874cfdcbfa9a60f069b.jpeg?token=8a8a0e1e20d4626cd31c0b838d9e4c1a"
|
|
|
|
|
|
}
|
2021-08-15 09:48:05 +08:00
|
|
|
|
if regexp.MustCompile(`^https{0,1}://[^\x{4e00}-\x{9fa5}\n\r\s]{3,}$`).FindString(v) != "" {
|
|
|
|
|
|
url := v
|
|
|
|
|
|
rsp, err := httplib.Get(url).Response()
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
2021-08-20 10:04:34 +08:00
|
|
|
|
ctp := rsp.Header.Get("content-type")
|
2021-08-20 11:10:34 +08:00
|
|
|
|
if ctp == "" {
|
|
|
|
|
|
rsp.Header.Get("Content-Type")
|
|
|
|
|
|
}
|
|
|
|
|
|
if strings.Contains(ctp, "text") || strings.Contains(ctp, "json") {
|
2021-08-20 10:04:34 +08:00
|
|
|
|
data, _ := ioutil.ReadAll(rsp.Body)
|
|
|
|
|
|
return string(data)
|
|
|
|
|
|
}
|
2021-08-15 09:48:05 +08:00
|
|
|
|
return rsp
|
|
|
|
|
|
}
|
|
|
|
|
|
return v
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|