Documentation ¶
Overview ¶
Package qqbotapi has functions and types used for interacting with the Coolq HTTP API.
Index ¶
- func NewFileBase64(file interface{}) (string, error)
- func NewFileLocal(file string) string
- func NewImageBase64(file interface{}) (*cqcode.Image, error)
- func NewImageLocal(file string) *cqcode.Image
- func NewRecordBase64(file interface{}) (*cqcode.Record, error)
- func NewRecordLocal(file string) *cqcode.Record
- type APIResponse
- type BaseChat
- type BaseUpdateConfig
- type BotAPI
- func (bot *BotAPI) DeleteMessage(messageID int64) (APIResponse, error)
- func (bot *BotAPI) Do(c Chattable) (APIResponse, error)
- func (bot *BotAPI) EnableAnonymousChat(groupID int64, enable bool) (APIResponse, error)
- func (bot *BotAPI) GetGroupList() ([]Group, error)
- func (bot *BotAPI) GetGroupMemberInfo(groupID int64, userID int64, noCache bool) (User, error)
- func (bot *BotAPI) GetGroupMemberList(groupID int64) ([]User, error)
- func (bot *BotAPI) GetMe() (User, error)
- func (bot *BotAPI) GetStrangerInfo(userID int64) (User, error)
- func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error)
- func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error)
- func (bot *BotAPI) HandleFriendRequest(flag string, approve bool, remark string) (APIResponse, error)
- func (bot *BotAPI) HandleGroupRequest(flag string, typ string, approve bool, reason string) (APIResponse, error)
- func (bot *BotAPI) IsMessageToMe(message Message) bool
- func (bot *BotAPI) KickChatMember(groupID int64, userID int64, rejectAddRequest bool) (APIResponse, error)
- func (bot *BotAPI) LeaveChat(chatID int64, chatType string, dismiss bool) (APIResponse, error)
- func (bot *BotAPI) Like(userID int64, times int) (APIResponse, error)
- func (bot *BotAPI) ListenForWebSocket(config WebhookConfig) UpdatesChannel
- func (bot *BotAPI) ListenForWebhook(config WebhookConfig) UpdatesChannel
- func (bot *BotAPI) ListenForWebhookSync(config WebhookConfig, handler func(update Update) interface{})
- func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error)
- func (bot *BotAPI) NewMessage(chatID int64, chatType string) *Sender
- func (bot *BotAPI) PreloadUserInfo(update *Update)
- func (bot *BotAPI) PromoteChatMember(groupID int64, userID int64, enable bool) (APIResponse, error)
- func (bot *BotAPI) RestrictAllChatMembers(groupID int64, enable bool) (APIResponse, error)
- func (bot *BotAPI) RestrictAnonymousChatMember(groupID int64, flag string, duration time.Duration) (APIResponse, error)
- func (bot *BotAPI) RestrictChatMember(groupID int64, userID int64, duration time.Duration) (APIResponse, error)
- func (bot *BotAPI) Send(c Chattable) (Message, error)
- func (bot *BotAPI) SendMessage(chatID int64, chatType string, message interface{}) (Message, error)
- func (bot *BotAPI) SetChatMemberCard(groupID int64, userID int64, card string) (APIResponse, error)
- func (bot *BotAPI) SetChatMemberTitle(groupID int64, userID int64, title string, duration time.Duration) (APIResponse, error)
- type Chat
- type ChatMemberConfig
- type Chattable
- type DeleteMessageConfig
- type EnableAnonymousChatConfig
- type Ev
- type File
- type FlatSender
- func (sender *FlatSender) At(QQ string) *FlatSender
- func (sender *FlatSender) Emoji(emojiID int) *FlatSender
- func (sender *FlatSender) Face(faceID int) *FlatSender
- func (sender *FlatSender) FaceByName(faceName string) *FlatSender
- func (sender *FlatSender) ImageBase64(file interface{}) *FlatSender
- func (sender *FlatSender) ImageLocal(file string) *FlatSender
- func (sender *FlatSender) ImageWeb(url *url.URL) *FlatSender
- func (sender *FlatSender) NewLine() *FlatSender
- func (sender *FlatSender) Send() *Sender
- func (sender *FlatSender) Sface(sfaceID int) *FlatSender
- func (sender *FlatSender) Text(text string) *FlatSender
- type Group
- type GroupControlConfig
- type HandleFriendRequestConfig
- type HandleGroupRequestConfig
- type HandleRequestConfig
- type KickChatMemberConfig
- type LeaveChatConfig
- type LikeConfig
- type Message
- type MessageConfig
- type NetImage
- type NetRecord
- type NetResource
- type PromoteChatMemberConfig
- type RestrictAllChatMembersConfig
- type RestrictChatMemberConfig
- type Sender
- func (sender *Sender) Bface(bfaceID int) *Sender
- func (sender *Sender) Dice() *Sender
- func (sender *Sender) Location(loc cqcode.Location) *Sender
- func (sender *Sender) Music(music cqcode.Music) *Sender
- func (sender *Sender) RecordBase64(file interface{}, magic bool) *Sender
- func (sender *Sender) RecordLocal(file string, magic bool) *Sender
- func (sender *Sender) RecordWeb(url *url.URL, magic bool) *Sender
- func (sender *Sender) Rps() *Sender
- func (sender *Sender) Shake(emojiID int) *Sender
- func (sender *Sender) Share(share cqcode.Share) *Sender
- func (sender *Sender) Show(id int) *Sender
- func (sender *Sender) Sign(sign cqcode.Sign) *Sender
- type SetChatMemberCardConfig
- type SetChatMemberTitleConfig
- type Unsubscribe
- type Update
- type UpdateConfig
- type UpdatesChannel
- type User
- type WebSocketRequest
- type WebhookConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFileBase64 ¶
NewFileBase64 formats a file into base64 format.
func NewFileLocal ¶
NewFileLocal formats a file with the file path, returning the string.
This method is deprecated and will get removed, see #11. Please use NewFileWeb instead.
func NewImageBase64 ¶
NewImageBase64 formats an image in base64.
func NewImageLocal ¶
NewImageLocal formats an image with the file path, this requires CQ HTTP runs in the same host with your bot.
This method is deprecated and will get removed, see #11. Please use NewImageWeb instead.
func NewRecordBase64 ¶
NewRecordBase64 formats a record in base64.
func NewRecordLocal ¶
NewRecordLocal formats a record with the file path, this requires CQ HTTP runs in the same host with your bot.
This method is deprecated and will get removed, see #11. Please use NewRecordWeb instead.
Types ¶
type APIResponse ¶
type APIResponse struct { Status string `json:"status"` Data json.RawMessage `json:"data"` RetCode int `json:"retcode"` Echo interface{} `json:"echo"` }
APIResponse is a response from the Coolq HTTP API with the result stored raw.
type BaseUpdateConfig ¶
type BaseUpdateConfig struct {
PreloadUserInfo bool // if this is enabled, more information will be provided in Update.From
}
BaseUpdateConfig contains information about loading updates.
type BotAPI ¶
type BotAPI struct { Token string `json:"token"` Secret string `json:"secret"` Debug bool `json:"debug"` Buffer int `json:"buffer"` APIEndpoint string `json:"api_endpoint"` Self User `json:"-"` Client *http.Client `json:"-"` WSAPIClient *websocket.Conn `json:"-"` WSEventClient *websocket.Conn `json:"-"` WSPendingRequests map[int]chan APIResponse `json:"-"` WSPendingMux sync.Mutex `json:"-"` WSRequestTimeout time.Duration `json:"-"` Echo int `json:"-"` EchoMux sync.Mutex `json:"-"` }
BotAPI allows you to interact with the Coolq HTTP API.
func NewBotAPI ¶
NewBotAPI creates a new BotAPI instance.
token: access_token, api: API Endpoint of Coolq-http, example: http://host:port. secret: the secret key of HMAC SHA1 signature of Coolq-HTTP, won't be validated if left blank.
func NewBotAPIWithClient ¶
NewBotAPIWithClient creates a new BotAPI instance
It requires a token, an API endpoint and a secret which you set in Coolq HTTP API.
func NewBotAPIWithWSClient ¶
NewBotAPIWithWSClient creates a new BotAPI instance
It requires a token, an API endpoint which you set in Coolq HTTP API.
func (*BotAPI) DeleteMessage ¶
func (bot *BotAPI) DeleteMessage(messageID int64) (APIResponse, error)
DeleteMessage deletes a message in a chat.
func (*BotAPI) Do ¶
func (bot *BotAPI) Do(c Chattable) (APIResponse, error)
Do will send a Chattable item to Coolq.
It requires the Chattable to send.
func (*BotAPI) EnableAnonymousChat ¶
func (bot *BotAPI) EnableAnonymousChat(groupID int64, enable bool) (APIResponse, error)
EnableAnonymousChat : By this enabled, members in a group will be able to send messages with an anonymous identity.
func (*BotAPI) GetGroupList ¶
GetGroupList fetches all groups
func (*BotAPI) GetGroupMemberInfo ¶
GetGroupMemberInfo fetches a group member's user info.
Using cache may result in not updating in time, but will be responded faster
func (*BotAPI) GetGroupMemberList ¶
GetGroupMemberList fetches a group all member's user info.
This information might be not full or accurate enough.
func (*BotAPI) GetMe ¶
GetMe fetches the currently authenticated bot.
This method is called upon creation to validate the token, and so you may get this data from BotAPI.Self without the need for another request.
func (*BotAPI) GetStrangerInfo ¶
GetStrangerInfo fetches a stranger's user info.
func (*BotAPI) GetUpdates ¶
func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error)
GetUpdates fetches updates over long polling or websocket. https://github.com/richardchien/cqhttp-ext-long-polling
Offset, Limit, and Timeout are optional. To avoid stale items, set Offset to one higher than the previous item. Set Timeout to a large number to reduce requests so you can get updates instantly instead of having to wait between requests.
func (*BotAPI) GetUpdatesChan ¶
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error)
GetUpdatesChan starts and returns a channel that gets updates over long polling or websocket. https://github.com/richardchien/cqhttp-ext-long-polling
func (*BotAPI) HandleFriendRequest ¶
func (bot *BotAPI) HandleFriendRequest(flag string, approve bool, remark string) (APIResponse, error)
HandleFriendRequest handles a friend request.
remark: 备注
func (*BotAPI) HandleGroupRequest ¶
func (bot *BotAPI) HandleGroupRequest(flag string, typ string, approve bool, reason string) (APIResponse, error)
HandleGroupRequest handles a group adding request.
typ: sub_type in Update reason: Reason if you rejects this request.
func (*BotAPI) IsMessageToMe ¶
IsMessageToMe returns true if message directed to this bot.
It requires the Message.
func (*BotAPI) KickChatMember ¶
func (bot *BotAPI) KickChatMember(groupID int64, userID int64, rejectAddRequest bool) (APIResponse, error)
KickChatMember kick a chat member in a group.
func (*BotAPI) Like ¶
func (bot *BotAPI) Like(userID int64, times int) (APIResponse, error)
Like sends like (displayed in one's profile page) to a user.
func (*BotAPI) ListenForWebSocket ¶
func (bot *BotAPI) ListenForWebSocket(config WebhookConfig) UpdatesChannel
ListenForWebSocket registers a http handler for a websocket and returns a channel that gets updates.
func (*BotAPI) ListenForWebhook ¶
func (bot *BotAPI) ListenForWebhook(config WebhookConfig) UpdatesChannel
ListenForWebhook registers a http handler for a webhook and returns a channel that gets updates.
func (*BotAPI) ListenForWebhookSync ¶
func (bot *BotAPI) ListenForWebhookSync(config WebhookConfig, handler func(update Update) interface{})
ListenForWebhookSync registers a http handler for a webhook.
handler receives a update and returns a key-value dictionary.
func (*BotAPI) MakeRequest ¶
MakeRequest makes a request to a specific endpoint with our token.
func (*BotAPI) NewMessage ¶
NewMessage sends message to a chat.
func (*BotAPI) PreloadUserInfo ¶
PreloadUserInfo fills in the information in update.Message.From
func (*BotAPI) PromoteChatMember ¶
PromoteChatMember add admin rights to user.
func (*BotAPI) RestrictAllChatMembers ¶
func (bot *BotAPI) RestrictAllChatMembers(groupID int64, enable bool) (APIResponse, error)
RestrictAllChatMembers : By this enabled, only administrators in a group will be able to send messages.
func (*BotAPI) RestrictAnonymousChatMember ¶
func (bot *BotAPI) RestrictAnonymousChatMember(groupID int64, flag string, duration time.Duration) (APIResponse, error)
RestrictAnonymousChatMember bans an anonymous chat member from sending messages.
func (*BotAPI) RestrictChatMember ¶
func (bot *BotAPI) RestrictChatMember(groupID int64, userID int64, duration time.Duration) (APIResponse, error)
RestrictChatMember bans a chat member from sending messages.
func (*BotAPI) Send ¶
Send will send a Chattable item to Coolq. The response will be regarded as Message, often with a MessageID in it.
It requires the Chattable to send.
func (*BotAPI) SendMessage ¶
SendMessage sends message to a chat.
func (*BotAPI) SetChatMemberCard ¶
SetChatMemberCard sets a chat member's 群名片 in the group.
func (*BotAPI) SetChatMemberTitle ¶
func (bot *BotAPI) SetChatMemberTitle(groupID int64, userID int64, title string, duration time.Duration) (APIResponse, error)
SetChatMemberTitle sets a chat member's 专属头衔 in the group.
type Chat ¶
type Chat struct { ID int64 `json:"id"` Type string `json:"type"` // "private"、"group"、"discuss" SubType string `json:"sub_type"` // (only when Type is "private") "friend"、"group"、"discuss"、"other" }
Chat contains information about the place a message was sent.
type ChatMemberConfig ¶
ChatMemberConfig contains information about a user in a chat for use with administrative functions such as kicking or unbanning a user.
type Chattable ¶
type Chattable interface {
// contains filtered or unexported methods
}
Chattable is any config type that can be sent.
type DeleteMessageConfig ¶
type DeleteMessageConfig struct {
MessageID int64
}
DeleteMessageConfig contains information of a message in a chat to delete.
type EnableAnonymousChatConfig ¶
type EnableAnonymousChatConfig struct {
GroupControlConfig
}
EnableAnonymousChatConfig contains fields to enable anonymous chat.
type Ev ¶
type Ev struct {
// contains filtered or unexported fields
}
func NewEv ¶
func NewEv(channel UpdatesChannel) *Ev
type File ¶
type File struct { ID string `json:"id"` Name string `json:"name"` Size int64 `json:"size"` BusID int64 `json:"busid"` }
File is a file.
type FlatSender ¶
type FlatSender struct { ChatID int64 ChatType string Result *Message Err error // contains filtered or unexported fields }
func (*FlatSender) At ¶
func (sender *FlatSender) At(QQ string) *FlatSender
func (*FlatSender) Emoji ¶
func (sender *FlatSender) Emoji(emojiID int) *FlatSender
func (*FlatSender) Face ¶
func (sender *FlatSender) Face(faceID int) *FlatSender
func (*FlatSender) FaceByName ¶
func (sender *FlatSender) FaceByName(faceName string) *FlatSender
func (*FlatSender) ImageBase64 ¶
func (sender *FlatSender) ImageBase64(file interface{}) *FlatSender
func (*FlatSender) ImageLocal ¶
func (sender *FlatSender) ImageLocal(file string) *FlatSender
This method is deprecated and will get removed, see #11. Please use ImageWeb instead.
func (*FlatSender) ImageWeb ¶
func (sender *FlatSender) ImageWeb(url *url.URL) *FlatSender
func (*FlatSender) NewLine ¶
func (sender *FlatSender) NewLine() *FlatSender
func (*FlatSender) Send ¶
func (sender *FlatSender) Send() *Sender
func (*FlatSender) Sface ¶
func (sender *FlatSender) Sface(sfaceID int) *FlatSender
func (*FlatSender) Text ¶
func (sender *FlatSender) Text(text string) *FlatSender
type GroupControlConfig ¶
GroupControlConfig contains fields as a configuration of a group.
type HandleFriendRequestConfig ¶
type HandleFriendRequestConfig struct { HandleRequestConfig Remark string }
HandleFriendRequestConfig contains fields to handle a friend request.
type HandleGroupRequestConfig ¶
type HandleGroupRequestConfig struct { HandleRequestConfig Type string Reason string }
HandleGroupRequestConfig contains fields to handle a group adding request.
type HandleRequestConfig ¶
HandleRequestConfig contains fields to handle a request.
type KickChatMemberConfig ¶
type KickChatMemberConfig struct { ChatMemberConfig RejectAddRequest bool }
KickChatMemberConfig contains extra fields to kick user.
type LeaveChatConfig ¶
LeaveChatConfig contains fields to leave a chat.
type LikeConfig ¶
LikeConfig contains information of a like (displayed on personal profile page) to send.
type Message ¶
type Message struct { *cqcode.Message `json:"message"` MessageID int64 `json:"message_id"` From *User `json:"from"` Chat *Chat `json:"chat"` Text string `json:"text"` SubType string `json:"sub_type"` // (only when Chat.Type is "group") "normal"、"anonymous"、"notice" Font int `json:"font"` }
Message is returned by almost every request, and contains data about almost anything.
func (Message) IsAnonymous ¶
IsAnonymous returns if a message is an anonymous message.
type MessageConfig ¶
MessageConfig contains information about a SendMessage request.
func NewMessage ¶
func NewMessage(chatID int64, chatType string, message interface{}) MessageConfig
NewMessage creates a new Message.
chatID is where to send it, message is the message.
type NetImage ¶
type NetImage struct { *cqcode.Image *NetResource }
NetImage is an image located in the Internet.
func NewImageWeb ¶
NewImageWeb formats an image with the URL.
type NetRecord ¶
type NetRecord struct { *cqcode.Record *NetResource }
NetRecord is a record located in the Internet.
func NewRecordWeb ¶
NewRecordWeb formats a record with the URL.
type NetResource ¶
type NetResource struct {
Cache int `cq:"cache"`
}
NetResource is a resource located in the Internet.
func (*NetResource) DisableCache ¶
func (r *NetResource) DisableCache()
DisableCache forces CQ HTTP download from the URL instead of using cache.
func (*NetResource) EnableCache ¶
func (r *NetResource) EnableCache()
EnableCache enables CQ HTTP's cache feature.
type PromoteChatMemberConfig ¶
type PromoteChatMemberConfig struct { ChatMemberConfig Enable bool }
PromoteChatMemberConfig contains fields to promote members of chat.
type RestrictAllChatMembersConfig ¶
type RestrictAllChatMembersConfig struct {
GroupControlConfig
}
RestrictAllChatMembersConfig contains fields to restrict all chat members.
type RestrictChatMemberConfig ¶
type RestrictChatMemberConfig struct { ChatMemberConfig Duration time.Duration }
RestrictChatMemberConfig contains fields to restrict members of chat.
type Sender ¶
type Sender struct {
*FlatSender
}
func (*Sender) RecordBase64 ¶
func (*Sender) RecordLocal ¶
This method is deprecated and will get removed, see #11. Please use RecordWeb instead.
type SetChatMemberCardConfig ¶
type SetChatMemberCardConfig struct { ChatMemberConfig Card string }
SetChatMemberCardConfig contains fields to set members's 群名片.
type SetChatMemberTitleConfig ¶
type SetChatMemberTitleConfig struct { ChatMemberConfig SpecialTitle string Duration time.Duration }
SetChatMemberTitleConfig contains fields to set members's 专属头衔.
type Unsubscribe ¶
type Unsubscribe func()
type Update ¶
type Update struct { Time int64 `json:"time"` PostType string `json:"post_type"` MessageType string `json:"message_type"` SubType string `json:"sub_type"` MessageID int64 `json:"message_id"` GroupID int64 `json:"group_id"` DiscussID int64 `json:"discuss_id"` UserID int64 `json:"user_id"` Font int `json:"font"` RawMessage interface{} `json:"message"` // Could be string or array, depends on configuration of coolq-http-api Anonymous interface{} `json:"anonymous"` // This field type is for backward-compatibility and might get changed, see #11 AnonymousFlag string `json:"anonymous_flag"` // This field is deprecated and will get removed, see #11 Event string `json:"event"` NoticeType string `json:"notice_type"` // This field is deprecated and will get removed, see #11 OperatorID int64 `json:"operator_id"` File *File `json:"file"` RequestType string `json:"request_type"` Flag string `json:"flag"` Comment string `json:"comment"` // This field is used for Request Event Text string `json:"-"` // Message with CQCode Message *Message `json:"-"` // Message parsed Sender *User `json:"sender"` }
Update is an update response, from GetUpdates.
func (*Update) ParseRawMessage ¶
func (update *Update) ParseRawMessage()
ParseRawMessage parses message
type UpdateConfig ¶
type UpdateConfig struct { BaseUpdateConfig Offset int Limit int Timeout int }
UpdateConfig contains information about a GetUpdates request.
func NewUpdate ¶
func NewUpdate(offset int) UpdateConfig
NewUpdate gets updates since the last Offset.
offset is the last Update ID to include. You likely want to set this to the last Update ID plus 1.
type UpdatesChannel ¶
type UpdatesChannel <-chan Update
UpdatesChannel is the channel for getting updates.
type User ¶
type User struct { ID int64 `json:"user_id"` NickName string `json:"nickname"` Sex string `json:"sex"` // "male"、"female"、"unknown" Age int `json:"age"` Area string `json:"area"` // Group member Card string `json:"card"` CardChangeable bool `json:"card_changeable"` Title string `json:"title"` TitleExpireTimeUnix int64 `json:"title_expire_time"` Level string `json:"level"` Role string `json:"role"` // "owner"、"admin"、"member" Unfriendly bool `json:"unfriendly"` JoinTimeUnix int64 `json:"join_time"` LastSentTimeUnix int64 `json:"last_sent_time"` AnonymousID int64 `json:"anonymous_id" anonymous:"id"` AnonymousName string `json:"anonymous_name" anonymous:"name"` AnonymousFlag string `json:"anonymous_flag" anonymous:"flag"` }
User is a user on QQ.
type WebSocketRequest ¶
type WebhookConfig ¶
type WebhookConfig struct { BaseUpdateConfig Pattern string // the webhook endpoint }
WebhookConfig contains information about a webhook.