mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
🎨 improve code
This commit is contained in:
parent
dbf8aa27f2
commit
2ad5102297
@ -1,37 +0,0 @@
|
||||
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]====================
|
||||
* OneBot + ZeroBot + Golang
|
||||
* Copyright © 2018-2020 Kanri, All Rights Reserved
|
||||
* Project: https://github.com/Yiwen-Chan/GroupManager
|
||||
=======================================================
|
||||
`)
|
||||
Conf = utils.Load("./GroupManager.yml")
|
||||
m.Conf = Conf
|
||||
fmt.Println("[GroupManager] 有需要请按 GitHub 项目上描述的方法修改配置文件")
|
||||
}
|
||||
8
go.mod
8
go.mod
@ -1,8 +1,8 @@
|
||||
module gm
|
||||
module bot
|
||||
|
||||
go 1.14
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20201209121757-2a04edb62bac
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20210212165900-0c6c4d79b40e
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
)
|
||||
|
||||
38
go.sum
38
go.sum
@ -1,15 +1,23 @@
|
||||
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/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
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/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
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/modern-go/reflect2 v1.0.2-0.20210109003243-333559e1834b h1:6Xjqolv/0DDdUqlpnsTomXQvjvvkz7Ux7TcMALvozEw=
|
||||
github.com/modern-go/reflect2 v1.0.2-0.20210109003243-333559e1834b/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
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=
|
||||
@ -18,20 +26,28 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
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/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
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/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
|
||||
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
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-20201209121757-2a04edb62bac h1:foT1gSWW3Ovkecyqoircrp2kP5pajSTUawwom9GLSlM=
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20201209121757-2a04edb62bac/go.mod h1:e92qGONnOry8XSfaUUlG7OhT9gyD839P8oZ2wfPe60w=
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20210212165900-0c6c4d79b40e h1:BaUnQOFcCU4l+uf+mifbPdzrBtYfGeDM9RgIFhMBRLs=
|
||||
github.com/wdvxdr1123/ZeroBot v0.0.0-20210212165900-0c6c4d79b40e/go.mod h1:MC6+vOkILANgHlEvZpDMKLNeOWSde5eRgiGFtNGix/4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
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=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
256
groupmanager/group_manager.go
Normal file
256
groupmanager/group_manager.go
Normal file
@ -0,0 +1,256 @@
|
||||
package groupmanager
|
||||
|
||||
import (
|
||||
"bot/groupmanager/utils"
|
||||
"time"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(groupManager{}) // 注册插件
|
||||
}
|
||||
|
||||
type groupManager struct{} // pixivSearch 搜索P站插图
|
||||
|
||||
func (_ groupManager) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "GroupManager",
|
||||
Version: "0.0.1",
|
||||
Details: "群管",
|
||||
}
|
||||
}
|
||||
|
||||
func (_ groupManager) Start() { // 插件主体
|
||||
// TODO 菜单
|
||||
zero.OnFullMatch("群管系统").SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.Send(event, `====群管====
|
||||
- 禁言@QQ 1
|
||||
- 解除禁言 @QQ
|
||||
- 我要自闭 1分钟
|
||||
- 开启全员禁言
|
||||
- 解除全员禁言
|
||||
- 升为管理@QQ
|
||||
- 取消管理@QQ
|
||||
- 修改名片@QQ XXX
|
||||
- 修改头衔@QQ XXX
|
||||
- 申请头衔 XXX
|
||||
- 群聊转发 1234 XXX
|
||||
- 私聊转发 0000 XXX`)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 升为管理
|
||||
zero.OnRegex(`^升为管理.*?(\d+)`, zero.OnlyGroup, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被升为管理的人的qq
|
||||
true,
|
||||
)
|
||||
nickname := zero.GetGroupMemberInfo( // 被升为管理的人的昵称
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被升为管理的人的qq
|
||||
false,
|
||||
).Get("nickname").Str
|
||||
zero.Send(
|
||||
event,
|
||||
nickname+" 升为了管理~",
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 取消管理
|
||||
zero.OnRegex(`^取消管理.*?(\d+)`, zero.OnlyGroup, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被取消管理的人的qq
|
||||
false,
|
||||
)
|
||||
nickname := zero.GetGroupMemberInfo( // 被取消管理的人的昵称
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被取消管理的人的qq
|
||||
false,
|
||||
).Get("nickname").Str
|
||||
zero.Send(
|
||||
event,
|
||||
"残念~ "+nickname+" 暂时失去了管理员的资格",
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 踢出群聊
|
||||
zero.OnRegex(`^踢出群聊.*?(\d+)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被踢出群聊的人的qq
|
||||
false,
|
||||
)
|
||||
nickname := zero.GetGroupMemberInfo( // 被踢出群聊的人的昵称
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被踢出群聊的人的qq
|
||||
false,
|
||||
).Get("nickname").Str
|
||||
zero.Send(
|
||||
event,
|
||||
"残念~ "+nickname+" 被放逐",
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 退出群聊
|
||||
zero.OnRegex(`^退出群聊.*?(\d+)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupLeave(
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 要退出的群的群号
|
||||
true,
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 开启全体禁言
|
||||
zero.OnRegex(`^开启全员禁言$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupWholeBan(
|
||||
event.GroupID,
|
||||
true,
|
||||
)
|
||||
zero.Send(event, "全员自闭开始~")
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 解除全体禁言
|
||||
zero.OnRegex(`^解除全体禁言$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupWholeBan(
|
||||
event.GroupID,
|
||||
false,
|
||||
)
|
||||
zero.Send(event, "全员自闭结束~")
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 禁言
|
||||
zero.OnRegex(`^禁言.*?(\d+).*?\s(\d+)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 要禁言的人的qq
|
||||
utils.Str2Int(state["regex_matched"].([]string)[2])*60, // 要禁言的时间(分钟)
|
||||
)
|
||||
zero.Send(event, "小黑屋收留成功~")
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 解除禁言
|
||||
zero.OnRegex(`^解除禁言.*?(\d+)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 要解除禁言的人的qq
|
||||
0,
|
||||
)
|
||||
zero.Send(event, "小黑屋释放成功~")
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 自闭禁言
|
||||
zero.OnRegex(`^我要自闭.*?(\d+)分钟`, zero.OnlyGroup).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(
|
||||
event.GroupID,
|
||||
event.UserID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1])*60, // 要自闭的时间(分钟)
|
||||
)
|
||||
zero.Send(event, "那我就不手下留情了~")
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 修改名片
|
||||
zero.OnRegex(`^修改名片.*?(\d+).*?\s(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupCard(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被修改群名片的人
|
||||
state["regex_matched"].([]string)[2], // 修改成的群名片
|
||||
)
|
||||
zero.Send(
|
||||
event,
|
||||
"嗯!已经修改了",
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 修改头衔
|
||||
zero.OnRegex(`^修改头衔.*?(\d+).*?\s(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupSpecialTitle(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被修改群头衔的人
|
||||
state["regex_matched"].([]string)[2], // 修改成的群头衔
|
||||
)
|
||||
zero.Send(
|
||||
event,
|
||||
"嗯!已经修改了",
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 申请头衔
|
||||
zero.OnRegex(`^申请头衔(.*)`, zero.OnlyGroup).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupSpecialTitle(
|
||||
event.GroupID,
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 被修改群头衔的人
|
||||
state["regex_matched"].([]string)[2], // 修改成的群头衔
|
||||
)
|
||||
zero.Send(
|
||||
event,
|
||||
"嗯!不错的头衔呢~",
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 群聊转发
|
||||
zero.OnRegex(`^群聊转发.*?(\d+)\s(.*)`, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SendGroupMessage(
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 需要发送的群
|
||||
state["regex_matched"].([]string)[1], // 需要发送的信息
|
||||
)
|
||||
zero.Send(
|
||||
event,
|
||||
"📧 --> "+state["regex_matched"].([]string)[1],
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 私聊转发
|
||||
zero.OnRegex(`^私聊转发.*?(\d+)\s(.*)`, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SendPrivateMessage(
|
||||
utils.Str2Int(state["regex_matched"].([]string)[1]), // 需要发送的人的qq
|
||||
state["regex_matched"].([]string)[1], // 需要发送的信息
|
||||
)
|
||||
zero.Send(
|
||||
event,
|
||||
"📧 --> "+state["regex_matched"].([]string)[1],
|
||||
)
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 戳一戳
|
||||
zero.OnNotice().SetBlock(true).SetPriority(40).
|
||||
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
|
||||
})
|
||||
// TODO 入群欢迎
|
||||
zero.OnNotice().SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.NoticeType == "group_increase" {
|
||||
zero.Send(event, "欢迎~")
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
// TODO 退群提醒
|
||||
zero.OnNotice().SetBlock(true).SetPriority(40).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
if event.NoticeType == "group_increase" {
|
||||
zero.Send(event, "有人跑路了~")
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
})
|
||||
}
|
||||
15
groupmanager/utils/utils.go
Normal file
15
groupmanager/utils/utils.go
Normal file
@ -0,0 +1,15 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
38
main.go
Normal file
38
main.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
|
||||
_ "bot/groupmanager"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetFormatter(&easy.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
LogFormat: "[zero][%time%][%lvl%]: %msg% \n",
|
||||
})
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf(`
|
||||
====================[GroupManager]====================
|
||||
* OneBot + ZeroBot + Golang
|
||||
* Copyright © 2018-2020 Kanri, All Rights Reserved
|
||||
* Project: https://github.com/Yiwen-Chan/GroupManager
|
||||
=======================================================
|
||||
`)
|
||||
zero.Run(zero.Option{
|
||||
Host: "127.0.0.1",
|
||||
Port: "6700",
|
||||
AccessToken: "",
|
||||
NickName: []string{"椛椛"},
|
||||
CommandPrefix: "/",
|
||||
SuperUsers: []string{"825111790"},
|
||||
})
|
||||
select {}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gm/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
var Conf = &utils.YamlConfig{}
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(menu{})
|
||||
}
|
||||
|
||||
type menu struct{}
|
||||
|
||||
func (menu) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "menu",
|
||||
Version: "0.0.1",
|
||||
Details: "菜单",
|
||||
}
|
||||
}
|
||||
|
||||
func (menu) Start() { // 插件主体
|
||||
gmmenu := zero.OnRegex("^群管系统$").
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
menuText := `====群管====
|
||||
- 禁言@QQ 1
|
||||
- 解除禁言 @QQ
|
||||
- 我要自闭 1分钟
|
||||
- 开启全员禁言
|
||||
- 解除全员禁言
|
||||
- 升为管理@QQ
|
||||
- 取消管理@QQ
|
||||
- 修改名片@QQ XXX
|
||||
- 修改头衔@QQ XXX
|
||||
- 申请头衔 XXX
|
||||
- 群聊转发 1234 XXX
|
||||
- 私聊转发 0000 XXX`
|
||||
zero.Send(event, fmt.Sprintf("%v", menuText))
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
gmmenu.Priority = 60
|
||||
gmmenu.Block = true
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
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.SuperUserPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(event.GroupID, GetInt(state, 1), true)
|
||||
nickname := GetNickname(event.GroupID, GetInt(state, 1))
|
||||
zero.Send(event, nickname+" 升为了管理~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
promoteManager.Priority = 20
|
||||
promoteManager.Block = true
|
||||
|
||||
cancleManager := zero.OnRegex("^取消管理.*?(\\d+)", zero.OnlyGroup, zero.SuperUserPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupAdmin(event.GroupID, GetInt(state, 1), false)
|
||||
nickname := GetNickname(event.GroupID, GetInt(state, 1))
|
||||
zero.Send(event, "残念~ "+nickname+" 暂时失去了管理员的资格")
|
||||
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)
|
||||
nickname := GetNickname(event.GroupID, GetInt(state, 1))
|
||||
zero.Send(event, "残念~ "+nickname+"("+GetStr(state, 1)+") 被放逐")
|
||||
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(GetInt(state, 1), true)
|
||||
zero.Send(event, "姬气人已主动离开群聊 "+GetStr(state, 1))
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
leave.Priority = 23
|
||||
leave.Block = true
|
||||
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
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)*60)
|
||||
zero.Send(event, "小黑屋收留成功~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
ban.Priority = 4
|
||||
ban.Block = true
|
||||
|
||||
selfBan := zero.OnRegex("^我要自闭.*?(\\d+)分钟", zero.OnlyGroup).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupBan(event.GroupID, event.UserID, GetInt(state, 1)*60)
|
||||
zero.Send(event, "那我就不手下留情了")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
selfBan.Priority = 5
|
||||
selfBan.Block = true
|
||||
}
|
||||
@ -1,61 +0,0 @@
|
||||
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
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
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 == "group" {
|
||||
nickname := GetNickname(event.GroupID, event.UserID)
|
||||
if event.SubType == "add" {
|
||||
zero.Send(event, nickname+"("+utils.Int2Str(event.UserID)+") 申请加群")
|
||||
} else {
|
||||
zero.SendPrivateMessage(utils.Str2Int(Conf.Master[0]), nickname+"("+utils.Int2Str(event.UserID)+") 邀请我加入群 "+utils.Int2Str(event.GroupID))
|
||||
}
|
||||
}
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
groupAdd.Priority = 51
|
||||
groupAdd.Block = true
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
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.SuperUserPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SendGroupMessage(GetInt(state, 1), GetStr(state, 2))
|
||||
zero.Send(event, "📧 --> "+GetStr(state, 1))
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
promoteManager.Priority = 30
|
||||
promoteManager.Block = true
|
||||
|
||||
cancleManager := zero.OnRegex("^私聊转发.*?(\\d+)\\s(.*)", zero.SuperUserPermission).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SendPrivateMessage(GetInt(state, 1), GetStr(state, 2))
|
||||
zero.Send(event, "📧 --> "+GetStr(state, 1))
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
cancleManager.Priority = 31
|
||||
cancleManager.Block = true
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
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("^申请头衔(.*)", zero.OnlyGroup).
|
||||
Handle(
|
||||
func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
zero.SetGroupSpecialTitle(event.GroupID, event.UserID, GetStr(state, 1))
|
||||
zero.Send(event, "嗯!不错的头衔呢~")
|
||||
return zero.SuccessResponse
|
||||
},
|
||||
)
|
||||
setSelfTitle.Priority = 12
|
||||
setSelfTitle.Block = true
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"gm/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func GetInt(state zero.State, index int64) int64 {
|
||||
return utils.Str2Int(state["regex_matched"].([]string)[index])
|
||||
}
|
||||
|
||||
func GetStr(state zero.State, index int64) string {
|
||||
return state["regex_matched"].([]string)[index]
|
||||
}
|
||||
|
||||
func GetNickname(groupID int64, userID int64) string {
|
||||
return zero.GetGroupMemberInfo(groupID, userID, false).Get("nickname").Str
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
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
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
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) {
|
||||
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