mock

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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

func (group *Group) RemoveMember(userId int64)

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"`  // 地区
}

func (*GroupMember) SetAdmin

func (m *GroupMember) SetAdmin()

设置为管理员

func (*GroupMember) SetMember

func (m *GroupMember) SetMember()

设置为普通成员

func (*GroupMember) SetOwner

func (m *GroupMember) SetOwner()

设置为群主

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的生命周期事件

func (*MockServer) SendEvent

func (server *MockServer) SendEvent(event gonebot.I_Event)

下发事件

type NewMockServerOptions

type NewMockServerOptions struct {
	BotId   int64
	BotName string
	Friends []User
	Groups  []Group

	SendEventTimeout time.Duration
}

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 (*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

模拟撤回消息事件

type User

type User struct {
	UserId   int64  `json:"user_id"`
	Nickname string `json:"nickname"`
	Sex      string `json:"sex"`
	Age      int32  `json:"age"`
}

Jump to

Keyboard shortcuts

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