新增插件 摸鱼人日历 (#133)

*  新增插件 摸鱼人日历

*  新增插件 摸鱼人日历

* ✏️ 优化插件 摸鱼人日历
This commit is contained in:
Kanri 2022-02-23 16:36:23 +08:00 committed by GitHub
parent 48deaf3aca
commit 8c40293fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 151 additions and 0 deletions

View File

@ -139,6 +139,9 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
- **摸鱼** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu"` - **摸鱼** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu"`
- [x] /启用 moyu - [x] /启用 moyu
- [x] /禁用 moyu - [x] /禁用 moyu
- **摸鱼人日历** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu_calendar"`
- [x] /启用 moyucalendar
- [x] /禁用 moyucalendar
- **涩图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime"` - **涩图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime"`
- [x] 来份[涩图/二次元/风景/车万] - [x] 来份[涩图/二次元/风景/车万]
- [x] 添加[涩图/二次元/风景/车万][P站图片ID] - [x] 添加[涩图/二次元/风景/车万][P站图片ID]

View File

@ -79,6 +79,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu_calendar" // 摸鱼人日历
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativesetu" // 本地涩图 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativesetu" // 本地涩图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativewife" // 本地老婆 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativewife" // 本地老婆

View File

@ -0,0 +1,147 @@
// Package moyucalendar 摸鱼人日历
package moyucalendar
import (
"bufio"
"errors"
"io"
"io/ioutil"
"net/http"
"regexp"
"strings"
"time"
control "github.com/FloatTech/zbputils/control"
"github.com/fumiama/cron"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/FloatTech/zbputils/control/order"
)
func init() {
control.Register("moyucalendar", order.AcquirePrio(), &control.Options{
DisableOnDefault: true,
Help: "摸鱼人日历\n" +
"- /启用 moyucalendar\n" +
"- /禁用 moyucalendar",
})
// 定时任务每天8点执行一次
c := cron.New()
_, err := c.AddFunc("* 8 * * *", func() {
m, ok := control.Lookup("moyucalendar")
if !ok {
return
}
image, err := crew()
if err != nil {
return
}
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
for _, g := range ctx.GetGroupList().Array() {
grp := g.Get("group_id").Int()
if m.IsEnabledIn(grp) {
ctx.SendGroupMessage(grp, []message.MessageSegment{message.Image(image)})
}
}
return true
})
})
if err == nil {
c.Start()
}
}
var newest = regexp.MustCompile(`uigs="account_article_0" href="(/link.+?)">`)
var weixin = regexp.MustCompile(`url \+= '(.+)';`)
var calendar = regexp.MustCompile(`data-src="(.{0,300})" data-type="png" data-w="540"`)
func crew() (string, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://weixin.sogou.com/weixin?type=1&s_from=input&query=%E6%91%B8%E9%B1%BC%E4%BA%BA%E6%97%A5%E5%8E%86", nil)
if err != nil {
return "", err
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", errors.New("status not ok")
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
match := newest.FindStringSubmatch(string(b))
if len(match) < 2 {
return "", errors.New("newest not found")
}
var link = "https://weixin.sogou.com" + match[1]
reqa, err := http.NewRequest("GET", link, nil)
if err != nil {
return "", err
}
reqa.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36")
var cookies = make([]string, 0, 4)
for _, cookie := range resp.Cookies() {
if cookie.Name != "ABTEST" && cookie.Name != "SNUID" && cookie.Name != "IPLOC" && cookie.Name != "SUID" {
continue
}
cookies = append(cookies, cookie.Name+"="+cookie.Value)
}
reqa.Header.Set("Cookie", strings.Join(cookies, "; "))
respa, err := client.Do(reqa)
if err != nil {
return "", err
}
defer respa.Body.Close()
if respa.StatusCode != http.StatusOK {
return "", errors.New("status not ok")
}
br := bufio.NewReader(respa.Body)
var weixinurl = make([]string, 0)
for {
b, _, err := br.ReadLine()
if err == io.EOF {
break
}
if err != nil {
return "", err
}
matcha := weixin.FindStringSubmatch(string(b))
if len(matcha) < 2 {
continue
}
weixinurl = append(weixinurl, strings.ReplaceAll(matcha[1], "@", ""))
}
if len(weixinurl) == 0 {
return "", errors.New("weixin url not found")
}
reqw, err := http.NewRequest("GET", strings.Join(weixinurl, ""), nil)
reqa.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36")
if err != nil {
return "", err
}
respw, err := client.Do(reqw)
if err != nil {
return "", err
}
defer respw.Body.Close()
if respw.StatusCode != http.StatusOK {
return "", errors.New("status not ok")
}
bw, _ := ioutil.ReadAll(respw.Body)
today := regexp.MustCompile(time.Now().Format("2006-01-02"))
if !today.Match(bw) {
return "", errors.New("calendar not found")
}
matchw := calendar.FindStringSubmatch(string(bw))
if len(matchw) < 2 {
return "", errors.New("calendar not found")
}
return matchw[1], nil
}