Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from bypanghu/master
Browse files Browse the repository at this point in the history
 新增疫情信息查询
  • Loading branch information
mcoo authored Jun 3, 2021
2 parents 040d135 + a3f3cda commit 9d91169
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Bili/bili.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func NewManager() (m Manager) {
m.ups[mid] = Up{
Name: v1.Name,
Created: v1.Created,
UserId: v1.UserId,
Groups: []int64{groupId},
UserId: v1.UserId,
}
Expand All @@ -373,6 +374,7 @@ func NewManager() (m Manager) {
m.fanjus[mid] = Fanju{
Title: v1.Title,
Id: v1.Id,
UserId: v1.UserId,
Groups: []int64{groupId},
UserId: v1.UserId,
}
Expand Down
93 changes: 73 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (
"OPQBot-QQGroupManager/draw"
"OPQBot-QQGroupManager/githubManager"
"OPQBot-QQGroupManager/methods"
"OPQBot-QQGroupManager/utils"
"OPQBot-QQGroupManager/yiqing"
"embed"
"encoding/base64"
"encoding/json"
"fmt"
_ "github.com/go-playground/webhooks/v6/github"
"github.com/mcoo/requests"
"io/fs"
"io/ioutil"
"log"
"math/rand"
"net/http"
Expand Down Expand Up @@ -62,7 +66,7 @@ func main() {
Code string
}{}
VerifyLock := sync.Mutex{}
c := NewBotCronManager()
c := utils.NewBotCronManager()
c.Start()
bi := bili.NewManager()
c.AddJob(-1, "Bili", "*/5 * * * *", func() {
Expand Down Expand Up @@ -134,6 +138,31 @@ func main() {
}
}
})
c.AddJob(-1, "Yiqing" ,"* * 8,18 * * ? " , func() {
client := &http.Client{}
baseUrl := "https://m.sm.cn/api/rest?method=Huoshenshan.local"
req ,err := http.NewRequest("GET",baseUrl,nil)
req.Header.Add("User-Agent","Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1")
req.Header.Add("referer" , "https://broccoli.uc.cn/" )
if(err !=nil){
panic(err)
}
response, _ := client.Do(req)
defer response.Body.Close()
s,err:=ioutil.ReadAll(response.Body)
var res yiqing.YiqingRes
json.Unmarshal(s, &res)
ups := fmt.Sprintf("疫情报告")
ups += fmt.Sprintf("%s-%s\n全国单日报告%s\n" ,res.Title ,res.Time,res.MainReport.Report)
ups += fmt.Sprintf("[表情190][表情190][表情190]信息总览[表情190][表情190][表情190]\n")
ups += fmt.Sprintf("[表情145]全国累计确诊%s个昨日新增%s个\n",res.ContryData.SureCnt,res.ContryData.YstCureCnt)
ups += fmt.Sprintf("[表情145]全国现存确诊%s个昨日新增%s个\n",res.ContryData.RestSureCnt,res.ContryData.RestSureCntIncr)
ups += fmt.Sprintf("[表情145]累计输入确诊%s个\n",res.ContryData.InputCnt)
ups += fmt.Sprintf("[表情145]全国累计治愈%s个昨日新增%s个\n",res.ContryData.CureCnt,res.ContryData.YstCureCnt)
ups += fmt.Sprintf("[表情66][表情66][表情66]疫情当下,请注意保护安全")
b.SendGroupTextMsg(-1, fmt.Sprintf(ups))
fmt.Println(ups)
})
err = b.AddEvent(OPQBot.EventNameOnFriendMessage, func(qq int64, packet *OPQBot.FriendMsgPack) {
s := b.Session.SessionStart(packet.FromUin)
if v, err := s.GetString("github"); err == nil {
Expand Down Expand Up @@ -191,20 +220,20 @@ func main() {
})
return
}
if m, err := regexp.MatchString(c.ShutUpWord, packet.Content); err != nil {
log.Println(err)
return
} else if m {
err := b.ReCallMsg(packet.FromGroupID, packet.MsgRandom, packet.MsgSeq)
if err != nil {
log.Println(err)
}
err = b.SetForbidden(1, c.ShutUpTime, packet.FromGroupID, packet.FromUserID)
if err != nil {
log.Println(err)
}
return
}
//if m, err := regexp.MatchString(c.ShutUpWord, packet.Content); err != nil {
// log.Println(err)
// return
//} else if m {
// err := b.ReCallMsg(packet.FromGroupID, packet.MsgRandom, packet.MsgSeq)
// if err != nil {
// log.Println(err)
// }
// err = b.SetForbidden(1, c.ShutUpTime, packet.FromGroupID, packet.FromUserID)
// if err != nil {
// log.Println(err)
// }
// return
//}
if v, _ := regexp.MatchString(`[0-9]{6}`, packet.Content); v {
VerifyLock.Lock()
if v1, ok := VerifyNum[strconv.FormatInt(packet.FromUserID, 10)+"|"+strconv.FormatInt(packet.FromGroupID, 10)]; ok {
Expand Down Expand Up @@ -521,8 +550,8 @@ func main() {
b.SendGroupTextMsg(packet.FromGroupID, "本群没有订阅UP主")
return
}
for mid, v1 := range c.BiliUps {
ups += fmt.Sprintf("%d - %s - 订阅者 - %d\n", mid, v1.Name, v1.UserId)
for mid, v1 := range c.BiliUps {
ups += fmt.Sprintf("%d - %s -订阅者:%d\n", mid, v1.Name, v1.UserId)
}
b.SendGroupTextMsg(packet.FromGroupID, ups)

Expand Down Expand Up @@ -577,10 +606,34 @@ func main() {
return
}
for mid, v1 := range c.Fanjus {
ups += fmt.Sprintf("%d - %s-订阅用户为:%d\n", mid, v1.Title, v1.UserId)
ups += fmt.Sprintf("%d - %s-订阅用户为:%d \n", mid, v1.Title,v1.UserId)
}
b.SendGroupTextMsg(packet.FromGroupID, ups)

}
if packet.Content == "疫情信息"{
b.SendGroupTextMsg(packet.FromGroupID, "正在查找信息")
client := &http.Client{}
baseUrl := "https://m.sm.cn/api/rest?method=Huoshenshan.local"
req ,err := http.NewRequest("GET",baseUrl,nil)
req.Header.Add("User-Agent","Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1")
req.Header.Add("referer" , "https://broccoli.uc.cn/" )
if(err !=nil){
panic(err)
}
response, _ := client.Do(req)
defer response.Body.Close()
s,err:=ioutil.ReadAll(response.Body)
var res yiqing.YiqingRes
json.Unmarshal(s, &res)
ups := fmt.Sprintf("%s-%s\n全国单日报告%s\n" ,res.Title ,res.Time,res.MainReport.Report)
ups += fmt.Sprintf("[表情190][表情190][表情190]信息总览[表情190][表情190][表情190]\n")
ups += fmt.Sprintf("[表情145]全国累计确诊%s个昨日新增%s个\n",res.ContryData.SureCnt,res.ContryData.YstCureCnt)
ups += fmt.Sprintf("[表情145]全国现存确诊%s个昨日新增%s个\n",res.ContryData.RestSureCnt,res.ContryData.RestSureCntIncr)
ups += fmt.Sprintf("[表情145]累计输入确诊%s个\n",res.ContryData.InputCnt)
ups += fmt.Sprintf("[表情145]全国累计治愈%s个昨日新增%s个\n",res.ContryData.CureCnt,res.ContryData.YstCureCnt)
ups += fmt.Sprintf("[表情66][表情66][表情66]疫情当下,请注意保护安全")
b.SendGroupTextMsg(packet.FromGroupID, fmt.Sprintf(ups))
fmt.Println(ups)
}
})
if err != nil {
Expand Down Expand Up @@ -673,7 +726,7 @@ func main() {
Config.Lock.Lock()
sess = sessions.New(sessions.Config{Cookie: "OPQWebSession"})
if Config.CoreConfig.OPQWebConfig.CSRF == "" {
Config.CoreConfig.OPQWebConfig.CSRF = RandomString(32)
Config.CoreConfig.OPQWebConfig.CSRF = utils.RandomString(32)
err := Config.Save()
if err != nil {
log.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion update.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"OPQBot-QQGroupManager"
"github.com/mcoo/requests"
"log"
"runtime"
Expand Down Expand Up @@ -93,7 +94,7 @@ func CheckUpdate() {
log.Println(err)
return
}
if !strings.HasSuffix(result.TagName, version) {
if !strings.HasSuffix(result.TagName, main.version) {
log.Println("检测到更新欧~ " + result.TagName)
if result.Prerelease {
log.Println("注意最新版本为预发行版本")
Expand Down
2 changes: 1 addition & 1 deletion cron.go → utils/cron.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion tools.go → utils/tools.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import "math/rand"

Expand Down
46 changes: 46 additions & 0 deletions yiqing/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package yiqing

type YiqingRes struct {
Title string `json:"title"`
Time string `json:"time"`
IncrTime string `json:"incrTime"`
logcation Logcation `json:"logcation"`
Colums []Colums `json:"colums"`
MainReport struct{
Id int `json:"id"`
Area string `json:"area"`
Report string `json:"report"`
Dateline string `json:"dateline"`
Date int64 `json:"date"`
} `json:"mainReport"`
ContryData struct{
SureCnt string `json:"sure_cnt"`
SureNewCnt string `json:"sure_new_cnt"`
RestSureCnt string `json:"rest_sure_cnt"`
RestSureCntIncr string `json:"rest_sure_cnt_incr"`
InputCnt string `json:"input_cnt"`
HiddenCnt string `json:"hidden_cnt"`
HiddenCntIncr string `json:"hidden_cnt_incr"`
CureCnt string `json:"cure_cnt"`
YstCureCnt string `json:"yst_cure_cnt"`
YstDieCnt string `json:"yst_die_cnt"`
YstLikeCnt string `json:"yst_like_cnt"`
YstSureCnt string `json:"yst_sure_cnt"`
YstSureHid string `json:"yst_sure_hid"`
}
}

type Colums struct {
Title string `json:"title"`
List []List `json:"list"`
}

type List struct {
Current int64 `json:"current"`
Incr string `json:"incr"`
}

type Logcation struct{
Province string `json:"province"`
City string `json:"city"`
}

0 comments on commit 9d91169

Please sign in to comment.