This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
写给开发者的话
Enjoy edited this page Jul 27, 2021
·
3 revisions
虽然机器人自带了很多功能,但我相信这些功能可能都满足不了你,所以在这里我写一些插件开发的注意点,欢迎PR功能到仓库里哟❤️❤️
type Module struct {
}
var (
log *logrus.Entry
)
func (m *Module) ModuleInfo() Core.ModuleInfo {
return Core.ModuleInfo{
Name: "词云生成",
Author: "enjoy",
Description: "给群生成聊天词云 还可以查询奥运信息呢!",
Version: 0,
//RequireModule: []string{"群管理插件"}, 如果需要在面板上开发接口就必须依赖于 群管理插件
}
}
func (m *Module) ModuleInit(b *Core.Bot, l *logrus.Entry) error {
log = l
err := b.AddEvent(OPQBot.EventNameOnGroupMessage, func(botQQ int64, packet *OPQBot.GroupMsgPack) {
...
return nil
}
func init() {
Core.RegisterModule(&Module{})
}
在将插件写好后需要在/main.go
里引用才行哟
package main
import (
_ "OPQBot-QQGroupManager/wordCloud"
...
)
err := b.BotCronManager.AddJob(-1, "setuAuto", "0 8 * * *", func() {
p.autoGetPic()
})
if err != nil {
log.Error(err)
}
// 0 是分钟 8 是小时 没有秒 注意
在/main.go
里我们可以看见有一条命令_ = BanWord.Hook(&b)
这个就是Hook的函数
func Hook(b *Core.Bot) error {
b.AddEvent(OPQBot.EventNameOnGroupMessage, func(botQQ int64, packet *OPQBot.GroupMsgPack) {
if packet.FromUserID == botQQ {
return
}
Config.Lock.RLock()
var c Config.GroupConfig
if v, ok := Config.CoreConfig.GroupConfig[packet.FromGroupID]; ok {
c = v
} else {
c = Config.CoreConfig.DefaultGroupConfig
}
banQQ := Config.CoreConfig.BanQQ
Config.Lock.RUnlock()
for _, v := range banQQ {
if packet.FromUserID == v {
packet.Ban = true //拦截了消息 后面的插件都收不到 的是
return
}
}
if !c.Enable {
return
}
if m, err := regexp.MatchString(c.ShutUpWord, packet.Content); err != nil {
log.Println(err)
return
} else if m {
err := packet.Bot.ReCallMsg(packet.FromGroupID, packet.MsgRandom, packet.MsgSeq)
if err != nil {
log.Println(err)
}
err = packet.Bot.SetForbidden(1, c.ShutUpTime, packet.FromGroupID, packet.FromUserID)
if err != nil {
log.Println(err)
}
packet.Bot.SendGroupTextMsg(packet.FromGroupID, OPQBot.MacroAt([]int64{packet.FromUserID})+"触发违禁词")
packet.Ban = true
return
}
})
return nil
}