mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-10 01:00:24 +00:00
Compare commits
13 Commits
v1.2.2-bet
...
v1.2.2-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
596c75eeca | ||
|
|
67a493ee84 | ||
|
|
f9c7d9419e | ||
|
|
1a1a006283 | ||
|
|
fd85ce0923 | ||
|
|
5ff9069ff2 | ||
|
|
4ad7ff7971 | ||
|
|
a9f98763c4 | ||
|
|
3b637fad78 | ||
|
|
f202797964 | ||
|
|
242d780048 | ||
|
|
bf23364097 | ||
|
|
7eaac7a20b |
@@ -96,7 +96,7 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
|
||||
- [ ] 撤回[@xxx] [xxx]
|
||||
- [ ] 警告[@xxx]
|
||||
- [x] run[xxx]
|
||||
- 注:使用gist加群自动审批,请在群介绍添加以下说明,同时开启`需要回答问题并由管理员审核`:加群请在github新建一个gist,其文件名为本群群号的字符串的md5,内容为一行,是当前unix时间戳。然后请将您的用户名和gist哈希按照username/gisthash的格式填写到回答即可。
|
||||
- 注:使用gist加群自动审批,请在群介绍添加以下说明,同时开启`需要回答问题并由管理员审核`:加群请在github新建一个gist,其文件名为本群群号的字符串的md5(小写),内容为一行,是当前unix时间戳(10分钟内有效)。然后请将您的用户名和gist哈希(小写)按照username/gisthash的格式填写到回答即可。
|
||||
- **GitHub仓库搜索** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_github"`
|
||||
- [x] >github [xxx]
|
||||
- [x] >github -p [xxx]
|
||||
@@ -176,7 +176,7 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
|
||||
- 注:由于需要科学,默认注释。
|
||||
- **AIfalse** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false"`
|
||||
- [x] 查询计算机当前活跃度: [检查身体|自检|启动自检|系统状态]
|
||||
- [x] 清理缓存
|
||||
- [x] 清理缓存 (仅适用于 gocq 且需要 bot 的运行目录和 gocq 相同)
|
||||
- [ ] 简易语音
|
||||
- [ ] 爬图合成 [@xxx]
|
||||
- **抽wife** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nativewife"`
|
||||
@@ -211,10 +211,12 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
|
||||
- [x] vtb语录
|
||||
- [x] 随机vtb
|
||||
- **书评** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review"`
|
||||
- [x] 书评[关键字]
|
||||
- [x] 书评[xxx]
|
||||
- [x] 随机书评
|
||||
- **coser** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" `
|
||||
- [x] coser
|
||||
- **novel** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_novel" `
|
||||
- [x] 小说[xxx]
|
||||
- **TODO...**
|
||||
|
||||
## 使用方法
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
// Package webctrl
|
||||
/*
|
||||
* 一个用户webui的包,里面包含了webui所需的所有内容
|
||||
*/
|
||||
// Package webctrl 包含 webui 所需的所有内容
|
||||
package webctrl
|
||||
|
||||
import (
|
||||
|
||||
4
go.mod
4
go.mod
@@ -3,9 +3,10 @@ module github.com/FloatTech/ZeroBot-Plugin
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/FloatTech/AnimeAPI v1.1.10
|
||||
github.com/FloatTech/AnimeAPI v1.1.11
|
||||
github.com/FloatTech/ZeroBot-Plugin-Gif v0.2.4
|
||||
github.com/FloatTech/bot-manager v1.0.1-0.20211112011524-85b9895271ed
|
||||
github.com/antchfx/htmlquery v1.2.3
|
||||
github.com/corona10/goimagehash v1.0.3
|
||||
github.com/fogleman/gg v1.3.0
|
||||
github.com/fumiama/cron v1.3.0
|
||||
@@ -24,4 +25,5 @@ require (
|
||||
github.com/tidwall/gjson v1.12.1
|
||||
github.com/wdvxdr1123/ZeroBot v1.4.1
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
|
||||
golang.org/x/text v0.3.6
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,6 +1,6 @@
|
||||
github.com/FloatTech/AnimeAPI v1.1.9/go.mod h1:CC+vF30UGBlcIUxwFOcXIEHoJ4r7c5x2iLQsnUCVdDI=
|
||||
github.com/FloatTech/AnimeAPI v1.1.10 h1:fYkv65P1HBukHi3GpzYulGx/xLshEL9635QXALDryf0=
|
||||
github.com/FloatTech/AnimeAPI v1.1.10/go.mod h1:CC+vF30UGBlcIUxwFOcXIEHoJ4r7c5x2iLQsnUCVdDI=
|
||||
github.com/FloatTech/AnimeAPI v1.1.11 h1:uuV4v5qweh0mI0E2KMiG5XGt0pKboV/EFAlIfSJxIi8=
|
||||
github.com/FloatTech/AnimeAPI v1.1.11/go.mod h1:CC+vF30UGBlcIUxwFOcXIEHoJ4r7c5x2iLQsnUCVdDI=
|
||||
github.com/FloatTech/ZeroBot-Plugin v1.1.5/go.mod h1:kWuUARvU7gs4xLggi8Sy37ja2GRL6k0X6kewe5TiZRs=
|
||||
github.com/FloatTech/ZeroBot-Plugin-Gif v0.2.4 h1:WW0BmmLLqAg+m6qGkrKbsfSIm91fkj3/udt3R7Myodo=
|
||||
github.com/FloatTech/ZeroBot-Plugin-Gif v0.2.4/go.mod h1:W7ag6hml1pZTNzRXKU74OMr6rS8awQKSU+o2g7Gj4O0=
|
||||
|
||||
1
main.go
1
main.go
@@ -38,6 +38,7 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_novel" // 铅笔小说网搜索
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji" // 浅草寺求签
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_reborn" // 投胎
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定
|
||||
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
datapath = file.BOT_PATH + "/data/acgimage/"
|
||||
datapath = file.BOTPATH + "/data/acgimage/"
|
||||
cacheuri = "file:///" + datapath + "cache"
|
||||
// r18有一定保护,一般不会发出图片
|
||||
randapi = "&loli=true&r18=true"
|
||||
|
||||
@@ -58,7 +58,10 @@ func diskPercent() string {
|
||||
msg := ""
|
||||
for _, p := range parts {
|
||||
diskInfo, _ := disk.Usage(p.Mountpoint)
|
||||
msg += fmt.Sprintf("\n - %s(%dM) %d%%", p.Mountpoint, diskInfo.Total/1024/1024, uint(math.Round(diskInfo.UsedPercent)))
|
||||
pc := uint(math.Round(diskInfo.UsedPercent))
|
||||
if pc > 0 {
|
||||
msg += fmt.Sprintf("\n - %s(%dM) %d%%", p.Mountpoint, diskInfo.Total/1024/1024, pc)
|
||||
}
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package plugin_coser
|
||||
// Package coser images
|
||||
package coser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
cachedir = file.BOT_PATH + "/data/hs/"
|
||||
cachedir = file.BOTPATH + "/data/hs/"
|
||||
reqconf = [...]string{"GET", "https://hs.fbigame.com",
|
||||
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36"}
|
||||
)
|
||||
|
||||
@@ -493,8 +493,8 @@ func init() { // 插件主体
|
||||
ctx.Send(cmd)
|
||||
})
|
||||
// 根据 gist 自动同意加群
|
||||
// 加群请在github新建一个gist,其文件名为本群群号的字符串的md5,内容为一行,是当前unix时间戳。
|
||||
// 然后请将您的用户名和gist哈希按照username/gisthash的格式填写到回答即可。
|
||||
// 加群请在github新建一个gist,其文件名为本群群号的字符串的md5(小写),内容为一行,是当前unix时间戳(10分钟内有效)。
|
||||
// 然后请将您的用户名和gist哈希(小写)按照username/gisthash的格式填写到回答即可。
|
||||
engine.OnRequest().SetBlock(false).FirstPriority().Handle(func(ctx *zero.Ctx) {
|
||||
/*if ctx.Event.RequestType == "friend" {
|
||||
ctx.SetFriendAddRequest(ctx.Event.Flag, true, "")
|
||||
@@ -505,6 +505,10 @@ func init() { // 插件主体
|
||||
// gist 内容是当前 uinx 时间戳,在 10 分钟内视为有效
|
||||
ans := ctx.Event.Comment[strings.Index(ctx.Event.Comment, "答案:")+len("答案:"):]
|
||||
divi := strings.Index(ans, "/")
|
||||
if divi <= 0 {
|
||||
ctx.SetGroupAddRequest(ctx.Event.Flag, "add", false, "格式错误!")
|
||||
return
|
||||
}
|
||||
ghun := ans[:divi]
|
||||
hash := ans[divi+1:]
|
||||
logrus.Infoln("[manager]收到加群申请, 用户:", ghun, ", hash:", hash)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
const base = "data/nwife"
|
||||
|
||||
var baseuri = "file:///" + file.BOT_PATH + "/" + base
|
||||
var baseuri = "file:///" + file.BOTPATH + "/" + base
|
||||
|
||||
func init() {
|
||||
err := os.MkdirAll(base, 0755)
|
||||
|
||||
186
plugin_novel/qianbi.go
Normal file
186
plugin_novel/qianbi.go
Normal file
@@ -0,0 +1,186 @@
|
||||
// Package novel 铅笔小说搜索插件
|
||||
package novel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/antchfx/htmlquery"
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
ub "github.com/FloatTech/ZeroBot-Plugin/utils/binary"
|
||||
)
|
||||
|
||||
const (
|
||||
websiteURL = "https://www.23qb.net"
|
||||
websiteTitle = "铅笔小说"
|
||||
errorTitle = "出现错误!"
|
||||
username = "zerobot"
|
||||
password = "123456"
|
||||
submit = "%26%23160%3B%B5%C7%26%23160%3B%26%23160%3B%C2%BC%26%23160%3B"
|
||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
|
||||
loginURL = websiteURL + "/login.php?do=submit&jumpurl=https%3A%2F%2Fwww.23qb.net%2F"
|
||||
searchURL = websiteURL + "/saerch.php"
|
||||
idReg = `/(\d+)/`
|
||||
)
|
||||
|
||||
var (
|
||||
gCurCookieJar *cookiejar.Jar
|
||||
engine = control.Register("novel", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "铅笔小说网搜索\n- 小说[xxx]",
|
||||
})
|
||||
limit = rate.NewManager(time.Minute, 5)
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine.OnRegex("^小说([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.GroupID).Acquire() {
|
||||
ctx.SendChain(message.Text("请稍后重试0x0..."))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||
login(username, password)
|
||||
searchKey := ctx.State["regex_matched"].([]string)[1]
|
||||
searchHtml := search(searchKey)
|
||||
var m message.Message
|
||||
doc, err := htmlquery.Parse(strings.NewReader(searchHtml))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
htmlTitle := htmlquery.InnerText(htmlquery.FindOne(doc, "/html/head/title"))
|
||||
if htmlTitle == websiteTitle {
|
||||
list, err := htmlquery.QueryAll(doc, "//dl[@id='nr']")
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
if len(list) != 0 {
|
||||
for _, v := range list {
|
||||
bookName := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[1]/h3/a[1]"))
|
||||
category := htmlquery.InnerText(htmlquery.FindOne(v, "/dt/span[1]"))
|
||||
author := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[2]/span[1]"))
|
||||
status := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[2]/span[2]"))
|
||||
wordNumbers := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[2]/span[3]"))
|
||||
description := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[3]"))
|
||||
updateTime := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[1]/h3/span[1]"))
|
||||
latestChapter := htmlquery.InnerText(htmlquery.FindOne(v, "/dd[4]/a[1]"))
|
||||
|
||||
reg := regexp.MustCompile(idReg)
|
||||
id := reg.FindStringSubmatch(htmlquery.SelectAttr(htmlquery.FindOne(v, "/dt/a[1]"), "href"))[1]
|
||||
|
||||
webpageURL := websiteURL + "/book/" + id + "/"
|
||||
downloadURL := websiteURL + "/modules/article/txtarticle.php?id=" + id
|
||||
text := fmt.Sprintf("书名:%s\n类型:%s\n作者:%s\n状态:%s\n字数:%s\n简介:%s\n更新时间:%s\n最新章节:%s\n网页链接:%s\n下载地址:%s\n", bookName, category, author, status, wordNumbers, description, updateTime, latestChapter, webpageURL, downloadURL)
|
||||
m = append(m,
|
||||
message.CustomNode(
|
||||
zero.BotConfig.NickName[0],
|
||||
ctx.Event.SelfID,
|
||||
text),
|
||||
)
|
||||
}
|
||||
if id := ctx.SendGroupForwardMessage(
|
||||
ctx.Event.GroupID,
|
||||
m).Get("message_id").Int(); id == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
} else {
|
||||
text := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@id='tipss']"))
|
||||
text = strings.Replace(text, " ", "", -1)
|
||||
text = strings.Replace(text, "本站", websiteURL, -1)
|
||||
ctx.SendChain(message.Text(text))
|
||||
}
|
||||
} else if htmlTitle == errorTitle {
|
||||
ctx.SendChain(message.Text(errorTitle))
|
||||
text := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@style='text-align: center;padding:10px']"))
|
||||
text = strings.Replace(text, " ", "", -1)
|
||||
ctx.SendChain(message.Text(text))
|
||||
} else {
|
||||
bookName := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:book_name']"), "content")
|
||||
category := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:category']"), "content")
|
||||
author := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:author']"), "content")
|
||||
status := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:status']"), "content")
|
||||
description := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@id='bookintro']/p"))
|
||||
updateTime := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:update_time']"), "content")
|
||||
latestChapter := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:latest_chapter_name']"), "content")
|
||||
|
||||
reg := regexp.MustCompile(idReg)
|
||||
id := reg.FindStringSubmatch(htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:read_url']"), "content"))[1]
|
||||
webpageURL := websiteURL + "/book/" + id + "/"
|
||||
downloadURL := websiteURL + "/modules/article/txtarticle.php?id=" + id
|
||||
text := fmt.Sprintf("书名:%s\n类型:%s\n作者:%s\n状态:%s\n简介:%s\n更新时间:%s\n最新章节:%s\n网页链接:%s\n下载地址:%s\n", bookName, category, author, status, description, updateTime, latestChapter, webpageURL, downloadURL)
|
||||
ctx.SendChain(message.Text(text))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func login(username, password string) {
|
||||
gCurCookieJar, _ = cookiejar.New(nil)
|
||||
client := &http.Client{
|
||||
Jar: gCurCookieJar,
|
||||
}
|
||||
usernameData, err := ub.UTF82GBK(helper.StringToBytes(username))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
usernameGbk := helper.BytesToString(usernameData)
|
||||
passwordData, err := ub.UTF82GBK(helper.StringToBytes(password))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
passwordGbk := helper.BytesToString(passwordData)
|
||||
loginReq, err := http.NewRequest("POST", loginURL, strings.NewReader(fmt.Sprintf("username=%s&password=%s&usecookie=315360000&action=login&submit=%s", url.QueryEscape(usernameGbk), url.QueryEscape(passwordGbk), submit)))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
loginReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
loginReq.Header.Set("User-Agent", ua)
|
||||
loginResp, err := client.Do(loginReq)
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
defer loginResp.Body.Close()
|
||||
}
|
||||
|
||||
func search(searchKey string) (searchHtml string) {
|
||||
searchKeyData, err := ub.UTF82GBK(helper.StringToBytes(searchKey))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
searchKeyGbk := helper.BytesToString(searchKeyData)
|
||||
client := &http.Client{
|
||||
Jar: gCurCookieJar,
|
||||
}
|
||||
searchReq, err := http.NewRequest("POST", searchURL, strings.NewReader(fmt.Sprintf("searchkey=%s&searchtype=all", url.QueryEscape(searchKeyGbk))))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
searchReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
searchReq.Header.Set("User-Agent", ua)
|
||||
searchResp, err := client.Do(searchReq)
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
defer searchResp.Body.Close()
|
||||
searchData, err := ioutil.ReadAll(searchResp.Body)
|
||||
if err != nil {
|
||||
log.Errorf("[novel] get response for url=%s got error=%s\n", searchURL, err.Error())
|
||||
}
|
||||
searchData, err = ub.GBK2UTF8(searchData)
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
}
|
||||
searchHtml = helper.BytesToString(searchData)
|
||||
return searchHtml
|
||||
}
|
||||
@@ -97,15 +97,17 @@ type dataQYK struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
const (
|
||||
qykURL = "http://api.qingyunke.com/api.php"
|
||||
key = "free"
|
||||
appid = "0"
|
||||
)
|
||||
|
||||
// 青云客取消息
|
||||
func getMessage(msg string) (string, error) {
|
||||
qykUrl := "http://api.qingyunke.com/api.php"
|
||||
key := "free"
|
||||
appid := "0"
|
||||
qykUrl = fmt.Sprintf(qykUrl+"?key=%s&appid=%s&msg=%s", key, appid, url.QueryEscape(msg))
|
||||
|
||||
u := fmt.Sprintf(qykURL+"?key=%s&appid=%s&msg=%s", key, appid, url.QueryEscape(msg))
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", qykUrl, nil)
|
||||
req, err := http.NewRequest("GET", u, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
datapath = file.BOT_PATH + "/data/saucenao/"
|
||||
datapath = file.BOTPATH + "/data/saucenao/"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
|
||||
@@ -217,7 +217,7 @@ func (p *imgpool) pop(imgtype string) (illust *pixiv.Illust) {
|
||||
|
||||
func file(i *pixiv.Illust) string {
|
||||
filename := fmt.Sprint(i.Pid)
|
||||
filepath := fileutil.BOT_PATH + `/` + pool.Path + filename
|
||||
filepath := fileutil.BOTPATH + `/` + pool.Path + filename
|
||||
if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) {
|
||||
return `file:///` + filepath + ".jpg"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package plugin_sleep_manage
|
||||
package sleepmanage
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -12,11 +12,10 @@ import (
|
||||
func init() {
|
||||
go func() {
|
||||
defer func() {
|
||||
//recover() //可以打印panic的错误信息
|
||||
if err := recover(); err != nil { //产生了panic异常
|
||||
if err := recover(); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}() //别忘了(), 调用此匿名函数
|
||||
}()
|
||||
process.SleepAbout1sTo2s()
|
||||
_ = os.MkdirAll(dbpath, 0755)
|
||||
model.Initialize(dbfile)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package model 睡眠管理数据库
|
||||
package model
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package plugin_sleep_manage
|
||||
// Package sleepmanage 睡眠管理
|
||||
package sleepmanage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
29
utils/binary/encode.go
Normal file
29
utils/binary/encode.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
// GBK2UTF8 GBK 转 UTF-8
|
||||
func GBK2UTF8(s []byte) ([]byte, error) {
|
||||
reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewDecoder())
|
||||
d, e := ioutil.ReadAll(reader)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// UTF82GBK UTF-8 转 GBK
|
||||
func UTF82GBK(s []byte) ([]byte, error) {
|
||||
reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewEncoder())
|
||||
d, e := ioutil.ReadAll(reader)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
@@ -5,6 +5,7 @@ package file
|
||||
|
||||
import "os"
|
||||
|
||||
// Pwd 获取当前路径
|
||||
func Pwd() (path string) {
|
||||
path, _ = os.Getwd()
|
||||
return
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Pwd 获取当前路径的正斜杠表示
|
||||
func Pwd() string {
|
||||
path, _ := os.Getwd()
|
||||
return strings.ReplaceAll(path, "\\", "/")
|
||||
|
||||
@@ -2,7 +2,8 @@ package file
|
||||
|
||||
import "os"
|
||||
|
||||
var BOT_PATH = Pwd()
|
||||
// BOTPATH BOT当前路径
|
||||
var BOTPATH = Pwd()
|
||||
|
||||
// IsExist 文件/路径存在
|
||||
func IsExist(path string) bool {
|
||||
@@ -10,7 +11,7 @@ func IsExist(path string) bool {
|
||||
return err == nil || os.IsExist(err)
|
||||
}
|
||||
|
||||
// IsExist 文件/路径不存在
|
||||
// IsNotExist 文件/路径不存在
|
||||
func IsNotExist(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err != nil && os.IsNotExist(err)
|
||||
|
||||
@@ -82,7 +82,7 @@ func GetLazyData(path string, isReturnDataBytes, isDataMustEqual bool) ([]byte,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(data) <= 0 {
|
||||
if len(data) == 0 {
|
||||
return nil, errors.New("read body len <= 0")
|
||||
}
|
||||
if filemd5 != nil {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package process 流程控制相关
|
||||
package process
|
||||
|
||||
import (
|
||||
@@ -5,6 +6,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// SleepAbout1sTo2s 随机阻塞等待 1 ~ 2s
|
||||
func SleepAbout1sTo2s() {
|
||||
time.Sleep(time.Second + time.Millisecond*time.Duration(rand.Intn(1000)))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package rule zb 规则扩展
|
||||
package rule
|
||||
|
||||
import zero "github.com/wdvxdr1123/ZeroBot"
|
||||
|
||||
@@ -366,10 +366,10 @@ func (db *Sqlite) Count(table string) (num int, err error) {
|
||||
return num, rows.Err()
|
||||
}
|
||||
if rows.Next() {
|
||||
rows.Scan(&num)
|
||||
err = rows.Scan(&num)
|
||||
}
|
||||
rows.Close()
|
||||
return num, nil
|
||||
return num, err
|
||||
}
|
||||
|
||||
// tags 反射 返回结构体对象的 tag 数组
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package web 网络处理相关
|
||||
package web
|
||||
|
||||
import (
|
||||
@@ -6,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ReqWith 使用自定义请求头获取数据
|
||||
func ReqWith(url string, method string, referer string, ua string) (data []byte, err error) {
|
||||
client := &http.Client{}
|
||||
// 提交请求
|
||||
@@ -25,6 +27,7 @@ func ReqWith(url string, method string, referer string, ua string) (data []byte,
|
||||
return
|
||||
}
|
||||
|
||||
// GetData 获取数据
|
||||
func GetData(url string) (data []byte, err error) {
|
||||
var response *http.Response
|
||||
response, err = http.Get(url)
|
||||
|
||||
Reference in New Issue
Block a user