Common code for implementing Twitch bots.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.3 KiB

package bot
import (
type messenger interface {
Message(con *conpool.Con, msg *ircon.Message)
// tmi manages conpool events and JOIN/PART via joinmgr.
type tmi struct {
cpool *conpool.Pool
jmgr *joinmgr.JM
messenger messenger
func newTMI(join15 int, login, oauth string) *tmi {
cpool := conpool.New(login, oauth)
t := &tmi{
jmgr: joinmgr.New(join15, cpool),
cpool: cpool,
return t
func (t *tmi) Run(ctx context.Context) {
func (t *tmi) SendInContext(login, rawmsg string) bool {
return t.cpool.SendInContext("#"+login, rawmsg)
// The following methods implement the conpool interface.
func (t *tmi) Connected(c *conpool.Con) {
func (t *tmi) Disconnected(c *conpool.Con, err error) {
t.jmgr.Disconnected(c, err)
// Message handles messages received on a specific connection, which may happen
// concurrently across multiple connections.
func (t *tmi) Message(con *conpool.Con, msg *ircon.Message) {
switch msg.Command {
case "PING":
case "JOIN":
t.jmgr.Joined(con, msg)
case "PART":
t.jmgr.Parted(con, msg)
t.messenger.Message(con, msg)