Documentation
¶
Index ¶
- type Group
- type GroupMember
- type GroupSession
- type MessageHistory
- type MessageRecord
- type MockServer
- func (server *MockServer) ConnectedEvent() gonebot.LifeCycleMetaEvent
- func (server *MockServer) HandleRequest(action string, params gjson.Result) (interface{}, error)
- func (server *MockServer) NewGroupSession(groupId int64) *GroupSession
- func (server *MockServer) NewPrivateSession(userId int64) *PrivateSession
- func (server *MockServer) RegisterEventReciever(reciever chan<- gonebot.I_Event)
- func (server *MockServer) SendEvent(event gonebot.I_Event)
- type NewMockServerOptions
- type PrivateSession
- func (s *PrivateSession) GetMessageHistory() MessageHistory
- func (s *PrivateSession) MessageEvent(msg gonebot.Message) gonebot.PrivateMessageEvent
- func (s *PrivateSession) MessageEventByText(txt string) gonebot.PrivateMessageEvent
- func (s *PrivateSession) PokeEvent() gonebot.PokeNoticeEvent
- func (s *PrivateSession) RecallEvent(msgId int32) gonebot.FriendRecallNoticeEvent
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
GroupId int64 `json:"group_id"` // 群号
GroupName string `json:"group_name"` // 群名
MemberCount int32 `json:"member_count"` // 群成员数
Members []GroupMember `json:"-"`
}
func (*Group) AddMember ¶
func (group *Group) AddMember(member GroupMember)
func (*Group) GetMember ¶
func (group *Group) GetMember(userId int64) *GroupMember
func (*Group) RemoveMember ¶
type GroupMember ¶
type GroupMember struct {
UserId int64 `json:"user_id"`
Nickname string `json:"nickname"` // 昵称
Age int32 `json:"age"`
Sex string `json:"sex"`
Card string `json:"card"` // 群名片、群备注
Role string `json:"role"` // 角色 member owner admin
Title string `json:"title"` // 头衔
Level string `json:"level"` // 等级
Area string `json:"area"` // 地区
}
type GroupSession ¶
type GroupSession struct {
Server *MockServer
BotId int64 // 机器人QQ号
GroupId int64 // 群号
GroupName string // 群名
Group Group
}
群聊会话
func (*GroupSession) AnonymousMessageEvent ¶
func (s *GroupSession) AnonymousMessageEvent(anonymous gonebot.Anonymous, msg gonebot.Message) gonebot.GroupMessageEvent
模拟一个群聊匿名消息事件
func (*GroupSession) GetMessageHistory ¶
func (s *GroupSession) GetMessageHistory() MessageHistory
获取聊天记录
func (*GroupSession) MessageEvent ¶
func (s *GroupSession) MessageEvent(userId int64, msg gonebot.Message) gonebot.GroupMessageEvent
模拟一个群聊消息事件。当userId不存在时,会当作普通成员发送消息。
type MessageHistory ¶
type MessageHistory []MessageRecord
func (MessageHistory) Len ¶
func (history MessageHistory) Len() int
func (MessageHistory) Less ¶
func (history MessageHistory) Less(i, j int) bool
func (MessageHistory) String ¶
func (history MessageHistory) String() string
func (MessageHistory) Swap ¶
func (history MessageHistory) Swap(i, j int)
type MessageRecord ¶
type MessageRecord struct {
MsgId int32
Msg gonebot.Message
UserId int64 // 发送者
Nickname string // 发送者昵称
Time int64 // 发送时间,unix时间戳
GroupId int64 // 群号,私聊为0
SessionId int64 // 私聊时为对方的 QQ 号,群聊时为群号
}
一条消息
func (*MessageRecord) IsGroupMessage ¶
func (r *MessageRecord) IsGroupMessage() bool
func (*MessageRecord) String ¶
func (r *MessageRecord) String() string
type MockServer ¶
type MockServer struct {
BotId int64 // 机器人QQ号
BotName string // 机器人昵称
Friends []User // 好友列表
Groups []Group // 群聊列表
AutoSendEvent bool // 是否自动发送事件,默认true
// contains filtered or unexported fields
}
模拟的协议提供端
func NewMockServer ¶
func NewMockServer(options NewMockServerOptions) *MockServer
func (*MockServer) ConnectedEvent ¶
func (server *MockServer) ConnectedEvent() gonebot.LifeCycleMetaEvent
模拟一个生命周期的Connected事件
func (*MockServer) HandleRequest ¶
func (server *MockServer) HandleRequest(action string, params gjson.Result) (interface{}, error)
处理API请求
func (*MockServer) NewGroupSession ¶
func (server *MockServer) NewGroupSession(groupId int64) *GroupSession
创建群聊会话。groupId为群号。若群号不存在,则创建一个空群聊。
func (*MockServer) NewPrivateSession ¶
func (server *MockServer) NewPrivateSession(userId int64) *PrivateSession
创建私聊会话。userId为对方的QQ号,如果这个QQ号是好友,后续模拟的消息事件的SubType将为"friend",否则为"other"
func (*MockServer) RegisterEventReciever ¶
func (server *MockServer) RegisterEventReciever(reciever chan<- gonebot.I_Event)
注册事件接收器,注册后会自动发送一个Connected的生命周期事件
type NewMockServerOptions ¶
type PrivateSession ¶
type PrivateSession struct {
Server *MockServer
IsFriend bool
UserId int64
Nickname string
Sex string
Age int32
BotId int64
}
私聊会话
func (*PrivateSession) GetMessageHistory ¶
func (s *PrivateSession) GetMessageHistory() MessageHistory
获取聊天记录
func (*PrivateSession) MessageEvent ¶
func (s *PrivateSession) MessageEvent(msg gonebot.Message) gonebot.PrivateMessageEvent
模拟一个私聊消息事件
func (*PrivateSession) MessageEventByText ¶
func (s *PrivateSession) MessageEventByText(txt string) gonebot.PrivateMessageEvent
模拟一个私聊消息事件
func (*PrivateSession) PokeEvent ¶
func (s *PrivateSession) PokeEvent() gonebot.PokeNoticeEvent
模拟戳一戳事件
func (*PrivateSession) RecallEvent ¶
func (s *PrivateSession) RecallEvent(msgId int32) gonebot.FriendRecallNoticeEvent
模拟撤回消息事件
Click to show internal directories.
Click to hide internal directories.