Documentation ¶
Overview ¶
Package capi implements the datastructures for the official classic Battle.net chat API.
The Chat API uses JSON with UTF8 encoding as its protocol with secure websockets as the transport.
Index ¶
- Constants
- Variables
- func Serialize(p *Packet) ([]byte, error)
- func Write(w io.Writer, p *Packet) error
- type Authenticate
- type BanUser
- type Connect
- type ConnectEvent
- type Disconnect
- type DisconnectEvent
- type FactoryFunc
- type KickUser
- type MapFactory
- type MessageEvent
- type MessageEventType
- type Packet
- type PayloadFactory
- type Response
- type SendEmote
- type SendMessage
- type SendWhisper
- type SetModerator
- type Status
- type UnbanUser
- type UserAttribute
- type UserLeaveEvent
- type UserUpdateEvent
Constants ¶
const ( CmdRequestSuffix = "Request" CmdResponseSuffix = "Response" CmdAuthenticate = "Botapiauth.Authenticate" CmdConnect = "Botapichat.Connect" CmdDisconnect = "Botapichat.Disconnect" CmdSendMessage = "Botapichat.SendMessage" CmdSendEmote = "Botapichat.SendEmote" CmdSendWhisper = "Botapichat.SendWhisper" CmdKickUser = "Botapichat.KickUser" CmdBanUser = "Botapichat.BanUser" CmdUnbanUser = "Botapichat.UnbanUser" CmdSetModerator = "Botapichat.SendSetModerator" CmdConnectEvent = "Botapichat.ConnectEvent" CmdDisconnectEvent = "Botapichat.DisconnectEvent" CmdMessageEvent = "Botapichat.MessageEvent" CmdUserUpdateEvent = "Botapichat.UserUpdateEvent" CmdUserLeaveEvent = "Botapichat.UserLeaveEvent" )
CAPI command identifiers
const ( UserFlagAdmin = "Admin" UserFlagModerator = "Moderator" UserFlagSpeaker = "Speaker" UserFlagMuteGlobal = "MuteGlobal" UserFlagMuteWhisper = "MuteWhisper" )
User flags
const ( UserAttrProgramID = "ProgramId" UserAttrRate = "Rate" UserAttrRank = "Rank" UserAttrWins = "Wins" )
User attribute keys
const Endpoint = "wss://connect-bot.classic.blizzard.com/v1/rpc/chat"
Endpoint for websocket connection
It is recommended that the certificate is checked to ensure that the common name matches *.classic.blizzard.com
Variables ¶
var ( Success = Status{0, 0} ErrNotConnected = Status{8, 1} ErrBadRequest = Status{8, 2} ErrRequestTimeout = Status{6, 5} ErrRateLimit = Status{6, 8} )
Errors
Area Code Reason 8 1 Not Connected to chat 8 2 Bad request 6 5 Request timed out 6 8 Hit rate limit
var DefaultFactory = MapFactory{ CmdAuthenticate + CmdRequestSuffix: func() interface{} { return &Authenticate{} }, CmdConnect + CmdRequestSuffix: func() interface{} { return &Connect{} }, CmdDisconnect + CmdRequestSuffix: func() interface{} { return &Disconnect{} }, CmdSendMessage + CmdRequestSuffix: func() interface{} { return &SendMessage{} }, CmdSendEmote + CmdRequestSuffix: func() interface{} { return &SendEmote{} }, CmdSendWhisper + CmdRequestSuffix: func() interface{} { return &SendWhisper{} }, CmdKickUser + CmdRequestSuffix: func() interface{} { return &KickUser{} }, CmdBanUser + CmdRequestSuffix: func() interface{} { return &BanUser{} }, CmdUnbanUser + CmdRequestSuffix: func() interface{} { return &UnbanUser{} }, CmdSetModerator + CmdRequestSuffix: func() interface{} { return &SetModerator{} }, CmdConnectEvent + CmdRequestSuffix: func() interface{} { return &ConnectEvent{} }, CmdDisconnectEvent + CmdRequestSuffix: func() interface{} { return &DisconnectEvent{} }, CmdMessageEvent + CmdRequestSuffix: func() interface{} { return &MessageEvent{} }, CmdUserUpdateEvent + CmdRequestSuffix: func() interface{} { return &UserUpdateEvent{} }, CmdUserLeaveEvent + CmdRequestSuffix: func() interface{} { return &UserLeaveEvent{} }, }
DefaultFactory maps command to matching payload type
Functions ¶
Types ¶
type Authenticate ¶
type Authenticate struct {
APIKey string `json:"api_key"`
}
Authenticate payload (Botapiauth.AuthenticateRequest)
When connection is established, the client will need to send an authentication request with the API key
type BanUser ¶
type BanUser struct {
UserID int64 `json:"user_id"`
}
BanUser payload (Botapichat.BanUserRequest)
Bans a user from the channel
type Connect ¶
type Connect struct{}
Connect payload (Botapichat.ConnectRequest)
Connect the bot to the gateway and chat channel
type ConnectEvent ¶
type ConnectEvent struct {
Channel string `json:"channel"`
}
ConnectEvent payload (Botapichat.ConnectEventRequest)
type Disconnect ¶
type Disconnect struct{}
Disconnect payload (Botapichat.DisconnectRequest)
Disconnects the bot from the gateway and chat channel
type DisconnectEvent ¶
type DisconnectEvent struct{}
DisconnectEvent payload (Botapichat.DisconnectEventRequest)
type FactoryFunc ¶ added in v1.5.0
type FactoryFunc func() interface{}
FactoryFunc creates new payload container
type KickUser ¶
type KickUser struct {
UserID int64 `json:"user_id"`
}
KickUser payload (Botapichat.KickUserRequest)
Kicks a user from the channel
type MapFactory ¶ added in v1.5.0
type MapFactory map[string]FactoryFunc
MapFactory implements PayloadFactory using a map
func (MapFactory) NewPayload ¶ added in v1.5.0
func (f MapFactory) NewPayload(cmd string) interface{}
NewPayload implements PayloadFactory interface
type MessageEvent ¶
type MessageEvent struct { UserID int64 `json:"user_id"` Message string `json:"message"` Type MessageEventType `json:"type"` }
MessageEvent payload (Botapichat.MessageEventRequest)
type MessageEventType ¶
type MessageEventType uint32
MessageEventType enum
const ( Unknown MessageEventType = iota MessageWhisper MessageChannel MessageServerInfo MessageServerError MessageEmote )
Message event types
func (MessageEventType) MarshalText ¶
func (m MessageEventType) MarshalText() ([]byte, error)
MarshalText implements TextMarshaler
func (MessageEventType) String ¶
func (m MessageEventType) String() string
func (*MessageEventType) UnmarshalText ¶
func (m *MessageEventType) UnmarshalText(txt []byte) error
UnmarshalText implements TextUnmarshaler
type Packet ¶
type Packet struct { Command string `json:"command"` RequestID int64 `json:"request_id"` Status *Status `json:"status,omitempty"` Payload interface{} `json:"payload"` }
Packet structure
func Deserialize ¶ added in v1.5.0
Deserialize reads exactly one packet from b and returns it in the proper (deserialized) packet type.
func DeserializeWithFactory ¶ added in v1.5.0
func DeserializeWithFactory(b []byte, f PayloadFactory) (*Packet, error)
DeserializeWithFactory reads exactly one packet from b and returns it in the proper (deserialized) packet type.
func Read ¶ added in v1.5.0
Read exactly one packet from r and returns it in the proper (deserialized) packet type.
func ReadWithFactory ¶ added in v1.5.0
func ReadWithFactory(r io.Reader, f PayloadFactory) (*Packet, error)
ReadWithFactory exactly one packet from r and returns it in the proper (deserialized) packet type.
type PayloadFactory ¶ added in v1.5.0
type PayloadFactory interface {
NewPayload(cmd string) interface{}
}
PayloadFactory returns a struct of the appropiate type for a Payload ID
type SendEmote ¶
type SendEmote struct {
Message string `json:"message"`
}
SendEmote payload (Botapichat.SendEmoteRequest)
Sends an emote on behalf of a bot
type SendMessage ¶
type SendMessage struct {
Message string `json:"message"`
}
SendMessage payload (Botapichat.SendMessageRequest)
Sends a chat message to the channel
type SendWhisper ¶
SendWhisper payload (Botapichat.SendWhisperRequest)
Sends a chat message to one user in the channel
type SetModerator ¶
type SetModerator struct {
UserID int64 `json:"user_id"`
}
SetModerator payload (Botapichat.SendSetModeratorRequest)
Sets the current chat moderator to a member of the current chat. Same as a normal user doing /designate followed by /resign.
type Status ¶
Status object
type UnbanUser ¶
type UnbanUser struct {
Username string `json:"toon_name"`
}
UnbanUser payload (Botapichat.UnbanUserRequest)
Un-Bans a user from the channel
type UserAttribute ¶ added in v1.3.0
UserAttribute for UserUpdateEvent
type UserLeaveEvent ¶
type UserLeaveEvent struct {
UserID int64 `json:"user_id"`
}
UserLeaveEvent payload (Botapichat.UserLeaveEventRequest)
type UserUpdateEvent ¶
type UserUpdateEvent struct { UserID int64 `json:"user_id"` Username string `json:"toon_name,omitempty"` Flags []string `json:"flag,omitempty"` Attributes []UserAttribute `json:"attribute,omitempty"` }
UserUpdateEvent payload (Botapichat.UserUpdateEvent)