Skip to content

Commit

Permalink
增加jx 818推送
Browse files Browse the repository at this point in the history
  • Loading branch information
Cha0sIDL committed Jul 18, 2023
1 parent 55fed7b commit fa9a2fd
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 24 deletions.
10 changes: 5 additions & 5 deletions plugin/arknights/daily.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func daily(ctx *zero.Ctx) {
result.ScrollIntoViewIfNeeded()
box, _ := result.BoundingBox()
PageScreenshotOptions := playwright.PageScreenshotOptions{
Clip: &playwright.PageScreenshotOptionsClip{
X: playwright.Float(float64(box.X - 25)),
Y: playwright.Float(float64(box.Y - 55)),
Width: playwright.Float(float64(box.Width - 130)),
Height: playwright.Float(float64(box.Width + 70)),
Clip: &playwright.Rect{
X: box.X - 25,
Y: box.Y - 55,
Width: box.Width - 130,
Height: box.Width + 70,
},
}
b, err := page.Screenshot(PageScreenshotOptions)
Expand Down
10 changes: 5 additions & 5 deletions plugin/baidu/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func screenshot(url string) []byte {
log.Errorf("could not goto: %v", err)
}
Clip := util.PageScreenshotOptionsClip(
playwright.PageScreenshotOptionsClip{
X: playwright.Float(10),
Y: playwright.Float(0),
Width: playwright.Float(1500),
Height: playwright.Float(1400),
playwright.Rect{
X: 10,
Y: 0,
Width: 1500,
Height: 1400,
})
if pic, err = page.Screenshot(playwright.PageScreenshotOptions{
Clip: Clip,
Expand Down
114 changes: 104 additions & 10 deletions plugin/jx3/jx3.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ func init() {
}
})
c.AddFunc("@every 30s", func() { //nolint:errcheck
controls := jdb.isEnable()
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
var grpList []GroupList
controls := jdb.isEnable()
for _, g := range ctx.GetGroupList().Array() {
grp := g.Get("group_id").Int()
if val, ok := controls[grp]; ok {
Expand All @@ -185,8 +185,8 @@ func init() {
})
c.AddFunc("@every 2m", func() { //nolint:errcheck
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
var grpList []GroupList
controls := jdb.isEnable()
var grpList []GroupList
for _, g := range ctx.GetGroupList().Array() {
grp := g.Get("group_id").Int()
if val, ok := controls[grp]; ok {
Expand All @@ -209,6 +209,7 @@ func init() {
go startChatWs(chat)
}
}
go startWs()
datapath := file.BOTPATH + "/" + en.DataFolder()
en.OnFullMatchGroup([]string{"日常", "日常任务"}, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
Expand Down Expand Up @@ -536,9 +537,9 @@ func init() {
return
}
page, err := browser.NewPage(playwright.BrowserNewContextOptions{
Viewport: &playwright.BrowserNewContextOptionsViewport{
Width: playwright.Int(1920),
Height: playwright.Int(1080),
Viewport: &playwright.ViewportSize{
Width: 1920,
Height: 1080,
},
})
if err != nil {
Expand All @@ -557,11 +558,11 @@ func init() {
result.ScrollIntoViewIfNeeded() //nolint:errcheck
box, _ := result.BoundingBox()
PageScreenshotOptions := playwright.PageScreenshotOptions{
Clip: &playwright.PageScreenshotOptionsClip{
X: playwright.Float(float64(box.X)),
Y: playwright.Float(float64(box.Y)),
Width: playwright.Float(float64(box.Width)),
Height: playwright.Float(float64(box.Width)),
Clip: &playwright.Rect{
X: box.X,
Y: box.Y,
Width: box.Width,
Height: box.Width,
},
}
b, err := page.Screenshot(PageScreenshotOptions)
Expand Down Expand Up @@ -1052,6 +1053,99 @@ func wujia(ctx *zero.Ctx, datapath string, control int8) {
}
}

//func feiNiuWuJia(ctx *zero.Ctx, datapath string) {
// var price = make(map[string][]map[string]interface{})
// commandPart := util.SplitSpace(ctx.State["args"].(string))
// if len(commandPart) != 1 {
// ctx.SendChain(message.Text("参数输入有误!\n" + "物价 牛金"))
// return
// }
// name := commandPart[0]
// if hei, ok := controlCd[name]; ok && (carbon.Now().Timestamp()-hei.last) < 86400 {
// ctx.SendChain(message.Image(hei.fileName))
// } else {
// goodURL := fmt.Sprintf("https://12897x770b.oicp.vip/m/bj/getsearch?qy=%s&gjc=%s&xl=%s&lb=%s&page=1&cxpara=hs", goUrl.QueryEscape("全区全服"), goUrl.QueryEscape(name), goUrl.QueryEscape("全部系列"), goUrl.QueryEscape("全部类别"))
// rspData, err := web.RequestDataWith(NewTimeOutDefaultClient(), goodURL, "GET", "", web.RandUA(), nil)
// switch {
// case err != nil:
// ctx.SendChain(message.Text("出错了联系管理员看看吧", err))
// return
// case len(gjson.ParseBytes(rspData).Array()) == 0:
// ctx.SendChain(message.Text("没有查找到", name, "请重新输入后重试"))
// return
// }
//
// if len(gjson.Get(binutils.BytesToString(rspData), "data").Array()) == 0 { // 如果输入无数据则请求
// searchURL := fmt.Sprintf("https://www.j3price.top:8088/black-api/api/outward/search?step=0&page=1&size=20&name=%s", goUrl.QueryEscape(name))
// searchData, err := web.PostData(searchURL, "application/x-www-form-urlencoded", nil)
// searchList := gjson.Get(binutils.BytesToString(searchData), "data.list").Array()
// if err != nil || len(searchList) == 0 {
// ctx.SendChain(message.Text(fmt.Sprintf("没有找到%s,你是不是乱输的哦~", name)))
// return
// }
// msg := "你可能找的是以下结果:\n"
// for _, s := range searchList {
// msg += s.Get("outwardName").String() + "\n"
// }
// msg += "自动帮你查询:" + searchList[0].Get("outwardAlias").String()
// ctx.SendChain(message.Text(msg))
// ctx.State["args"] = searchList[0].Get("outwardName").String()
// wujia(ctx, datapath)
// return
// }
// goodid := gjson.Get(binutils.BytesToString(rspData), "data.0.id").Int() // 获得商品id
// infoURL := fmt.Sprintf("https://www.j3price.top:8088/black-api/api/common/search/index/prices?regionId=1&outwardId=%d", goodid)
// wuJiaData, err := web.PostData(infoURL, "application/x-www-form-urlencoded", nil)
// json.Unmarshal(wuJiaData, &data) //nolint:errcheck
// if err != nil || data.State != 0 {
// ctx.SendChain(message.Text("出错了联系管理员看看吧"))
// return
// }
// wujiaPicURL := fmt.Sprintf("https://www.j3price.top:8088/black-api/api/common/search/index/outward?regionId=1&imageLimit=1&outwardId=%d", goodid)
// wujiaPic, err := RequestDataWith(wujiaPicURL)
// if err != nil {
// ctx.SendChain(message.Text("Err:", err))
// return
// }
// for _, rprice := range data.Data.Other {
// if server, ok := xiaoheiIndx[rprice.Prices.Region]; ok {
// price[server] = append(price[server], map[string]interface{}{
// "date": rprice.Prices.TradeTime,
// "server": rprice.Prices.Server,
// "value": fmt.Sprintf("%.2f", rprice.Prices.Price),
// "sale": rprice.Prices.SaleCode,
// })
// }
// }
// for _, rprice := range data.Data.Prices {
// if server, ok := xiaoheiIndx[rprice.Region]; ok {
// price[server] = append(price[server], map[string]interface{}{
// "date": rprice.TradeTime,
// "server": rprice.Server,
// "value": fmt.Sprintf("%.2f", rprice.Price),
// "sale": rprice.SaleCode,
// })
// }
// }
// lineHTML := priceData2line(price, datapath)
// html := util.Template2html("price.html", map[string]interface{}{
// "image": gjson.Get(binutils.BytesToString(wujiaPic), "data.images.0.image"),
// "name": name,
// "data": price,
// })
// finName, err := util.HTML2pic(datapath, name+util.TodayFileName(), html+lineHTML)
// if err != nil {
// ctx.SendChain(message.Text("Err:", err))
// return
// }
// controlCd[name] = cd{
// last: carbon.Now().Timestamp(),
// fileName: "file:///" + finName,
// }
// ctx.SendChain(message.Image("file:///" + finName))
// }
//}

func updateTalk() error {
url := "https://cms.jx3box.com/api/cms/post/jokes?per=%d&page=%d"
var page int64 = 1
Expand Down
83 changes: 83 additions & 0 deletions plugin/jx3/jx3api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package jx3

// JxApi Ws
import (
"github.com/FloatTech/floatbox/process"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"time"

"github.com/RomiChan/websocket"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
)

type wsClient struct {
url string // ws连接地址
conn *websocket.Conn
}

func startWs() {
ws := &wsClient{
url: "wss://socket.nicemoe.cn",
}
ws.connect()
ws.listen()
}

func (ws *wsClient) connect() {
var err error
RETRY:
conn, res, err := websocket.DefaultDialer.Dial(ws.url, nil)
for err != nil {
log.Warnf("连接JXApi Websocket服务器时出现错误: %v", err)
time.Sleep(2 * time.Second) // 等待两秒后重新连接
goto RETRY
}
ws.conn = conn
defer res.Body.Close()
log.Infof("连接JXApi Websocket服务器成功")
}

func (ws *wsClient) listen() {
for {
t, payload, err := ws.conn.ReadMessage()
if err != nil { // reconnect
log.Warn("JXApi Websocket服务器连接断开...")
time.Sleep(time.Millisecond * time.Duration(3))
ws.connect()
}
if t == websocket.TextMessage {
rsp := gjson.Parse(helper.BytesToString(payload))
log.Println("收到JXApi推送", helper.BytesToString(payload))
sendNotice(rsp)
}
}
}

func sendNotice(payload gjson.Result) {
var rsp []message.MessageSegment
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
controls := jdb.isEnable()
for _, g := range ctx.GetGroupList().Array() {
grp := g.Get("group_id").Int()
if _, ok := controls[grp]; ok {
switch payload.Get("action").Int() {

Check failure on line 66 in plugin/jx3/jx3api.go

View workflow job for this annotation

GitHub Actions / lint

singleCaseSwitch: should rewrite switch statement to if statement (gocritic)
case 2004:
rsp =
[]message.MessageSegment{
message.Text("【818】:\n"),
message.Text(payload.Get("data.title").String() + "\n" +
payload.Get("data.url").String() + "\n" + payload.Get("data.date").String()),
}
}
if len(rsp) != 0 {
ctx.SendGroupMessage(grp, rsp)
process.SleepAbout1sTo2s()
}
}
}
return true
})
}
2 changes: 1 addition & 1 deletion util/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// ScreenShot 截取浏览器
func ScreenShot(url string, option ...playwright.PageScreenshotOptionsClip) []byte {
func ScreenShot(url string, option ...playwright.Rect) []byte {
pw, err := playwright.Run()
var pic []byte
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions util/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Template2html(templateName string, arg pongo2.Context) string {
}

// HTML2pic html转图片
func HTML2pic(dataPath string, fileName string, html string, clip ...*playwright.PageScreenshotOptionsClip) (finName string, err error) {
func HTML2pic(dataPath string, fileName string, html string, clip ...*playwright.Rect) (finName string, err error) {
pw, err := playwright.Run()
finName = ""
if err != nil {
Expand Down Expand Up @@ -67,7 +67,7 @@ func HTML2pic(dataPath string, fileName string, html string, clip ...*playwright
return finName, err
}

// PageScreenshotOptionsClip 返回PageScreenshotOptionsClip的指针
func PageScreenshotOptionsClip(v playwright.PageScreenshotOptionsClip) *playwright.PageScreenshotOptionsClip {
// PageScreenshotOptionsClip 返回Rect的指针
func PageScreenshotOptionsClip(v playwright.Rect) *playwright.Rect {
return &v
}

0 comments on commit fa9a2fd

Please sign in to comment.