callapi

package
v0.0.0-...-e4931e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallAPIFromDict

func CallAPIFromDict(client Client, s *discordgo.Session, message ActionMessage) string

CallAPIFromDict 处理信息 by calling the 对应的 handler.

func RegisterHandler

func RegisterHandler(action string, handler HandlerFunc)

RegisterHandler registers a new handler for a specific action.

Types

type ActionMessage

type ActionMessage struct {
	Action      string        `json:"action"`
	Params      ParamsContent `json:"params"`
	Echo        interface{}   `json:"echo,omitempty"`
	PostType    string        `json:"post_type,omitempty"`
	MessageType string        `json:"message_type,omitempty"`
}

onebot发来的action调用信息

func (*ActionMessage) UnmarshalJSON

func (a *ActionMessage) UnmarshalJSON(data []byte) error

type Client

type Client interface {
	SendMessage(message map[string]interface{}) error
}

这是一个接口,在wsclient传入client但不需要引用wsclient包,避免循环引用,复用wsserver和client逻辑

type Context

type Context struct {
	Avatar      string `json:"avatar,omitempty"`       // 用户头像链接
	Font        int    `json:"font,omitempty"`         // 字体(假设是整数类型)
	MessageID   int    `json:"message_id,omitempty"`   // 消息 ID
	MessageSeq  int    `json:"message_seq,omitempty"`  // 消息序列号
	MessageType string `json:"message_type,omitempty"` // 消息类型
	PostType    string `json:"post_type,omitempty"`    // 帖子类型
	SubType     string `json:"sub_type,omitempty"`     // 子类型
	Time        int64  `json:"time,omitempty"`         // 时间戳
	UserID      int    `json:"user_id,omitempty"`      // 用户 ID
	GroupID     int    `json:"group_id,omitempty"`     // 群号
}

Context 结构体用于存储 context 字段相关信息

type HandlerFunc

type HandlerFunc func(client Client, s *discordgo.Session, messgae ActionMessage) (string, error)

根据action订阅handler处理api

type Message

type Message struct {
	Action string                 `json:"action"`
	Params map[string]interface{} `json:"params"`
	Echo   interface{}            `json:"echo,omitempty"`
}

Message represents a standardized structure for the incoming messages.

type Operation

type Operation struct {
	Reply    string `json:"reply,omitempty"`     // 回复内容
	AtSender bool   `json:"at_sender,omitempty"` // 是否 @ 发送者
}

Operation 结构体用于存储 operation 字段相关信息

type ParamsContent

type ParamsContent struct {
	BotQQ     string      `json:"botqq"`
	ChannelID string      `json:"channel_id"`
	GuildID   string      `json:"guild_id"`
	GroupID   interface{} `json:"group_id"`           // 每一种onebotv11实现的字段类型都可能不同
	Message   interface{} `json:"message"`            // 这里使用interface{}因为它可能是多种类型
	Messages  interface{} `json:"messages,omitempty"` // 坑爹转发信息
	UserID    interface{} `json:"user_id"`            // 这里使用interface{}因为它可能是多种类型
	Duration  int         `json:"duration,omitempty"` // 可选的整数
	Enable    bool        `json:"enable,omitempty"`   // 可选的布尔值
	// handle quick operation
	Context   Context   `json:"context"`   // context 字段
	Operation Operation `json:"operation"` // operation 字段
}

params类型

func (*ParamsContent) UnmarshalJSON

func (p *ParamsContent) UnmarshalJSON(data []byte) error

自定义一个ParamsContent的UnmarshalJSON 让GroupID同时兼容str和int

type WebSocketServerClienter

type WebSocketServerClienter interface {
	SendMessage(message map[string]interface{}) error
	Close() error
}

为了解决processor和server循环依赖设计的接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL