bot

package
v0.0.0-...-788a77d Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SubEventDescriptions = []string{
	"game changes",
	"title changes",
	"streamer goes live",
	"streamer goes offline",
}

SubEventDescriptions slice with all currently supported events, indexed by the values of SubEventType allowing to cast the index of a string in the slice to a corresponding SubEventType value

Functions

This section is empty.

Types

type Bot

type Bot struct {
	TwitchIRC *twitch.Client
	Mongo     *mongo.Connection
	Helix     *helix.Client
	EventSub  *eventsub.EventSub

	Logins   map[string]string
	Channels map[string]*Channel
	Commands *CommandController

	Self      *Self
	StartTime time.Time
}

type Channel

type Channel struct {
	ID    string `bson:"id"`
	Login string `bson:"login"`

	DisabledCommands   []string                `bson:"disabled_commands"`
	Events             map[SubEventType]string `bson:"events"`
	PajbotAPI          *PajbotAPI              `bson:"pajbot_api"`
	MessageLengthLimit int                     `bson:"message_length_limit"`
	WhisperCommands    bool                    `bson:"whisper_commands"`
	EventsOnlyOffline  bool                    `bson:"events_only_offline"`
	Mode               ChannelMode             `bson:"mode"`

	CurrentTitle string             `bson:"-"`
	CurrentGame  string             `bson:"-"`
	IsLive       bool               `bson:"-"`
	LastMsg      string             `bson:"-"`
	QueueChannel chan *QueueMessage `bson:"-"`
}

func (*Channel) ChangeMode

func (channel *Channel) ChangeMode(mongoConn *mongo.Connection, newMode ChannelMode) (err error)

func (*Channel) MessageLengthMax

func (channel *Channel) MessageLengthMax() int

func (*Channel) Send

func (channel *Channel) Send(message string)

Sends a message to the channel while taking care of ratelimits

func (*Channel) Sendf

func (channel *Channel) Sendf(format string, a ...interface{})

Sendf formats according to a format specifier and runs channel.Send with the resulting string

func (*Channel) StartMessageQueue

func (channel *Channel) StartMessageQueue(twitchIRC *twitch.Client)

func (*Channel) String

func (channel *Channel) String() string

type ChannelMode

type ChannelMode int

ChannelMode indicates the bot's state in a Channel

const (
	// ChannelModeNormal default ChannelMode with regular ratelimits
	ChannelModeNormal ChannelMode = iota
	// ChannelModeInactive bot has been disabled in that chat
	ChannelModeInactive
	// ChannelModeModerator bot has elevated ratelimits with moderation permissions
	ChannelModeModerator

	// ChannelModeEnumBoundary marks the end of enumeration
	ChannelModeEnumBoundary
)

func (ChannelMode) MessageRatelimit

func (mode ChannelMode) MessageRatelimit() time.Duration

MessageRatelimit the minimum time.Duration that must pass between sending messages in the Channel

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Usage       string
	Run         func(msg twitch.PrivateMessage, args []string)

	CooldownChannel time.Duration
	CooldownUser    time.Duration

	// TODO: Perhaps cooldown logic should be stored in Bot / redis (?)
	LastExecutionChannel map[string]time.Time
	LastExecutionUser    map[string]time.Time
}

func (*Command) String

func (c *Command) String() string

type CommandController

type CommandController struct {
	Commands map[string]*Command

	Prefix string
	// contains filtered or unexported fields
}

func NewCommandController

func NewCommandController(prefix string) *CommandController

func (*CommandController) GetCommand

func (c *CommandController) GetCommand(alias string) (*Command, bool)

func (*CommandController) RegisterCommand

func (c *CommandController) RegisterCommand(cmd *Command)

type PajbotAPI

type PajbotAPI struct {
	Mode   PajbotAPIMode `bson:"mode"`
	Domain string        `bson:"domain"`
}

type PajbotAPIMode

type PajbotAPIMode int

PajbotAPIMode indicates bot's behavior regarding banphrase checks in channels that have pajbot API configured

const (
	// PajbotAPIModeDisabled even if the Domain link is set, API will be totally ignored
	PajbotAPIModeDisabled PajbotAPIMode = iota
	// PajbotAPIModeEnabled will attempt to sanitize potentially harmful message content
	PajbotAPIModeEnabled
)

type QueueMessage

type QueueMessage struct {
	Message string
}

type Self

type Self struct {
	Login string
	OAuth string
}

Self contains properties related to bot's user account

type SubEventMOTD

type SubEventMOTD struct {
	ChannelID string `bson:"channel_id"`
	Message   string `bson:"message"`
}

SubEventMOTD if present for a channel with the corresponding ChannelID, should be posted right after announcing channel going live It could be useful to remind streamer to tweet or announce going live on Discord

type SubEventMessage

type SubEventMessage struct {
	Bot       *Bot
	ChannelID string
	Type      SubEventType
}

type SubEventSubscription

type SubEventSubscription struct {
	UserLogin string       `bson:"user_login"`
	UserID    string       `bson:"user_id"`
	Event     SubEventType `bson:"event"`
	Value     string       `bson:"value"`
}

type SubEventType

type SubEventType int

SubEventType defines event to which users can subscribe

const (
	// SubEventTypeGame game (category) has been updated
	// Received in EventSub's "channel.update"
	SubEventTypeGame SubEventType = iota
	// SubEventTypeTitle title has been updated
	// Received in EventSub's "channel.update"
	SubEventTypeTitle
	// SubEventTypeLive channel has gone live
	// Received in EventSub's "stream.online"
	SubEventTypeLive
	// EventLive channel has gone offline
	// Received in EventSub's "stream.offline"
	SubEventTypeOffline
	// SubEventTypePartnered broadcaster has become partnered
	// This is deprecated and is kept in case legacy subscriptions with this value are found
	SubEventTypePartnered

	// SubEventTypeInvalid represents an invalid event type that was passed to ParseChannelEvent
	SubEventTypeInvalid
)

func ParseSubEventType

func ParseSubEventType(value string) (valid bool, event SubEventType)

ParseSubEventType attempts to convert value to a ChannelEvent event

func (SubEventType) String

func (e SubEventType) String() string

Jump to

Keyboard shortcuts

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