mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
feat:添加青云客接口
This commit is contained in:
parent
47aa6213bf
commit
060e167dc7
6
main.go
6
main.go
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,6 +10,7 @@ import (
|
||||
// 词库类
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_atri" // ATRI词库
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_chat" // 基础词库
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_qingyunke" //青云客
|
||||
|
||||
// 实用类
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_github" // 搜索GitHub仓库
|
||||
@ -23,6 +24,7 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji" // 浅草寺求签
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_personal" //个人私货
|
||||
|
||||
// b站相关
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息
|
||||
@ -74,7 +76,7 @@ func main() {
|
||||
// SuperUsers 某些功能需要主人权限,可通过以下两种方式修改
|
||||
// []string{}:通过代码写死的方式添加主人账号
|
||||
// os.Args[1:]:通过命令行参数的方式添加主人账号
|
||||
SuperUsers: append([]string{"12345678", "87654321"}, os.Args[1:]...),
|
||||
SuperUsers: append([]string{"1156544355","1846515440","1776620359"}, os.Args[1:]...),
|
||||
|
||||
Driver: []zero.Driver{
|
||||
&driver.WSClient{
|
||||
|
||||
@ -25,16 +25,20 @@ var (
|
||||
func init() { // 插件主体
|
||||
zero.OnFullMatch("ATRI醒醒", zero.AdminPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
enable = true
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText("嗯呜呜……夏生先生……?"))
|
||||
})
|
||||
zero.OnFullMatch("ATRI睡吧", zero.AdminPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
enable = false
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText("Zzz……Zzz……"))
|
||||
})
|
||||
zero.OnFullMatch("萝卜子", atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
switch rand.Intn(2) {
|
||||
case 0:
|
||||
ctx.SendChain(randText("萝卜子是对机器人的蔑称!", "是亚托莉......萝卜子可是对机器人的蔑称"))
|
||||
@ -44,12 +48,21 @@ func init() { // 插件主体
|
||||
})
|
||||
zero.OnKeywordGroup([]string{"喜欢", "爱你", "爱", "suki", "daisuki", "すき", "好き", "贴贴", "老婆", "亲一个", "mua"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
if rand.Intn(10) == 0 {
|
||||
ctx.SendChain(randImage("SUKI.jpg", "SUKI1.jpg", "SUKI2.png"))
|
||||
}else{
|
||||
ctx.SendChain(randText(
|
||||
"椛椛不是你的电子宠物",
|
||||
"椛椛不爱你,爬",
|
||||
"你是个好人,你值得更好的归属",
|
||||
"椛椛已经有主人了",
|
||||
))
|
||||
}
|
||||
})
|
||||
zero.OnKeywordGroup([]string{"草你妈", "操你妈", "脑瘫", "废柴", "fw", "five", "废物", "战斗", "爬", "爪巴", "sb", "SB", "傻B"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio - 1).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randImage("FN.jpg", "WQ.jpg", "WQ1.jpg"))
|
||||
})
|
||||
zero.OnFullMatchGroup([]string{"早安", "早哇", "早上好", "ohayo", "哦哈哟", "お早う"}, atriSwitch()).SetBlock(true).SetPriority(prio).
|
||||
@ -57,6 +70,7 @@ func init() { // 插件主体
|
||||
now := time.Now().Hour()
|
||||
switch {
|
||||
case now < 6: // 凌晨
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"zzzz......",
|
||||
"zzzzzzzz......",
|
||||
@ -66,6 +80,7 @@ func init() { // 插件主体
|
||||
"...zzz....哧溜哧溜....",
|
||||
))
|
||||
case now >= 6 && now < 9:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"啊......早上好...(哈欠)",
|
||||
"唔......吧唧...早上...哈啊啊~~~\n早上好......",
|
||||
@ -78,12 +93,14 @@ func init() { // 插件主体
|
||||
"早上好......欸~~~脸好近呢",
|
||||
))
|
||||
case now >= 9 && now < 18:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"哼!这个点还早啥,昨晚干啥去了!?",
|
||||
"熬夜了对吧熬夜了对吧熬夜了对吧???!",
|
||||
"是不是熬夜是不是熬夜是不是熬夜?!",
|
||||
))
|
||||
case now >= 18 && now < 24:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"早个啥?哼唧!我都准备洗洗睡了!",
|
||||
"不是...你看看几点了,哼!",
|
||||
@ -95,6 +112,7 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
now := time.Now().Hour()
|
||||
if now > 11 && now < 15 { // 中午
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"午安w",
|
||||
"午觉要好好睡哦,ATRI会陪伴在你身旁的w",
|
||||
@ -108,6 +126,7 @@ func init() { // 插件主体
|
||||
now := time.Now().Hour()
|
||||
switch {
|
||||
case now < 6: // 凌晨
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"zzzz......",
|
||||
"zzzzzzzz......",
|
||||
@ -117,6 +136,7 @@ func init() { // 插件主体
|
||||
"...zzz....哧溜哧溜....",
|
||||
))
|
||||
case now >= 6 && now < 11:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"你可猝死算了吧!",
|
||||
"?啊这",
|
||||
@ -124,6 +144,7 @@ func init() { // 插件主体
|
||||
"不可忍不可忍不可忍!!为何这还不猝死!!",
|
||||
))
|
||||
case now >= 11 && now < 15:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"午安w",
|
||||
"午觉要好好睡哦,ATRI会陪伴在你身旁的w",
|
||||
@ -131,12 +152,14 @@ func init() { // 插件主体
|
||||
"睡你午觉去!哼唧!!",
|
||||
))
|
||||
case now >= 15 && now < 19:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"难不成??晚上不想睡觉??现在休息",
|
||||
"就......挺离谱的...现在睡觉",
|
||||
"现在还是白天哦,睡觉还太早了",
|
||||
))
|
||||
case now >= 19 && now < 24:
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"嗯哼哼~睡吧,就像平常一样安眠吧~o(≧▽≦)o",
|
||||
"......(打瞌睡)",
|
||||
@ -147,6 +170,7 @@ func init() { // 插件主体
|
||||
})
|
||||
zero.OnKeywordGroup([]string{"高性能", "太棒了", "すごい", "sugoi", "斯国一", "よかった"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"当然,我是高性能的嘛~!",
|
||||
"小事一桩,我是高性能的嘛",
|
||||
@ -167,6 +191,7 @@ func init() { // 插件主体
|
||||
})
|
||||
zero.OnKeywordGroup([]string{"没事", "没关系", "大丈夫", "还好", "不要紧", "没出大问题", "没伤到哪"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText(
|
||||
"当然,我是高性能的嘛~!",
|
||||
"没事没事,因为我是高性能的嘛!嗯哼!",
|
||||
@ -181,22 +206,26 @@ func init() { // 插件主体
|
||||
|
||||
zero.OnKeywordGroup([]string{"好吗", "是吗", "行不行", "能不能", "可不可以"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
if rand.Intn(2) == 0 {
|
||||
ctx.SendChain(randImage("YES.png", "NO.jpg"))
|
||||
}
|
||||
})
|
||||
zero.OnFullMatchGroup([]string{"啊这"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
if rand.Intn(2) == 0 {
|
||||
ctx.SendChain(randImage("AZ.jpg", "AZ1.jpg"))
|
||||
}
|
||||
})
|
||||
zero.OnFullMatchGroup([]string{"我好了"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText("不许好!", "憋回去!"))
|
||||
})
|
||||
zero.OnFullMatchGroup([]string{"?", "?", "¿"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
switch rand.Intn(5) {
|
||||
case 0:
|
||||
ctx.SendChain(randText("?", "?", "嗯?", "(。´・ω・)ん?", "ん?"))
|
||||
@ -215,6 +244,7 @@ func init() { // 插件主体
|
||||
})
|
||||
zero.OnKeyword("答应我", atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(randText("我无法回应你的请求"))
|
||||
})
|
||||
}
|
||||
|
||||
49
plugin_personal/personal.go
Normal file
49
plugin_personal/personal.go
Normal file
@ -0,0 +1,49 @@
|
||||
package personal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
zero.OnFullMatch("经典台词", zero.OnlyToMe,zero.SuperUserPermission).SetBlock(false).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
k:=getDialogue()
|
||||
arr:= []int64{1197716421,1652997133,657595613,1481003793}
|
||||
for _,v:= range arr{
|
||||
ctx.SendPrivateMessage(v,message.Text(k.Newslist[0].Dialogue+" ——《"+k.Newslist[0].Source+"》"))
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
type TData struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Newslist []NData `json:"newslist"`
|
||||
}
|
||||
type NData struct {
|
||||
Dialogue string `json:"dialogue"`
|
||||
English string `json:"english"`
|
||||
Source string `json:"source"`
|
||||
Type int `json:"type"`
|
||||
}
|
||||
func getDialogue() TData{
|
||||
resp,_ := http.Get("http://api.tianapi.com/txapi/dialogue/index?key=4f56c7838d5b064147e71893d14ddeb1")
|
||||
bytes,_ := ioutil.ReadAll(resp.Body)
|
||||
fmt.Println(string(bytes))
|
||||
|
||||
var r TData
|
||||
err := json.Unmarshal(bytes, &r)
|
||||
if err != nil {
|
||||
fmt.Printf("err was %v", err)
|
||||
}
|
||||
return r
|
||||
|
||||
|
||||
}
|
||||
151
plugin_qingyunke/qingyunke.go
Normal file
151
plugin_qingyunke/qingyunke.go
Normal file
@ -0,0 +1,151 @@
|
||||
package qingyunke
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var prio = -1
|
||||
var poke = rate.NewManager(time.Minute, 20) // 青云客接口回复
|
||||
var enable = true
|
||||
|
||||
func init() { // 插件主体
|
||||
// 被喊名字
|
||||
zero.OnRegex("(^.{1,30}$)", zero.OnlyToMe,atriSwitch()).SetBlock(false).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
//var nickname = zero.BotConfig.NickName[0]
|
||||
switch {
|
||||
case poke.Load(ctx.Event.UserID).Acquire():
|
||||
time.Sleep(time.Second * 1)
|
||||
msg := ctx.State["regex_matched"].([]string)[1]
|
||||
fmt.Println(msg)
|
||||
reply := getMessage(msg)
|
||||
reg := regexp.MustCompile(`\{face:(\d+)\}(.*)`)
|
||||
faceReply := -1
|
||||
var textReply string
|
||||
if reg.MatchString(reply) {
|
||||
fmt.Println(reg.FindStringSubmatch(reply))
|
||||
faceReply, _ = strconv.Atoi(reg.FindStringSubmatch(reply)[1])
|
||||
textReply = reg.FindStringSubmatch(reply)[2]
|
||||
} else {
|
||||
textReply = reply
|
||||
}
|
||||
strings.Replace(textReply,"菲菲","椛椛",-1)
|
||||
if ctx.Event.DetailType == "group" {
|
||||
|
||||
ctx.SendChain(message.Text(textReply))
|
||||
if faceReply != -1 {
|
||||
ctx.SendChain(message.Face(faceReply))
|
||||
}
|
||||
|
||||
}
|
||||
if ctx.Event.DetailType == "private" {
|
||||
ctx.SendChain(message.Text(textReply))
|
||||
if faceReply != -1 {
|
||||
ctx.SendChain(message.Face(faceReply))
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
//频繁触发,不回复
|
||||
}
|
||||
|
||||
})
|
||||
zero.OnFullMatch("启动",zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
enable = true
|
||||
ctx.SendChain(message.Text("自动回复启动"))
|
||||
|
||||
|
||||
|
||||
})
|
||||
zero.OnFullMatch("关闭",zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
enable = false
|
||||
ctx.SendChain(message.Text("自动回复关闭"))
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
// 群空调
|
||||
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Result int `json:"result"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func getMessage(msg string) string {
|
||||
url := "http://api.qingyunke.com/api.php"
|
||||
key := "free"
|
||||
appid := "0"
|
||||
//msg := "早上好"
|
||||
url = fmt.Sprintf(url+"?key=%s&appid=%s&msg=%s", key, appid, msg)
|
||||
fmt.Println(url)
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
fmt.Println("new.request", err)
|
||||
}
|
||||
// 自定义Header
|
||||
req.Header.Set("User-Agent", getAgent())
|
||||
req.Header.Set("Connection", "keep-alive")
|
||||
req.Header.Set("Host", "api.qingyunke.com")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println("http.get.url", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
bytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println("ioutil.ReadAll", err)
|
||||
}
|
||||
fmt.Println(string(bytes))
|
||||
var data Data
|
||||
if err := json.Unmarshal(bytes, &data); err != nil {
|
||||
fmt.Println("json transform", err)
|
||||
}
|
||||
return data.Content
|
||||
}
|
||||
|
||||
func getAgent() string {
|
||||
agent := [...]string{
|
||||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0",
|
||||
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
|
||||
"Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
|
||||
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",
|
||||
"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
|
||||
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",
|
||||
"User-Agent,Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
|
||||
"User-Agent, Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)",
|
||||
"User-Agent,Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
|
||||
}
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
len1 := len(agent)
|
||||
return agent[r.Intn(len1)]
|
||||
}
|
||||
|
||||
func atriSwitch() zero.Rule {
|
||||
return func(ctx *zero.Ctx) bool {
|
||||
return enable
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user