feat: 初始化多机器人服务端项目框架
基于Go语言构建多机器人服务端框架,包含配置管理、事件总线、依赖注入等核心模块 添加项目基础结构、README、gitignore和初始代码实现
This commit is contained in:
107
internal/protocol/action.go
Normal file
107
internal/protocol/action.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package protocol
|
||||
|
||||
// Action 动作接口
|
||||
// 参考OneBot12协议,定义统一的动作操作接口
|
||||
type Action interface {
|
||||
// GetType 获取动作类型
|
||||
GetType() ActionType
|
||||
// GetParams 获取动作参数
|
||||
GetParams() map[string]interface{}
|
||||
// Execute 执行动作
|
||||
Execute(ctx interface{}) (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// ActionType 动作类型
|
||||
type ActionType string
|
||||
|
||||
const (
|
||||
// 消息相关动作
|
||||
ActionTypeSendPrivateMessage ActionType = "send_private_message"
|
||||
ActionTypeSendGroupMessage ActionType = "send_group_message"
|
||||
ActionTypeDeleteMessage ActionType = "delete_message"
|
||||
|
||||
// 用户相关动作
|
||||
ActionTypeGetUserInfo ActionType = "get_user_info"
|
||||
ActionTypeGetFriendList ActionType = "get_friend_list"
|
||||
ActionTypeGetGroupInfo ActionType = "get_group_info"
|
||||
ActionTypeGetGroupMemberList ActionType = "get_group_member_list"
|
||||
|
||||
// 群组相关动作
|
||||
ActionTypeSetGroupKick ActionType = "set_group_kick"
|
||||
ActionTypeSetGroupBan ActionType = "set_group_ban"
|
||||
ActionTypeSetGroupAdmin ActionType = "set_group_admin"
|
||||
ActionTypeSetGroupWholeBan ActionType = "set_group_whole_ban"
|
||||
|
||||
// 其他动作
|
||||
ActionTypeGetStatus ActionType = "get_status"
|
||||
ActionTypeGetVersion ActionType = "get_version"
|
||||
)
|
||||
|
||||
// BaseAction 基础动作结构
|
||||
type BaseAction struct {
|
||||
Type ActionType `json:"type"`
|
||||
Params map[string]interface{} `json:"params"`
|
||||
}
|
||||
|
||||
// GetType 获取动作类型
|
||||
func (a *BaseAction) GetType() ActionType {
|
||||
return a.Type
|
||||
}
|
||||
|
||||
// GetParams 获取动作参数
|
||||
func (a *BaseAction) GetParams() map[string]interface{} {
|
||||
return a.Params
|
||||
}
|
||||
|
||||
// Execute 执行动作(需子类实现)
|
||||
func (a *BaseAction) Execute(ctx interface{}) (map[string]interface{}, error) {
|
||||
return nil, ErrNotImplemented
|
||||
}
|
||||
|
||||
// SendPrivateMessageAction 发送私聊消息动作
|
||||
type SendPrivateMessageAction struct {
|
||||
BaseAction
|
||||
UserID string `json:"user_id"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// SendGroupMessageAction 发送群聊消息动作
|
||||
type SendGroupMessageAction struct {
|
||||
BaseAction
|
||||
GroupID string `json:"group_id"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// DeleteMessageAction 删除消息动作
|
||||
type DeleteMessageAction struct {
|
||||
BaseAction
|
||||
MessageID string `json:"message_id"`
|
||||
}
|
||||
|
||||
// GetUserInfoAction 获取用户信息动作
|
||||
type GetUserInfoAction struct {
|
||||
BaseAction
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
||||
// GetGroupInfoAction 获取群信息动作
|
||||
type GetGroupInfoAction struct {
|
||||
BaseAction
|
||||
GroupID string `json:"group_id"`
|
||||
}
|
||||
|
||||
// 错误定义
|
||||
var (
|
||||
ErrNotImplemented = &ProtocolError{Code: 10001, Message: "action not implemented"}
|
||||
ErrInvalidParams = &ProtocolError{Code: 10002, Message: "invalid parameters"}
|
||||
)
|
||||
|
||||
// ProtocolError 协议错误
|
||||
type ProtocolError struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (e *ProtocolError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
Reference in New Issue
Block a user