1
0
forked from lxh/go-wxhelper
go-wxhelper/initialization/plugin.go

39 lines
863 B
Go
Raw Permalink Normal View History

2023-12-11 10:53:21 +08:00
package initialization
import (
"go-wechat/common/current"
"go-wechat/model"
plugin "go-wechat/plugin"
"go-wechat/plugin/plugins"
)
// Plugin
// @description: 初始化插件
func Plugin() {
// 定义一个处理器
dispatcher := plugin.NewMessageMatchDispatcher()
// 设置为异步处理
dispatcher.SetAsync(true)
// 注册插件
// 保存消息进数据库
dispatcher.RegisterHandler(func(*model.Message) bool {
return true
}, plugins.SaveToDb)
// AI消息插件
dispatcher.RegisterHandler(func(m *model.Message) bool {
// 群内@或者私聊文字消息
return m.IsAt() || m.IsPrivateText()
}, plugins.AI)
// 欢迎新成员
dispatcher.RegisterHandler(func(m *model.Message) bool {
return m.IsNewUserJoin()
}, plugins.WelcomeNew)
// 注册消息处理器
current.SetRobotMessageHandler(plugin.DispatchMessage(dispatcher))
}