mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
🎨 调整代码结构
This commit is contained in:
parent
14d07bf963
commit
9a47bc93b0
@ -29,6 +29,7 @@
|
|||||||
- [ ] 同意好友请求
|
- [ ] 同意好友请求
|
||||||
- [ ] 撤回[@xxx] [xxx]
|
- [ ] 撤回[@xxx] [xxx]
|
||||||
- [ ] 警告[@xxx]
|
- [ ] 警告[@xxx]
|
||||||
|
- [x] run[xxx]
|
||||||
- 涩图
|
- 涩图
|
||||||
- [x] 来份[涩图/二次元/风景]
|
- [x] 来份[涩图/二次元/风景]
|
||||||
- [x] 添加[涩图/二次元/风景][P站图片ID]
|
- [x] 添加[涩图/二次元/风景][P站图片ID]
|
||||||
@ -38,8 +39,6 @@
|
|||||||
- [x] setu -p
|
- [x] setu -p
|
||||||
- 点歌
|
- 点歌
|
||||||
- [x] 点歌[xxx]
|
- [x] 点歌[xxx]
|
||||||
- run
|
|
||||||
- [x] run[xxx]
|
|
||||||
- TODO...
|
- TODO...
|
||||||
|
|
||||||
### 使用方法
|
### 使用方法
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module bot
|
module github.com/Yiwen-Chan/ZeroBot-Plugin
|
||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
|
|||||||
9
main.go
9
main.go
@ -8,11 +8,10 @@ import (
|
|||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/driver"
|
"github.com/wdvxdr1123/ZeroBot/driver"
|
||||||
|
|
||||||
_ "bot/github"
|
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/github"
|
||||||
_ "bot/manager"
|
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/manager"
|
||||||
_ "bot/music"
|
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/music"
|
||||||
_ "bot/run"
|
setutime "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime"
|
||||||
setutime "bot/setutime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
package manager
|
package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bot/manager/utils"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Yiwen-Chan/ZeroBot-Plugin/manager/utils"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +23,8 @@ func init() { // 插件主体
|
|||||||
- 修改名片@QQ XXX
|
- 修改名片@QQ XXX
|
||||||
- 修改头衔@QQ XXX
|
- 修改头衔@QQ XXX
|
||||||
- 申请头衔 XXX
|
- 申请头衔 XXX
|
||||||
|
- 踢出群聊@QQ
|
||||||
|
- 退出群聊 1234
|
||||||
- 群聊转发 1234 XXX
|
- 群聊转发 1234 XXX
|
||||||
- 私聊转发 0000 XXX`)
|
- 私聊转发 0000 XXX`)
|
||||||
return
|
return
|
||||||
@ -251,4 +253,12 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
// 运行 CQ 码
|
||||||
|
zero.OnRegex(`^run(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(0).
|
||||||
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
var cmd = ctx.State["regex_matched"].([]string)[1]
|
||||||
|
cmd = strings.ReplaceAll(cmd, "[", "[")
|
||||||
|
cmd = strings.ReplaceAll(cmd, "]", "]")
|
||||||
|
ctx.Send(cmd)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,30 +2,77 @@ package setutime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"bot/music/utils"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var limit = rate.NewManager(time.Minute*1, 3)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
zero.OnRegex(`^点歌(.*)$`).SetBlock(true).SetPriority(50).
|
zero.OnRegex(`^点歌(.*)$`).SetBlock(true).SetPriority(50).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
music, err := utils.CloudMusic(ctx.State["regex_matched"].([]string)[1])
|
if limit.Load(ctx.Event.UserID).Acquire() == false {
|
||||||
|
ctx.Send("请稍后重试0x0...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 调用网易云 API
|
||||||
|
var api = "http://music.163.com/api/search/pc"
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
// 包装请求参数
|
||||||
|
data := url.Values{}
|
||||||
|
data.Set("offset", "0")
|
||||||
|
data.Set("total", "true")
|
||||||
|
data.Set("limit", "9")
|
||||||
|
data.Set("type", "1")
|
||||||
|
data.Set("s", ctx.State["regex_matched"].([]string)[1])
|
||||||
|
fromData := strings.NewReader(data.Encode())
|
||||||
|
|
||||||
|
// 网络请求
|
||||||
|
req, err := http.NewRequest("POST", api, fromData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Send(fmt.Sprintf("ERROR: %v", err))
|
ctx.Send(fmt.Sprintf("ERROR: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
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 {
|
||||||
|
ctx.Send(fmt.Sprintf("ERROR: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Send(fmt.Sprintf("ERROR: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if code := resp.StatusCode; code != 200 {
|
||||||
|
// 如果返回不是200则立刻抛出错误
|
||||||
|
ctx.Send(fmt.Sprintf("ERROR: code %d", code))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
content := gjson.ParseBytes(body).Get("result.songs.0")
|
||||||
|
|
||||||
// 发送搜索结果
|
// 发送搜索结果
|
||||||
ctx.Send(
|
ctx.Send(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"[CQ:music,type=%s,url=%s,audio=%s,title=%s,content=%s,image=%s]",
|
"[CQ:music,type=%s,url=%s,audio=%s,title=%s,content=%s,image=%s]",
|
||||||
music.Type,
|
"custom",
|
||||||
music.Url,
|
fmt.Sprintf("http://y.music.163.com/m/song?id=%d", content.Get("id").Int()),
|
||||||
music.Audio,
|
fmt.Sprintf("http://music.163.com/song/media/outer/url?id=%d.mp3", content.Get("id").Int()),
|
||||||
music.Title,
|
content.Get("name").Str,
|
||||||
music.Content,
|
content.Get("artists.0.name").Str,
|
||||||
music.Image,
|
content.Get("album.blurPicUrl").Str,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CloudMusic(name string) (music CQMusic, err error) {
|
|
||||||
var api = "http://music.163.com/api/search/pc"
|
|
||||||
|
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
// 包装请求参数
|
|
||||||
data := url.Values{}
|
|
||||||
data.Set("offset", "0")
|
|
||||||
data.Set("total", "true")
|
|
||||||
data.Set("limit", "9")
|
|
||||||
data.Set("type", "1")
|
|
||||||
data.Set("s", name)
|
|
||||||
fromData := strings.NewReader(data.Encode())
|
|
||||||
|
|
||||||
// 网络请求
|
|
||||||
req, err := http.NewRequest("POST", api, fromData)
|
|
||||||
if err != nil {
|
|
||||||
return music, err
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
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 music, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return music, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if code := resp.StatusCode; code != 200 {
|
|
||||||
// 如果返回不是200则立刻抛出错误
|
|
||||||
return music, errors.New(fmt.Sprintf("CloudMusic not found, code %d", code))
|
|
||||||
}
|
|
||||||
content := gjson.ParseBytes(body).Get("result.songs.0")
|
|
||||||
music.Type = "custom"
|
|
||||||
music.Url = fmt.Sprintf("http://y.music.163.com/m/song?id=%d", content.Get("id").Int())
|
|
||||||
music.Audio = fmt.Sprintf("http://music.163.com/song/media/outer/url?id=%d.mp3", content.Get("id").Int())
|
|
||||||
music.Title = content.Get("name").Str
|
|
||||||
music.Content = content.Get("artists.0.name").Str
|
|
||||||
music.Image = content.Get("album.blurPicUrl").Str
|
|
||||||
return music, nil
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
type CQMusic struct {
|
|
||||||
Type string
|
|
||||||
Url string
|
|
||||||
Audio string
|
|
||||||
Title string
|
|
||||||
Content string
|
|
||||||
Image string
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
package runner
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() { // 插件主体
|
|
||||||
zero.OnRegex(`^run(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(0).
|
|
||||||
Handle(func(ctx *zero.Ctx) {
|
|
||||||
var cmd = ctx.State["regex_matched"].([]string)[1]
|
|
||||||
cmd = strings.ReplaceAll(cmd, "[", "[")
|
|
||||||
cmd = strings.ReplaceAll(cmd, "]", "]")
|
|
||||||
ctx.Send(cmd)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package setutime
|
package setutime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
utils "bot/setutime/utils"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
utils "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime/utils"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
utils "bot/setutime/utils"
|
"github.com/Yiwen-Chan/ZeroBot-Plugin/setutime/utils"
|
||||||
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user