capi

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 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

Functions

func SerializePacket

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

SerializePacket 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 KickUser

type KickUser struct {
	UserID int64 `json:"user_id"`
}

KickUser payload (Botapichat.KickUserRequest)

Kicks a user from the channel

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 DeserializePacket

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

DeserializePacket reads exactly one packet from r and returns it in the proper (deserialized) packet type.

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