event

package
v0.0.0-...-d64b273 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeMessageSent EventType = "message_sent"
	EventTypeMessage     EventType = "message"
	EventTypeNotice      EventType = "notice"
	EventTypeRequest     EventType = "request"
	EventTypeMeta        EventType = "meta_event"

	MetaEventTypeLifecycle MetaEventType = "lifecycle"
	MetaEventTypeHeartbeat MetaEventType = "heartbeat"

	MetaEventSubtypeConnect MetaEventSubtype = "connect"
	MetaEventSubtypeDisable MetaEventSubtype = "disable"
	MetaEventSubtypeEnable  MetaEventSubtype = "enable"
	MetaEventSubtypeNone    MetaEventSubtype = ""

	MessageEventTypePrivate MessageEventType = MessageEventType(api.MessageTypePrivate)
	MessageEventTypeGroup   MessageEventType = MessageEventType(api.MessageTypeGroup)

	MessageEventSubtypeFriend    MessageEventSubtype = "friend"
	MessageEventSubtypeGroup     MessageEventSubtype = "group"
	MessageEventSubtypeOther     MessageEventSubtype = "other"
	MessageEventSubtypeNormal    MessageEventSubtype = "normal"
	MessageEventSubtypeAnonymous MessageEventSubtype = "anonymous"
	MessageEventSubtypeNotice    MessageEventSubtype = "notice"

	NoticeEventTypeGroupUpload   NoticeEventType = "group_upload"
	NoticeEventTypeGroupAdmin    NoticeEventType = "group_admin"
	NoticeEventTypeGroupDecrease NoticeEventType = "group_decrease"
	NoticeEventTypeGroupIncrease NoticeEventType = "group_increase"
	NoticeEventTypeGroupBan      NoticeEventType = "group_ban"
	NoticeEventTypeGroupRecall   NoticeEventType = "group_recall"
	NoticeEventTypeFriendAdd     NoticeEventType = "friend_add"
	NoticeEventTypeFriendRecall  NoticeEventType = "friend_recall"
	NoticeEventTypeNotify        NoticeEventType = "notify"

	NoticeEventSubtypeApprove   NoticeEventSubtype = "approve"
	NoticeEventSubtypeInvite    NoticeEventSubtype = "invite"
	NoticeEventSubtypeKick      NoticeEventSubtype = "kick"
	NoticeEventSubtypeLeave     NoticeEventSubtype = "leave"
	NoticeEventSubtypeKickMe    NoticeEventSubtype = "kick_me"
	NoticeEventSubtypeSet       NoticeEventSubtype = "set"
	NoticeEventSubtypeUnset     NoticeEventSubtype = "unset"
	NoticeEventSubtypePoke      NoticeEventSubtype = "poke"
	NoticeEventSubtypeLuckyKing NoticeEventSubtype = "lucky_king"
	NoticeEventSubtypeHonor     NoticeEventSubtype = "honor"
	NoticeEventSubtypeBan       NoticeEventSubtype = "ban"
	NoticeEventSubtypeLiftBan   NoticeEventSubtype = "lift_ban"

	RequestEventTypeFriend RequestEventType = "friend"
	RequestEventTypeGroup  RequestEventType = "group"

	GroupRequestSubtypeAdd    GroupRequestSubtype = "add"
	GroupRequestSubtypeInvite GroupRequestSubtype = "invite"

	HonorTypeTalkative HonorType = "talkative"
	HonorTypePerformer HonorType = "performer"
	HonorTypeEmotion   HonorType = "emotion"
)

Variables

This section is empty.

Functions

func GetAs

func GetAs[T any](e any) *T

func GetAsOrError

func GetAsOrError[T any](e any) (*T, error)

func GetAsUnsafe

func GetAsUnsafe[T any](e any) *T

Types

type BaseEvent

type BaseEvent struct {
	Time      int64     `json:"time"`
	SelfId    qq.UserId `json:"self_id"`
	EventType EventType `json:"post_type"`
	// contains filtered or unexported fields
}

func (*BaseEvent) Context

func (e *BaseEvent) Context() any

func (*BaseEvent) GetError

func (e *BaseEvent) GetError() error

func (*BaseEvent) GetEventType

func (e *BaseEvent) GetEventType() EventType

func (*BaseEvent) GetSelfId

func (e *BaseEvent) GetSelfId() qq.UserId

func (*BaseEvent) GetTime

func (e *BaseEvent) GetTime() int64

func (*BaseEvent) PreventDefault

func (e *BaseEvent) PreventDefault()

func (*BaseEvent) SetContext

func (e *BaseEvent) SetContext(ctx any)

type CmdNameMode

type CmdNameMode string
const (
	CmdNameModePrefix CmdNameMode = "prefix"
	CmdNameModeNormal CmdNameMode = "normal"
)

type CommandCenter

type CommandCenter struct {
	Commands       map[string]ICommand
	PrefixCommands []ICommand
	// contains filtered or unexported fields
}

func NewCommandCenter

func NewCommandCenter(logger *zap.Logger) *CommandCenter

func (*CommandCenter) RegisterCommand

func (c *CommandCenter) RegisterCommand(command ICommand)

func (*CommandCenter) SetGlobalCommandPrefix

func (c *CommandCenter) SetGlobalCommandPrefix(prefix string)

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(logger *zap.Logger, isGoroutineMode bool) *Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(event IEvent)

func (*Dispatcher) RegisterCommand

func (d *Dispatcher) RegisterCommand(command ICommand)

func (*Dispatcher) RegisterHandlerAllTypes

func (d *Dispatcher) RegisterHandlerAllTypes(handler Handler)

func (*Dispatcher) RegisterHandlerGroupMessage

func (d *Dispatcher) RegisterHandlerGroupMessage(handler Handler)

func (*Dispatcher) RegisterHandlerMeta

func (d *Dispatcher) RegisterHandlerMeta(handler Handler)

func (*Dispatcher) RegisterHandlerNotice

func (d *Dispatcher) RegisterHandlerNotice(handler Handler)

func (*Dispatcher) RegisterHandlerPrivateMessage

func (d *Dispatcher) RegisterHandlerPrivateMessage(handler Handler)

func (*Dispatcher) RegisterHandlerRequest

func (d *Dispatcher) RegisterHandlerRequest(handler Handler)

func (*Dispatcher) SetGlobalCommandPrefix

func (d *Dispatcher) SetGlobalCommandPrefix(prefix string)

type EventType

type EventType string

type FriendRequestEvent

type FriendRequestEvent RequestEvent

func (*FriendRequestEvent) Approve

func (e *FriendRequestEvent) Approve(remark string) error

Approve 同意好友请求

func (*FriendRequestEvent) Reject

func (e *FriendRequestEvent) Reject(reason string) error

Reject 拒绝好友请求,reason 为拒绝理由

type GroupMessageEvent

type GroupMessageEvent struct {
	MessageEvent
	GroupId   qq.GroupId       `json:"group_id"`
	Anonymous qq.AnonymousData `json:"anonymous"`
	Sender    qq.GroupUser     `json:"sender"`
}

func (*GroupMessageEvent) Reply

func (e *GroupMessageEvent) Reply(msg *message.Chain, quote bool) (qq.MessageId, error)

func (*GroupMessageEvent) ReplyAt

func (e *GroupMessageEvent) ReplyAt(msg *message.Chain, quote bool, at bool) (qq.MessageId, error)

func (*GroupMessageEvent) ReplyString

func (e *GroupMessageEvent) ReplyString(msg string, autoEscape bool, quote bool, at bool) (qq.MessageId, error)

type GroupNoticeEvent

type GroupNoticeEvent struct {
	NoticeEvent
	GroupId qq.GroupId `json:"group_id"`
}

type GroupRequestEvent

type GroupRequestEvent struct {
	RequestEvent
	SubType GroupRequestSubtype `json:"sub_type"`
	GroupId qq.GroupId          `json:"group_id"`
}

func (*GroupRequestEvent) Approve

func (e *GroupRequestEvent) Approve() error

Approve 同意加群请求

func (*GroupRequestEvent) Reject

func (e *GroupRequestEvent) Reject(reason string) error

Reject 拒绝加群请求,reason 为拒绝理由

type GroupRequestSubtype

type GroupRequestSubtype string

type Handler

type Handler func(event IEvent)

type HonorType

type HonorType string

type ICommand

type ICommand interface {
	GetName() (string, CmdNameMode)
	// GetNew 用于获取一个新的命令行参数定义结构体。
	// 它将被传入回调函数。具体请参考 kong 的文档。
	GetNew() any
	GetOptions() []kong.Option
	SplitBySpaceOnly() bool
	OnCommand(parseResult *ParseResult)
}

type ICommandStopPropagation

type ICommandStopPropagation interface {
	// StopPropagation 返回 true 时,事件将在指令处理完成后停止继续处理其它处理器。
	StopPropagation() bool
}

type ICommandWithPreprocess

type ICommandWithPreprocess interface {
	Preprocess(remaining string) string
}

type IEvent

type IEvent interface {
	GetTime() int64
	GetSelfId() qq.UserId
	GetEventType() EventType

	// PreventDefault 阻止事件继续传播。别问我为什么取这个名字。
	// 当 BotConfig.UseGoroutine 为 true 时,这个函数无效。
	PreventDefault()
	GetError() error

	SetContext(any)
	Context() any
	// contains filtered or unexported methods
}

func ParseEvent

func ParseEvent(data []byte, apiSender *api.Sender) (IEvent, error)

type IMessageEvent

type IMessageEvent interface {
	IEvent
	GetMessageEventType() MessageEventType
	GetMessageId() qq.MessageId
	GetMessage() *message.Chain
	GetRawMessage() string

	Reply(msg *message.Chain, quote bool) (qq.MessageId, error)
}

type MessageEvent

type MessageEvent struct {
	BaseEvent
	MessageType MessageEventType    `json:"message_type"`
	SubType     MessageEventSubtype `json:"sub_type"`
	MessageId   qq.MessageId        `json:"message_id"`
	UserId      qq.UserId           `json:"user_id"`
	Message     *message.Chain      `json:"message"`
	RawMessage  string              `json:"raw_message"`
	Font        int32               `json:"font"`
}

func (*MessageEvent) GetMessage

func (e *MessageEvent) GetMessage() *message.Chain

func (*MessageEvent) GetMessageEventType

func (e *MessageEvent) GetMessageEventType() MessageEventType

func (*MessageEvent) GetMessageId

func (e *MessageEvent) GetMessageId() qq.MessageId

func (*MessageEvent) GetRawMessage

func (e *MessageEvent) GetRawMessage() string

func (*MessageEvent) Reply

func (e *MessageEvent) Reply(msg *message.Chain, quote bool) (qq.MessageId, error)

type MessageEventSubtype

type MessageEventSubtype string

type MessageEventType

type MessageEventType api.MessageType

type MetaEvent

type MetaEvent struct {
	BaseEvent
	MetaEventType MetaEventType     `json:"meta_event_type"`
	SubType       MetaEventSubtype  `json:"sub_type"`
	Status        *api.ServerStatus `json:"status"`
	Interval      int64             `json:"interval"`
}

type MetaEventSubtype

type MetaEventSubtype string

type MetaEventType

type MetaEventType string

type NoticeEvent

type NoticeEvent struct {
	BaseEvent
	NoticeType NoticeEventType    `json:"notice_type"`
	SubType    NoticeEventSubtype `json:"sub_type"`
	UserId     qq.UserId          `json:"user_id"`
}

type NoticeEventFriendAdd

type NoticeEventFriendAdd NoticeEvent

type NoticeEventFriendRecall

type NoticeEventFriendRecall struct {
	NoticeEvent
	MessageId qq.MessageId `json:"message_id"`
}

type NoticeEventGroupBan

type NoticeEventGroupBan struct {
	NoticeEventGroupOperation
	Duration int64 `json:"duration"`
}

type NoticeEventGroupHonor

type NoticeEventGroupHonor struct {
	GroupNoticeEvent
	HonorType HonorType `json:"honor_type"`
}

type NoticeEventGroupNotify

type NoticeEventGroupNotify struct {
	GroupNoticeEvent
	TargetId qq.UserId `json:"target_id"`
}

type NoticeEventGroupOperation

type NoticeEventGroupOperation struct {
	GroupNoticeEvent
	OperatorId qq.UserId `json:"operator_id"`
}

type NoticeEventGroupRecall

type NoticeEventGroupRecall struct {
	GroupNoticeEvent
	MessageId qq.MessageId `json:"message_id"`
}

type NoticeEventGroupUpload

type NoticeEventGroupUpload struct {
	GroupNoticeEvent
	File struct {
		Id    string `json:"id"`
		Name  string `json:"name"`
		Size  int64  `json:"size"`
		Busid int64  `json:"busid"`
	} `json:"file"`
}

type NoticeEventSubtype

type NoticeEventSubtype string

type NoticeEventType

type NoticeEventType string

type ParseResult

type ParseResult struct {
	Ctx        *kong.Context
	Event      IMessageEvent
	ParsedArgs any
	Error      error
	ExitCode   int
	StdOut     string
	StdErr     string
}

func NewParseResult

func NewParseResult() *ParseResult

type PrivateMessageEvent

type PrivateMessageEvent struct {
	MessageEvent
	Sender qq.User `json:"sender"`
}

func (*PrivateMessageEvent) Reply

func (e *PrivateMessageEvent) Reply(msg *message.Chain, quote bool) (qq.MessageId, error)

func (*PrivateMessageEvent) ReplyString

func (e *PrivateMessageEvent) ReplyString(msg string, autoEscape bool, quote bool) (qq.MessageId, error)

type RequestEvent

type RequestEvent struct {
	BaseEvent
	RequestType RequestEventType `json:"request_type"`
	UserId      qq.UserId        `json:"user_id"`
	Comment     string           `json:"comment"`
	Flag        string           `json:"flag"`
}

type RequestEventType

type RequestEventType string

Jump to

Keyboard shortcuts

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