Documentation ¶
Overview ¶
Package chat implements the official classic Battle.net chat API.
Example ¶
package main import ( "fmt" "github.com/nielsAD/gowarcraft3/network" "github.com/nielsAD/gowarcraft3/network/chat" "github.com/nielsAD/gowarcraft3/protocol/capi" ) func main() { bot, err := chat.NewBot(&chat.Config{ Endpoint: capi.Endpoint + ".example", APIKey: "12345678901234567890", }) if err != nil { fmt.Println(err) return } defer bot.Close() // Connect to server if err = bot.Connect(); err != nil { fmt.Println(err) return } // Print incoming chat messages bot.On(&capi.MessageEvent{}, func(ev *network.Event) { var msg = ev.Arg.(*capi.MessageEvent) fmt.Printf("[%d] %s\n", msg.UserID, msg.Message) }) // Run() blocks until the connection is closed bot.Run() }
Output:
Index ¶
- Variables
- type Bot
- func (b *Bot) BanUser(uid int64) error
- func (b *Bot) Channel() string
- func (b *Bot) Connect() error
- func (b *Bot) InitDefaultHandlers()
- func (b *Bot) KickUser(uid int64) error
- func (b *Bot) RPC(command string, arg ...interface{}) (interface{}, error)
- func (b *Bot) Run() error
- func (b *Bot) SendEmote(s string) error
- func (b *Bot) SendMessage(s string) error
- func (b *Bot) SendWhisper(uid int64, s string) error
- func (b *Bot) SetModerator(uid int64) error
- func (b *Bot) UnbanUser(username string) error
- func (b *Bot) User(uid int64) (*User, bool)
- func (b *Bot) Users() map[int64]User
- type Config
- type User
- type UserFlags
- type UserJoined
- type UserLeft
- type UserUpdate
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnexpectedPacket = errors.New("chat: Received unexpected packet")
)
Errors
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct { network.EventEmitter network.CAPIConn // Set once before Connect(), read-only after that Config // contains filtered or unexported fields }
Bot implements a basic chat bot using the official classic Battle.net chat API Public methods/fields are thread-safe unless explicitly stated otherwise
func (*Bot) InitDefaultHandlers ¶
func (b *Bot) InitDefaultHandlers()
InitDefaultHandlers adds the default callbacks for relevant packets
func (*Bot) RPC ¶
RPC executes Remote Procedure Call cmd asynchronously, retries on timeout/rate-limit Needs to called in a goroutine while Run() is running asynchronously to process incoming packets
func (*Bot) Run ¶
Run reads packets and emits an event for each received packet Not safe for concurrent invocation
func (*Bot) SendMessage ¶
SendMessage sends a chat message to the channel
func (*Bot) SendWhisper ¶
SendWhisper sends a chat message to one user in the channel
func (*Bot) SetModerator ¶
SetModerator sets the current chat moderator to a member of the current chat
type User ¶
type User struct { UserID int64 Username string Flags UserFlags ProgramID string Rate string Rank string Wins string Joined time.Time LastSeen time.Time }
User in chat
func (*User) Update ¶ added in v1.3.0
func (u *User) Update(ev *capi.UserUpdateEvent)
Update u with UserUpdateEvent information
type UserFlags ¶ added in v1.3.0
type UserFlags uint32
UserFlags enum
const ( UserFlagAdmin UserFlags = 1 << iota UserFlagModerator UserFlagSpeaker UserFlagMuteGlobal UserFlagMuteWhisper )
User flags
func UnmarshalUserFlags ¶ added in v1.3.0
UnmarshalUserFlags from its JSON representation