capi

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: MPL-2.0 Imports: 4 Imported by: 12

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

View Source
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

View Source
const (
	UserFlagAdmin       = "Admin"
	UserFlagModerator   = "Moderator"
	UserFlagSpeaker     = "Speaker"
	UserFlagMuteGlobal  = "MuteGlobal"
	UserFlagMuteWhisper = "MuteWhisper"
)

User flags

View Source
const (
	UserAttrProgramID = "ProgramId"
	UserAttrRate      = "Rate"
	UserAttrRank      = "Rank"
	UserAttrWins      = "Wins"
)

User attribute keys

View Source
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

View Source
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

View Source
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

func Serialize added in v1.5.0

func Serialize(p *Packet) ([]byte, error)

Serialize packet and returns its byte representation.

func Write added in v1.5.0

func Write(w io.Writer, p *Packet) error

Write serializes p and writes it to w.

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

func Deserialize(b []byte) (*Packet, error)

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

func Read(r io.Reader) (*Packet, error)

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 Response

type Response struct{}

Response payload (*.*Response)

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

type SendWhisper struct {
	Message string `json:"message"`
	UserID  int64  `json:"user_id"`
}

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

type Status struct {
	Area int `json:"area"`
	Code int `json:"code"`
}

Status object

func (*Status) Error

func (s *Status) Error() string

Error converts the Status object to an appropriate error message

func (*Status) Timeout

func (s *Status) Timeout() bool

Timeout error (able to retry later)

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

type UserAttribute struct {
	Key   string
	Value string
}

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)

Jump to

Keyboard shortcuts

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