onebot

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anonymous

type Anonymous struct {
	ID   int64  `json:"id" mapstructure:"id"`
	Name string `json:"name" mapstructure:"name"`
	Flag string `json:"flag,omitempty" mapstructure:"flag,omitempty"`
}

type AtSegment

type AtSegment struct {
	Segment `mapstructure:",squash"`
}

func NewAt

func NewAt(target string) *AtSegment

func (*AtSegment) Target

func (s *AtSegment) Target() string

type Client

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

func NewClient

func NewClient(log zerolog.Logger, id, token string, service *Service) *Client

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(id int32) error

func (*Client) DownloadMedia

func (c *Client) DownloadMedia(seg ISegment) (string, []byte, error)

func (*Client) GetFriendList

func (c *Client) GetFriendList() ([]*UserInfo, error)

func (*Client) GetGroupInfo

func (c *Client) GetGroupInfo(id string) (*GroupInfo, error)

func (*Client) GetGroupList

func (c *Client) GetGroupList() ([]*GroupInfo, error)

func (*Client) GetGroupMemberInfo

func (c *Client) GetGroupMemberInfo(gid string, uid string) (*MemberInfo, error)

func (*Client) GetGroupMemberList

func (c *Client) GetGroupMemberList(id string) ([]*MemberInfo, error)

func (*Client) GetLoginInfo

func (c *Client) GetLoginInfo() (*UserInfo, error)

func (*Client) GetToken

func (c *Client) GetToken() string

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(id string) (*UserInfo, error)

func (*Client) IsLoggedIn

func (c *Client) IsLoggedIn() bool

func (*Client) Release

func (c *Client) Release()

func (*Client) SendGroupMessage

func (c *Client) SendGroupMessage(groupID int64, segments []ISegment) (*SendMessageResponse, error)

func (*Client) SendPrivateMessage

func (c *Client) SendPrivateMessage(userID int64, segments []ISegment) (*SendMessageResponse, error)

func (*Client) SetEventHandler

func (c *Client) SetEventHandler(handler func(IEvent))

func (*Client) StartLoop

func (c *Client) StartLoop(conn *websocket.Conn)

type ContactSegment

type ContactSegment struct {
	Segment `mapstructure:",squash"`
}

type Event

type Event struct {
	Time     int64  `json:"time" mapstructure:"time"`
	SelfID   int64  `json:"self_id" mapstructure:"self_id"`
	PostType string `json:"post_type" mapstructure:"post_type"`
}

func (*Event) EventType

func (e *Event) EventType() EventType

func (*Event) PayloadType

func (e *Event) PayloadType() PayloadType

type EventType

type EventType string
const (
	MessagePrivate             EventType = "message_private"
	MessageGroup               EventType = "message_group"
	MetaLifecycle              EventType = "meta_lifecycle"
	MetaHeartbeat              EventType = "meta_heartbeat"
	NoticeOfflineFile          EventType = "notice_offline_file"
	NoticeGroupUpload          EventType = "notice_group_upload"
	NoticeGroupAdminSet        EventType = "notice_group_admin_set"
	NoticeGroupAdminUnset      EventType = "notice_group_admin_unset"
	NoticeGroupDecreaseleave   EventType = "notice_group_decrease_leave"
	NoticeGroupDecreaseKick    EventType = "notice_group_decrease_kick"
	NoticeGroupDecreaseKickMe  EventType = "notice_group_decrease_kick_me"
	NoticeGroupIncreaseApprove EventType = "notice_group_increase_approve"
	NoticeGroupIncreaseInvite  EventType = "notice_group_increase_invite"
	NoticeGroupBanBan          EventType = "notice_group_ban_ban"
	NoticeGroupBanLiftBan      EventType = "notice_group_ban_lift_ban"
	NoticeFriendAdd            EventType = "notice_friend_add"
	NoticeGroupRecall          EventType = "notice_group_recall"
	NoticeFriendRecall         EventType = "notice_friend_recall"
	NoticeNotifyPoke           EventType = "notice_notify_poke"
	NoticeNotifyLuckyKing      EventType = "notice_notify_lucky_king"
	NoticeNotifyHonnor         EventType = "notice_notify_honnor"
	RequestFriend              EventType = "request_friend"
	RequestGroupAdd            EventType = "request_group_add"
	RequestGroupInvite         EventType = "request_group_invite"
	EventUnknown               EventType = "event_unknown"
)

type FaceSegment

type FaceSegment struct {
	Segment `mapstructure:",squash"`
}

func NewFace

func NewFace(id string) *FaceSegment

func (*FaceSegment) ID

func (s *FaceSegment) ID() string

type FileInfo

type FileInfo struct {
	ID       string `json:"id,omitempty" mapstructure:"id,omitempty"`
	Name     string `json:"name,omitempty" mapstructure:"name,omitempty"`
	File     string `json:"file,omitempty" mapstructure:"file,omitempty"`
	FileName string `json:"file_name,omitempty" mapstructure:"file_name,omitempty"`
	URL      string `json:"url" mapstructure:"url"`
	Base64   string `json:"base64,omitempty" mapstructure:"base64,omitempty"`
}

type FileSegment

type FileSegment struct {
	Segment `mapstructure:",squash"`
}

func NewFile

func NewFile(file, name string) *FileSegment

func (*FileSegment) File

func (s *FileSegment) File() string

type ForwardSegment

type ForwardSegment struct {
	Segment `mapstructure:",squash"`
}

func (*ForwardSegment) ID

func (s *ForwardSegment) ID() string

type FriendRecall

type FriendRecall struct {
	Event      `mapstructure:",squash"`
	NoticeType string `json:"notice_type" mapstructure:"notice_type"`
	UserID     int64  `json:"user_id" mapstructure:"user_id"`
	MessageID  int64  `json:"message_id" mapstructure:"message_id"`
}

func (*FriendRecall) EventType

func (g *FriendRecall) EventType() EventType

type GroupInfo

type GroupInfo struct {
	ID   int64  `json:"group_id" mapstructure:"group_id"`
	Name string `json:"group_name,omitempty" mapstructure:"group_name,omitempty"`
}

type GroupRecall

type GroupRecall struct {
	Event      `mapstructure:",squash"`
	NoticeType string `json:"notice_type" mapstructure:"notice_type"`
	GroupID    int64  `json:"group_id" mapstructure:"group_id"`
	UserID     int64  `json:"user_id" mapstructure:"user_id"`
	OperatorID int64  `json:"operator_id" mapstructure:"operator_id"`
	MessageID  int64  `json:"message_id" mapstructure:"message_id"`
}

func (*GroupRecall) EventType

func (g *GroupRecall) EventType() EventType

type Heartbeat

type Heartbeat struct {
	Event         `mapstructure:",squash"`
	MetaEventType string `json:"meta_event_type" mapstructure:"meta_event_type"`
	Status        Status `json:"status" mapstructure:"status"`
	Interval      int64  `json:"interval" mapstructure:"interval"`
}

func (*Heartbeat) EventType

func (h *Heartbeat) EventType() EventType

type IEvent

type IEvent interface {
	EventType() EventType
}

type ISegment

type ISegment interface {
	SegmentType() SegmentType
}

type ImageSegment

type ImageSegment struct {
	Segment `mapstructure:",squash"`
}

func NewImage

func NewImage(file, name string) *ImageSegment

func (*ImageSegment) File

func (s *ImageSegment) File() string

func (*ImageSegment) IsSticker

func (s *ImageSegment) IsSticker() bool

func (*ImageSegment) URL

func (s *ImageSegment) URL() string

type JSONSegment

type JSONSegment struct {
	Segment `mapstructure:",squash"`
}

func (*JSONSegment) Content

func (s *JSONSegment) Content() string

type Lifecycle

type Lifecycle struct {
	Event         `mapstructure:",squash"`
	MetaEventType string `json:"meta_event_type" mapstructure:"meta_event_type"`
	SubType       string `json:"sub_type" mapstructure:"sub_type"`
}

func (*Lifecycle) EventType

func (lc *Lifecycle) EventType() EventType

type LightAPPSegment

type LightAPPSegment struct {
	Segment `mapstructure:",squash"`
}

type LocationSegment

type LocationSegment struct {
	Segment `mapstructure:",squash"`
}

func (*LocationSegment) Content

func (s *LocationSegment) Content() string

func (*LocationSegment) Latitude

func (s *LocationSegment) Latitude() float64

func (*LocationSegment) Longitude

func (s *LocationSegment) Longitude() float64

func (*LocationSegment) Title

func (s *LocationSegment) Title() string

type MarketFaceSegment

type MarketFaceSegment struct {
	Segment `mapstructure:",squash"`
}

func (*MarketFaceSegment) Content

func (s *MarketFaceSegment) Content() string

func (*MarketFaceSegment) File

func (s *MarketFaceSegment) File() string

func (*MarketFaceSegment) URL

func (s *MarketFaceSegment) URL() string

type MemberInfo

type MemberInfo struct {
	UserID   int64  `json:"user_id" mapstructure:"user_id"`
	GroupID  int64  `json:"group_id" mapstructure:"group_id"`
	Nickname string `json:"nickname,omitempty" mapstructure:"nickname,omitempty"`
	Card     string `json:"card,omitempty" mapstructure:"card,omitempty"`
	Role     string `json:"role,omitempty" mapstructure:"role,omitempty"`
}

type Message

type Message struct {
	Event       `mapstructure:",squash"`
	MessageType string    `json:"message_type" mapstructure:"message_type"`
	SubType     string    `json:"sub_type" mapstructure:"sub_type"`
	MessageID   int32     `json:"message_id" mapstructure:"message_id"`
	GroupID     int64     `json:"group_id,omitempty" mapstructure:"group_id,omitempty"`
	UserID      int64     `json:"user_id" mapstructure:"user_id"`
	TargetID    int64     `json:"target_id,omitempty" mapstructure:"target_id,omitempty"`
	Anonymous   Anonymous `json:"anonymous,omitempty" mapstructure:"anonymous,omitempty"`
	Message     any       `json:"message" mapstructure:"message"`
	Font        int32     `json:"font" mapstructure:"font"`
	Sender      Sender    `json:"sender" mapstructure:"sender"`
}

func (*Message) EventType

func (m *Message) EventType() EventType

type MusicSegment

type MusicSegment struct {
	Segment `mapstructure:",squash"`
}

type NodeSegment

type NodeSegment struct {
	Segment `mapstructure:",squash"`
}

func NewJSON

func NewJSON(content string) *NodeSegment

func (*NodeSegment) ID

func (s *NodeSegment) ID() string

type Payload

type Payload interface {
	PayloadType() PayloadType
}

func UnmarshalPayload

func UnmarshalPayload(m map[string]interface{}) (Payload, error)

type PayloadType

type PayloadType string
const (
	PaylaodRequest  PayloadType = "request"
	PayloadResponse PayloadType = "response"
	PayloadEvent    PayloadType = "event"
)

type RecordSegment

type RecordSegment struct {
	Segment `mapstructure:",squash"`
}

func NewRecord

func NewRecord(file, name string) *RecordSegment

func (*RecordSegment) File

func (s *RecordSegment) File() string

type ReplySegment

type ReplySegment struct {
	Segment `mapstructure:",squash"`
}

func NewReply

func NewReply(id string) *ReplySegment

func (*ReplySegment) ID

func (s *ReplySegment) ID() string

type Request

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

func NewDeleteMsgRequest

func NewDeleteMsgRequest(messageID int32) *Request

func NewGetFileRequest

func NewGetFileRequest(fileID string) *Request

func NewGetForwardMsgRequest

func NewGetForwardMsgRequest(msgID string) *Request

func NewGetFriendListRequest

func NewGetFriendListRequest() *Request

func NewGetGroupInfoRequest

func NewGetGroupInfoRequest(groupID int64) *Request

func NewGetGroupListRequest

func NewGetGroupListRequest() *Request

func NewGetGroupMemberInfoRequest

func NewGetGroupMemberInfoRequest(groupID, userID int64) *Request

func NewGetGroupMemberListRequest

func NewGetGroupMemberListRequest(groupID int64) *Request

func NewGetImageRequest

func NewGetImageRequest(fileID string) *Request

func NewGetLoginInfoRequest

func NewGetLoginInfoRequest() *Request

func NewGetRecordRequest

func NewGetRecordRequest(fileID string) *Request

func NewGetUserInfoRequest

func NewGetUserInfoRequest(userID int64) *Request

func NewGroupMsgRequest

func NewGroupMsgRequest(groupID int64, segments []ISegment) *Request

func NewPrivateMsgRequest

func NewPrivateMsgRequest(userID int64, segments []ISegment) *Request

func (*Request) PayloadType

func (r *Request) PayloadType() PayloadType

type RequestType

type RequestType string
const (
	// OneBot11
	SendPrivateMsg       RequestType = "send_private_msg"
	SendGroupMsg         RequestType = "send_group_msg"
	SendMsg              RequestType = "send_msg"
	DeleteMsg            RequestType = "delete_msg"
	GetMsg               RequestType = "get_msg"
	GetForwardMsg        RequestType = "get_forward_msg"
	SendLike             RequestType = "send_like"
	SetGroupKick         RequestType = "set_group_kick"
	SetGroupBan          RequestType = "set_group_ban"
	SetGroupAnonymousBan RequestType = "set_group_anonymous_ban"
	SetGroupWholeBan     RequestType = "set_group_whole_ban"
	SetGroupAdmin        RequestType = "set_group_admin"
	SetGroupAnonymous    RequestType = "set_group_anonymous"
	SetGroupCard         RequestType = "set_group_card"
	SetGroupName         RequestType = "set_group_name"
	SetGroupLeave        RequestType = "set_group_leave"
	SetGroupSpecialTitle RequestType = "set_group_special_title"
	SetFriendAddRequest  RequestType = "set_friend_add_request"
	SetGroupAddRequest   RequestType = "set_group_add_request"
	GetLoginInfo         RequestType = "get_login_info"
	GetStrangerInfo      RequestType = "get_stranger_info"
	GetFriendList        RequestType = "get_friend_list"
	GetGroupInfo         RequestType = "get_group_info"
	GetGroupList         RequestType = "get_group_list"
	GetGroupMemberInfo   RequestType = "get_group_member_info"
	GetGroupMemberList   RequestType = "get_group_member_list"
	GetGroupHonorInfo    RequestType = "get_group_honor_info"
	GetCookies           RequestType = "get_cookies"
	GetCSRFToken         RequestType = "get_csrf_token"
	GetCredentials       RequestType = "get_credentials"
	GetRecord            RequestType = "get_record"
	GetImage             RequestType = "get_image"
	CanSendImage         RequestType = "can_send_image"
	CanSendRecord        RequestType = "can_send_record"
	GetStatus            RequestType = "get_status"
	GetVersionInfo       RequestType = "get_version_info"
	SetRestart           RequestType = "set_restart"
	CleanCache           RequestType = "clean_cache"

	// go-cqhttp
	MarkMsgAsRead         RequestType = "mark_msg_as_read"
	SendGroupForwardMsg   RequestType = "send_group_forward_msg"
	SendPrivateForwardMsg RequestType = "send_private_forward_msg"
	GetGroupMsgHistory    RequestType = "get_group_msg_history"
	UploadGroupFile       RequestType = "upload_group_file"
	DownloadFile          RequestType = "download_file"

	// NapCat
	GetFile                RequestType = "get_file"
	ForwardFriendSingleMsg RequestType = "forward_friend_single_msg"
	ForwardGroupSingleMsg  RequestType = "forward_group_single_msg"
	SendForwardMsg         RequestType = "send_forward_msg"
	MarkPrivateMsgAsRead   RequestType = "mark_private_msg_as_read"
	MarkGroupMsgAsRead     RequestType = "mark_private_msg_as_read"
	GetFriendMsgHistory    RequestType = "get_friend_msg_history"
)

type Response

type Response struct {
	Status  string `json:"status"`
	Retcode int32  `json:"retcode"`
	Data    any    `json:"params,omitempty"`
	Echo    string `json:"echo,omitempty"`
}

func (*Response) PayloadType

func (r *Response) PayloadType() PayloadType

type Segment

type Segment struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data"`
}

func (*Segment) SegmentType

func (s *Segment) SegmentType() SegmentType

type SegmentType

type SegmentType string
const (
	Text       SegmentType = "text"
	Face       SegmentType = "face"
	MarketFace SegmentType = "mface"
	Image      SegmentType = "image"
	Record     SegmentType = "record"
	Video      SegmentType = "video"
	File       SegmentType = "file"
	At         SegmentType = "at"
	Share      SegmentType = "share"
	Contact    SegmentType = "contact"
	Location   SegmentType = "location"
	Music      SegmentType = "music"
	LightAPP   SegmentType = "lightapp"
	Reply      SegmentType = "reply"
	Forward    SegmentType = "forward"
	Node       SegmentType = "node"
	XML        SegmentType = "xml"
	JSON       SegmentType = "json"
)

type SendMessageResponse

type SendMessageResponse struct {
	MessageID int32 `json:"message_id" mapstructure:"message_id"`
}

type Sender

type Sender struct {
	UserID   int64  `json:"user_id" mapstructure:"user_id"`
	Nickname string `json:"nickname,omitempty" mapstructure:"nickname,omitempty"`
	Card     string `json:"card,omitempty" mapstructure:"card,omitempty"`
	Sex      string `json:"sex,omitempty" mapstructure:"sex,omitempty"`
	Age      int32  `json:"age,omitempty" mapstructure:"age,omitempty"`
	Area     string `json:"area,omitempty" mapstructure:"area,omitempty"`
	Level    int32  `json:"level,omitempty" mapstructure:"level,omitempty"`
	Role     string `json:"role,omitempty" mapstructure:"role,omitempty"`
	Title    string `json:"title,omitempty" mapstructure:"title,omitempty"`
}

type Service

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

func NewService

func NewService(log zerolog.Logger, endpoint string, timeout time.Duration) *Service

func (*Service) NewClient

func (s *Service) NewClient(log zerolog.Logger, id, token string) *Client

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Service) Start

func (s *Service) Start()

func (*Service) Stop

func (s *Service) Stop()

type ShareSegment

type ShareSegment struct {
	Segment `mapstructure:",squash"`
}

func (*ShareSegment) Content

func (s *ShareSegment) Content() string

func (*ShareSegment) Image

func (s *ShareSegment) Image() string

func (*ShareSegment) Title

func (s *ShareSegment) Title() string

func (*ShareSegment) URL

func (s *ShareSegment) URL() string

type Status

type Status struct {
	Online bool `json:"online" mapstructure:"online"`
	Good   bool `json:"good" mapstructure:"good"`
}

type TextSegment

type TextSegment struct {
	Segment `mapstructure:",squash"`
}

func NewText

func NewText(content string) *TextSegment

func (*TextSegment) Content

func (s *TextSegment) Content() string

type UserInfo

type UserInfo struct {
	ID       int64  `json:"user_id" mapstructure:"user_id"`
	Nickname string `json:"nickname,omitempty" mapstructure:"nickname,omitempty"`
	Remark   string `json:"remark,omitempty" mapstructure:"remark,omitempty"`
}

type VideoSegment

type VideoSegment struct {
	Segment `mapstructure:",squash"`
}

func NewVideo

func NewVideo(file, name string) *VideoSegment

func (*VideoSegment) File

func (s *VideoSegment) File() string

func (*VideoSegment) URL

func (s *VideoSegment) URL() string

type XMLSegment

type XMLSegment struct {
	Segment `mapstructure:",squash"`
}

func (*XMLSegment) Content

func (s *XMLSegment) Content() string

Jump to

Keyboard shortcuts

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