Documentation ¶
Overview ¶
Package birc implements IRC communication for the bot.
Index ¶
- Constants
- Variables
- type Config
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) Incoming() <-chan *irc.Message
- func (c *Connection) IsJoined(channel string) bool
- func (c *Connection) Join(ctx context.Context, channels ...string) error
- func (c *Connection) Joined() []string
- func (c *Connection) NumJoined() int
- func (c *Connection) Part(ctx context.Context, channels ...string) error
- func (c *Connection) Run(ctx context.Context) error
- func (c *Connection) SendMessage(ctx context.Context, target, message string) error
- func (c *Connection) WaitUntilReady(ctx context.Context) error
- type Dialer
- type Pool
- func (p *Pool) Incoming() <-chan *irc.Message
- func (p *Pool) IsJoined(channel string) bool
- func (p *Pool) Join(ctx context.Context, channels ...string) error
- func (p *Pool) Joined() []string
- func (p *Pool) NumConns() int
- func (p *Pool) NumJoined() int
- func (p *Pool) Part(ctx context.Context, channels ...string) error
- func (p *Pool) Prune()
- func (p *Pool) Run(ctx context.Context) error
- func (p *Pool) SendMessage(ctx context.Context, target, message string) error
- func (p *Pool) Stop()
- func (p *Pool) SyncJoined(ctx context.Context, channels ...string) error
- func (p *Pool) WaitUntilReady(ctx context.Context) error
- type PoolConfig
- type UserConfig
Constants ¶
const ( TwitchCapCommands = "twitch.tv/commands" TwitchCapTags = "twitch.tv/tags" TwitchCapMembership = "twitch.tv/membership" )
Twitch capabilities.
const ( TwitchAddr = "irc.chat.twitch.tv:6667" TwitchTLSAddr = "irc.chat.twitch.tv:6697" )
Twitch IRC addresses.
const ( // DefaultMaxChannelsPerSubConn is the default maximum number of channels a // single subconn is allowed to be joined. DefaultMaxChannelsPerSubConn = 10 // DefaultJoinRate is the default number of channels that can be joined by // pool per second. DefaultJoinRate = 1.0 // DefaultPruneInterval is the default interval between subconn prunes. DefaultPruneInterval = time.Minute )
Variables ¶
var ( // ErrConnectionClosed is returned when a Connection is closed, so a message // cannot be sent. ErrConnectionClosed = errors.New("birc: connection closed") // ErrReconnect is returned when the connection closes as the server has // requested a reconnect. ErrReconnect = errors.New("birc: server asked for reconnect") // ErrReadOnly is returned when a read only connection is used to send a message. ErrReadOnly = errors.New("birc: connection is marked read only") // ErrFailedPing is returned when a server fails to respond to a PING. ErrFailedPing = errors.New("birc: server did not respond to PING") )
var DefaultDialer = Dialer{ Addr: TwitchTLSAddr, }
DefaultDialer is the default dialer used for conns, connecting to the Twitch IRC server securely.
var ErrPoolStopped = errors.New("birc: pool stopped")
ErrPoolStopped is returned when the pool is stopped.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // UserConfig configures the user that connects to the IRC server. UserConfig UserConfig // Dialer specifies the dialer to use to connect to the IRC server. If nil, // DefaultDialer will be used. Dialer *Dialer // InitialChannels specifies the list of channels the connection should // initially join once connected. // // These channels will all be joined via the same JOIN message, so if the // server has a JOIN rate limitation, it may be preferred to perform the // joins via the Join method manually. InitialChannels []string // Caps is a list of capabilities to declare to the server. Caps []string // RecvBuffer sets the buffer size for the received message buffer. A // buffer size of zero causes message receiving to be synchronous. // // This includes automatically handled PING/RECONNECT messages, so a slow // consumer may negatively impact the connection. RecvBuffer int // PingInterval is how often the connection will send a PING to the server. // If zero, PINGs are disabled. PingInterval time.Duration // PingDeadline is how long the connection will wait for a response to a // PING before disconnecting. PingDeadline time.Duration }
Config configures a Connection. Addr, Nick, and Pass must be specified.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection manages a single connection to an IRC server.
func NewConnection ¶
func NewConnection(config Config) *Connection
NewConnection creates a new Connection.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close closes the IRC connection. This function is safe to call more than once and safe for concurrent use. All calls following the first will return the same error.
func (*Connection) Incoming ¶
func (c *Connection) Incoming() <-chan *irc.Message
Incoming returns a channel which is sent incoming messages. When the connection is closed this channel will also be closed. Note that the returned channel is shared among all callers; only one receiver will be able to receive any given message.
func (*Connection) IsJoined ¶
func (c *Connection) IsJoined(channel string) bool
IsJoined returns true if the specified channel has been joined.
func (*Connection) Join ¶
func (c *Connection) Join(ctx context.Context, channels ...string) error
Join instructs the connection to join the specified channels.
Note that even if an error occurs, the connection's state will be updated such that it appears that the channels were parted.
func (*Connection) Joined ¶
func (c *Connection) Joined() []string
Joined returns a list of the joined channels. It is safe for concurrent use, and is available even after the connection has closed.
func (*Connection) NumJoined ¶
func (c *Connection) NumJoined() int
NumJoined returns the number of joined channels.
func (*Connection) Part ¶
func (c *Connection) Part(ctx context.Context, channels ...string) error
Part instructs the connection to part with the specified channels.
Note that even if an error occurs, the connection's state will be updated such that it appears that the channels were parted.
func (*Connection) Run ¶
func (c *Connection) Run(ctx context.Context) error
Run starts the connection and returns when the connection is closed.
Once this function has returned, the connection cannot be reused.
func (*Connection) SendMessage ¶
func (c *Connection) SendMessage(ctx context.Context, target, message string) error
SendMessage sends a PRIVMSG to the specified target.
func (*Connection) WaitUntilReady ¶
func (c *Connection) WaitUntilReady(ctx context.Context) error
WaitUntilReady waits until the connection is ready, or the context is canceled.
type Dialer ¶
type Dialer struct { // Addr is the IRC address to connect to, in hostname:port form. Addr string // Insecure will disable TLS if set to true. Insecure bool // TLSConfig is a TLS config to be used when connecting to the server. // If nil, the default will be used. If Insecure is true, this config // will not be used. TLSConfig *tls.Config // Dialer is the dialer used to connect to the IRC server. If unset, the // default will be used. Dialer *net.Dialer // contains filtered or unexported fields }
Dialer dials underlying TCP connections to IRC servers. The default value is valid for use.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a collection of managed IRC connections.
func (*Pool) Incoming ¶
Incoming returns a channel which is sent incoming messages. When the pool is stopped, this channel will be closed. Note that the returned channel is shared between all of the pool's subconnections and all other callers of Incoming, so it is imperative that this channel not be blocked needlessly.
func (*Pool) Run ¶
Run runs the pool. It blocks until the pool is stopped, or the context cancelled. It always returns a non-nil error.
func (*Pool) SendMessage ¶
SendMessage sends a PRIVMSG through the pool to a subconn.
Note: this function does no rate limiting. Apply any rate limits before calling this function.
func (*Pool) SyncJoined ¶
SyncJoined synchronizes the pool's joined channels to match the provided list.
type PoolConfig ¶
type PoolConfig struct { // Config is the main IRC connection configuration. Config // MaxChannelsPerSubConn controls the maximum number of channels joined // per subconn. MaxChannelsPerSubConn int // JoinRate controls the number of channels the pool can join per second. // Set negative to disable. JoinRate float64 // PruneInterval controls how often the pool prunes connections that are // not joined to any channels. Set negative to disable. PruneInterval time.Duration // PriorityChannels is a list of "priority channels" which will be // prioritized ahead of other channels during a join sync. PriorityChannels []string }
PoolConfig configures a connection pool.
type UserConfig ¶
type UserConfig struct { // Nick is the nick to give when authenticating to the server. // // If Nick is empty, a random anonymous Twitch username will be used, and // the connection marked readonly. Nick string // Pass is the pass to give when authenticating to the server. If empty, it // will not be sent. Pass string // ReadOnly sets the connection to be read only. No messages may be sent // from this connection, other than control messages (like JOIN, PONG, etc). ReadOnly bool }
UserConfig configures the user information for an IRC connection.
Directories ¶
Path | Synopsis |
---|---|
Package breq implements requests passed around internally inside of birc.
|
Package breq implements requests passed around internally inside of birc. |
Package fakeirc implements a fake IRC server for testing.
|
Package fakeirc implements a fake IRC server for testing. |