mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
⬆️ Using zeroBot
This commit is contained in:
commit
e8945f6572
37
app.go
Normal file
37
app.go
Normal file
@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
m "gm/modules"
|
||||
"gm/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
var Conf = &utils.YamlConfig{}
|
||||
|
||||
func main() {
|
||||
zero.Run(zero.Option{
|
||||
Host: Conf.Host,
|
||||
Port: Conf.Port,
|
||||
AccessToken: Conf.AccessToken,
|
||||
NickName: []string{"GroupManager"},
|
||||
CommandPrefix: "/",
|
||||
SuperUsers: Conf.Master,
|
||||
})
|
||||
select {}
|
||||
}
|
||||
|
||||
func init() {
|
||||
fmt.Println(`
|
||||
====================[GroupManager]====================
|
||||
* Mirai + ZeroBot + Golang
|
||||
* Copyright © 2018-2020 Kanri, All Rights Reserved
|
||||
* Project: https://github.com/Yiwen-Chan/GroupManager
|
||||
=======================================================
|
||||
`)
|
||||
Conf = utils.Load("./data/config.yml")
|
||||
m.Conf = Conf
|
||||
fmt.Println("[GroupManager] 有需要请按 GitHub 项目上描述的方法修改配置文件")
|
||||
}
|
||||
9
go.mod
Normal file
9
go.mod
Normal file
@ -0,0 +1,9 @@
|
||||
module gm
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20201129064504-07d9e1b5400f
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
||||
)
|
||||
35
go.sum
Normal file
35
go.sum
Normal file
@ -0,0 +1,35 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
|
||||
github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws=
|
||||
github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
||||
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
||||
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20201129064504-07d9e1b5400f h1:06qEGANaKnXdJShXGEbD70F77C7AQAXA0nkQVdyORHc=
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20201129064504-07d9e1b5400f/go.mod h1:e92qGONnOry8XSfaUUlG7OhT9gyD839P8oZ2wfPe60w=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 h1:HlFl4V6pEMziuLXyRkm5BIYq1y1GAbb02pRlWvI54OM=
|
||||
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
5
modules/main.go
Normal file
5
modules/main.go
Normal file
@ -0,0 +1,5 @@
|
||||
package modules
|
||||
|
||||
import "gm/utils"
|
||||
|
||||
var Conf = &utils.YamlConfig{}
|
||||
67
modules/manage.go
Normal file
67
modules/manage.go
Normal file
@ -0,0 +1,67 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(manage{})
|
||||
}
|
||||
|
||||
type manage struct{}
|
||||
|
||||
func (manage) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "manage",
|
||||
Version: "0.0.1",
|
||||
Details: "设置群名片群头衔",
|
||||
}
|
||||
}
|
||||
|
||||
func (manage) Start() { // 插件主体
|
||||
promoteManager := zero.OnRegex("^升为管理.*?(\\d+)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(event.GroupID, GetInt(state, 1), true)
|
||||
zero.Send(event, "恭喜~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
promoteManager.Priority = 20
|
||||
promoteManager.Block = true
|
||||
|
||||
cancleManager := zero.OnRegex("^取消管理.*?(\\d+)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(event.GroupID, GetInt(state, 1), false)
|
||||
zero.Send(event, "残念~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
cancleManager.Priority = 21
|
||||
cancleManager.Block = true
|
||||
|
||||
kick := zero.OnRegex("^踢出群聊.*?(\\d+)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupKick(event.GroupID, GetInt(state, 1), false)
|
||||
zero.Send(event, "残念~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
kick.Priority = 22
|
||||
kick.Block = true
|
||||
|
||||
leave := zero.OnRegex("^退出群聊.*?(\\d+)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupLeave(event.GroupID, true)
|
||||
zero.Send(event, "明白了!")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
leave.Priority = 23
|
||||
leave.Block = true
|
||||
|
||||
}
|
||||
77
modules/mute.go
Normal file
77
modules/mute.go
Normal file
@ -0,0 +1,77 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(mute{})
|
||||
}
|
||||
|
||||
type mute struct{}
|
||||
|
||||
func (mute) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "mute",
|
||||
Version: "0.0.1",
|
||||
Details: "禁言",
|
||||
}
|
||||
}
|
||||
|
||||
func (mute) Start() { // 插件主体
|
||||
unWholeBan := zero.OnRegex("^解除全体禁言$", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupWholeBan(event.GroupID, false)
|
||||
zero.Send(event, "小黑屋收留成功~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
unWholeBan.Priority = 1
|
||||
unWholeBan.Block = true
|
||||
|
||||
wholeBan := zero.OnRegex("^开启全体禁言$", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupWholeBan(event.GroupID, true)
|
||||
zero.Send(event, "小黑屋收留成功~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
wholeBan.Priority = 2
|
||||
wholeBan.Block = true
|
||||
|
||||
unban := zero.OnRegex("^解除禁言.*?(\\d+)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(event.GroupID, GetInt(state, 1), 0)
|
||||
zero.Send(event, "小黑屋释放成功~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
unban.Priority = 3
|
||||
unban.Block = true
|
||||
|
||||
ban := zero.OnRegex("^禁言.*?(\\d+).*?\\s(\\d+)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(event.GroupID, GetInt(state, 1), GetInt(state, 2)*1000)
|
||||
zero.Send(event, "小黑屋收留成功~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
ban.Priority = 4
|
||||
ban.Block = true
|
||||
|
||||
selfBan := zero.OnRegex("^我要自闭.*?(\\d+)分钟", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(event.GroupID, event.UserID, GetInt(state, 1)*1000)
|
||||
zero.Send(event, "那我就不手下留情了")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
selfBan.Priority = 5
|
||||
selfBan.Block = true
|
||||
}
|
||||
61
modules/notice.go
Normal file
61
modules/notice.go
Normal file
@ -0,0 +1,61 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(notice{})
|
||||
}
|
||||
|
||||
type notice struct{}
|
||||
|
||||
func (notice) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "notice",
|
||||
Version: "0.0.1",
|
||||
Details: "设置群名片群头衔",
|
||||
}
|
||||
}
|
||||
|
||||
func (notice) Start() { // 插件主体
|
||||
notify := zero.OnNotice().
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.NoticeType == "notify" {
|
||||
time.Sleep(time.Second * 1)
|
||||
zero.Send(event, "请不要戳我 >_<")
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
notify.Priority = 40
|
||||
notify.Block = true
|
||||
|
||||
increase := zero.OnNotice().
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.NoticeType == "group_increase" {
|
||||
zero.Send(event, "欢迎~")
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
increase.Priority = 41
|
||||
increase.Block = true
|
||||
|
||||
decrease := zero.OnNotice().
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.NoticeType == "group_decrease" {
|
||||
zero.Send(event, "有人跑路了")
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
decrease.Priority = 42
|
||||
decrease.Block = true
|
||||
}
|
||||
52
modules/request.go
Normal file
52
modules/request.go
Normal file
@ -0,0 +1,52 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"gm/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(request{})
|
||||
}
|
||||
|
||||
type request struct{}
|
||||
|
||||
func (request) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "request",
|
||||
Version: "0.0.1",
|
||||
Details: "设置群名片群头衔",
|
||||
}
|
||||
}
|
||||
|
||||
func (request) Start() { // 插件主体
|
||||
friendAdd := zero.OnNotice().
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.RequestType == "friend" {
|
||||
zero.SendPrivateMessage(utils.Str2Int(Conf.Master[0]), "有人想加我")
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
friendAdd.Priority = 50
|
||||
friendAdd.Block = true
|
||||
|
||||
groupAdd := zero.OnNotice().
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.RequestType == "friend" {
|
||||
if event.SubType == "add" {
|
||||
zero.Send(event, "有人申请加群")
|
||||
} else {
|
||||
zero.SendPrivateMessage(utils.Str2Int(Conf.Master[0]), "有人想拉我入群")
|
||||
}
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
groupAdd.Priority = 51
|
||||
groupAdd.Block = true
|
||||
}
|
||||
44
modules/sender.go
Normal file
44
modules/sender.go
Normal file
@ -0,0 +1,44 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(sender{})
|
||||
}
|
||||
|
||||
type sender struct{}
|
||||
|
||||
func (sender) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "sender",
|
||||
Version: "0.0.1",
|
||||
Details: "设置群名片群头衔",
|
||||
}
|
||||
}
|
||||
|
||||
func (sender) Start() { // 插件主体
|
||||
promoteManager := zero.OnRegex("^群聊转发.*?(\\d+)\\s(.*)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SendGroupMessage(GetInt(state, 1), GetStr(state, 2))
|
||||
zero.Send(event, "complete!")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
promoteManager.Priority = 30
|
||||
promoteManager.Block = true
|
||||
|
||||
cancleManager := zero.OnRegex("^私聊转发.*?(\\d+)\\s(.*)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SendPrivateMessage(GetInt(state, 1), GetStr(state, 2))
|
||||
zero.Send(event, "complete!")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
cancleManager.Priority = 31
|
||||
cancleManager.Block = true
|
||||
}
|
||||
55
modules/title.go
Normal file
55
modules/title.go
Normal file
@ -0,0 +1,55 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(title{})
|
||||
}
|
||||
|
||||
type title struct{}
|
||||
|
||||
func (title) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "title",
|
||||
Version: "0.0.1",
|
||||
Details: "设置群名片群头衔",
|
||||
}
|
||||
}
|
||||
|
||||
func (title) Start() { // 插件主体
|
||||
setCard := zero.OnRegex("^修改名片.*?(\\d+).*?\\s(.*)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupCard(event.GroupID, GetInt(state, 1), GetStr(state, 2))
|
||||
zero.Send(event, "嗯!已经修改了")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
setCard.Priority = 10
|
||||
setCard.Block = true
|
||||
|
||||
setTitle := zero.OnRegex("^修改头衔.*?(\\d+).*?\\s(.*)", zero.OnlyGroup, zero.AdminPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupSpecialTitle(event.GroupID, GetInt(state, 1), GetStr(state, 2))
|
||||
zero.Send(event, "嗯!已经修改了")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
setTitle.Priority = 11
|
||||
setTitle.Block = true
|
||||
|
||||
setSelfTitle := zero.OnRegex("^申请头衔(.*)").
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupSpecialTitle(event.GroupID, event.UserID, GetStr(state, 2))
|
||||
zero.Send(event, "嗯!不错的头衔呢~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
setSelfTitle.Priority = 12
|
||||
setSelfTitle.Block = true
|
||||
}
|
||||
17
modules/utils.go
Normal file
17
modules/utils.go
Normal file
@ -0,0 +1,17 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gm/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func GetInt(state zero.State, index int64) int64 {
|
||||
fmt.Println(state["regex_matched"].([]string))
|
||||
return utils.Str2Int(state["regex_matched"].([]string)[index])
|
||||
}
|
||||
|
||||
func GetStr(state zero.State, index int64) string {
|
||||
return state["regex_matched"].([]string)[index]
|
||||
}
|
||||
47
utils/utils.go
Normal file
47
utils/utils.go
Normal file
@ -0,0 +1,47 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func PathExecute() string {
|
||||
dir, _ := os.Getwd()
|
||||
return dir + "\\"
|
||||
}
|
||||
|
||||
func PathExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil || os.IsExist(err)
|
||||
}
|
||||
|
||||
func ReadAllText(path string) string {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func WriteAllText(path, text string) {
|
||||
_ = ioutil.WriteFile(path, []byte(text), 0644)
|
||||
}
|
||||
|
||||
func CreatePath(path string) error {
|
||||
err := os.MkdirAll(path, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Int2Str(val int64) string {
|
||||
str := strconv.FormatInt(val, 10)
|
||||
return str
|
||||
}
|
||||
|
||||
func Str2Int(str string) int64 {
|
||||
val, _ := strconv.ParseInt(str, 10, 64)
|
||||
return val
|
||||
}
|
||||
59
utils/yaml.go
Normal file
59
utils/yaml.go
Normal file
@ -0,0 +1,59 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type YamlConfig struct {
|
||||
Version string `yaml:"插件版本"`
|
||||
Host string `yaml:"监听地址"`
|
||||
Port string `yaml:"监听端口"`
|
||||
AccessToken string `yaml:"Token"`
|
||||
Master []string `yaml:"主人QQ"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *YamlConfig {
|
||||
return &YamlConfig{
|
||||
Version: "1",
|
||||
Host: "127.0.0.1",
|
||||
Port: "8080",
|
||||
AccessToken: "",
|
||||
Master: []string{
|
||||
"66666666",
|
||||
"88888888",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func Load(p string) *YamlConfig {
|
||||
if !PathExists(p) {
|
||||
CreatePath(p)
|
||||
DefaultConfig().Save(p)
|
||||
}
|
||||
c := YamlConfig{}
|
||||
err := yaml.Unmarshal([]byte(ReadAllText(p)), &c)
|
||||
if err != nil {
|
||||
fmt.Println("[GroupManager] 尝试加载配置文件失败: 读取文件失败")
|
||||
fmt.Println("[GroupManager] 原配置文件已备份")
|
||||
os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
|
||||
DefaultConfig().Save(p)
|
||||
}
|
||||
c = YamlConfig{}
|
||||
yaml.Unmarshal([]byte(ReadAllText(p)), &c)
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c *YamlConfig) Save(p string) error {
|
||||
data, err := yaml.Marshal(c)
|
||||
if err != nil {
|
||||
fmt.Println("[GroupManager] 写入新的配置文件失败")
|
||||
return err
|
||||
}
|
||||
WriteAllText(p, string(data))
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user