chore: update project structure and enhance plugin functionality

- Added new entries to .gitignore for database files.
- Updated go.mod and go.sum to include new indirect dependencies for database and ORM support.
- Refactored event handling to improve message reply functionality in the protocol.
- Enhanced the dispatcher to allow for better event processing and logging.
- Removed outdated plugin documentation and unnecessary files to streamline the codebase.
- Improved welcome message formatting and screenshot options for better user experience.
This commit is contained in:
lafay
2026-01-05 05:14:31 +08:00
parent 64cd81b7f1
commit fb5fae1524
16 changed files with 900 additions and 619 deletions

View File

@@ -2,6 +2,7 @@ package echo
import (
"context"
"strings"
"cellbot/internal/engine"
"cellbot/internal/protocol"
@@ -10,56 +11,27 @@ import (
)
func init() {
// 在 init 函数中注册多个处理函数(类似 ZeroBot 风格)
// 处理私聊消息(使用 OnlyPrivate 中间件,虽然 OnPrivateMessage 已经匹配私聊,这里作为示例)
engine.OnPrivateMessage().
Use(engine.OnlyPrivate()). // 只在私聊中响应
// 注册 /echo 命令
engine.OnCommand("/echo").
Handle(func(ctx context.Context, event protocol.Event, botManager *protocol.BotManager, logger *zap.Logger) error {
// 获取消息内容
data := event.GetData()
message, ok := data["message"]
rawMessage, ok := data["raw_message"].(string)
if !ok {
return nil
}
userID, ok := data["user_id"]
if !ok {
return nil
// 解析命令参数(/echo 后面的内容)
parts := strings.Fields(rawMessage)
if len(parts) < 2 {
// 如果没有参数,返回提示
return event.ReplyText(ctx, botManager, logger, "用法: /echo <消息内容>")
}
// 获取 bot 实例
selfID := event.GetSelfID()
bot, ok := botManager.Get(selfID)
if !ok {
bots := botManager.GetAll()
if len(bots) == 0 {
logger.Error("No bot instance available")
return nil
}
bot = bots[0]
}
// 获取要回显的内容
echoContent := strings.Join(parts[1:], " ")
// 发送回复
action := &protocol.BaseAction{
Type: protocol.ActionTypeSendPrivateMessage,
Params: map[string]interface{}{
"user_id": userID,
"message": message,
},
}
_, err := bot.SendAction(ctx, action)
if err != nil {
logger.Error("Failed to send reply", zap.Error(err))
return err
}
logger.Info("Echo reply sent", zap.Any("user_id", userID))
return nil
// 使用 ReplyText 发送回复
return event.ReplyText(ctx, botManager, logger, echoContent)
})
// 可以继续注册更多处理函数
// engine.OnGroupMessage().Handle(...)
// engine.OnCommand("help").Handle(...)
}