bot

package
v0.0.0-...-ce734fa Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FlagMap = map[string]Flag{
	"channel-mode": FlagChannelMode,
}

Functions

This section is empty.

Types

type Bot

type Bot struct {
	TwitchIRC *twitch.Client
	Helix     *helix.Client
	Mongo     *db.Connection
	Logins    map[string]string
	Channels  map[string]*Channel
	Commands  map[string]*Command
	Users     map[string]*User
	Self      *Self
	StartTime time.Time
}

type BotType

type BotType int

BotType represents which kind of global rate-limit the bot has

const (
	BotTypeNormal BotType = iota
	BotTypeKnown
	BotTypeVerified
)

type Channel

type Channel struct {
	ID       string           `bson:"id"`
	Login    string           `bson:"login"`
	Mode     ChannelMode      `bson:"mode"`
	EventSub *ChannelEventSub `bson:"eventsub"`

	LastMsg      string
	QueueChannel chan *QueuedMessage
	Cooldowns    map[string]time.Time
}

func (*Channel) ChangeMode

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

func (*Channel) Send

func (channel *Channel) Send(message string)

func (*Channel) VerboseName

func (channel *Channel) VerboseName() string

func (*Channel) Write

func (channel *Channel) Write(bot *Bot)

type ChannelEventSub

type ChannelEventSub struct {
	Enabled       bool                           `bson:"enabled"`
	Subscriptions []*ChannelEventSubSubscription `bson:"subscriptions"`
}

ChannelEventSub represents Channel's EventSub settings along with all Subscriptions active in the Channel

type ChannelEventSubSubscription

type ChannelEventSubSubscription struct {
	Type    string `bson:"type"`
	Version string `bson:"version"`
}

ChannelEventSubSubscription represents an EventSub subscription type as stored in database

type ChannelMode

type ChannelMode int

ChannelMode indicates the bot's state in a Channel

const (
	ChannelModeNormal ChannelMode = iota
	ChannelModeInactive
	ChannelModeVIP
	ChannelModeModerator

	ChannelModeBoundary
)

func ParseChannelMode

func ParseChannelMode(num int) (err error, mode ChannelMode)

func (ChannelMode) MessageRatelimit

func (mode ChannelMode) MessageRatelimit() time.Duration

MessageRatelimit returns underlying value of messageRatelimit that corresponds to mode

func (ChannelMode) String

func (mode ChannelMode) String() string

String human-readable name of the mode. Meant to be used only in logs and output visible to end-user

type Command

type Command struct {
	Name        string
	Description string
	Usage       string
	Permission  Permission
	Cooldown    time.Duration
	Run         func(msg twitch.PrivateMessage, args []string) (err CommandError)
}

type CommandError

type CommandError int

CommandError is a type for

const (
	// CommandErrorNoError command returned successfully
	CommandErrorNoError CommandError = iota

	// CommandErrorInvalidArguments user used invalid syntax
	// Could be caused by providing invalid arguments or too little of them
	CommandErrorInvalidArguments

	// CommandErrorInternal something completely unexpected happened, e.g. parsing new http.Req
	CommandErrorInternal

	// CommandErrorHTTPRequest executing an HTTP request failed, or any other HTTP request-related action
	CommandErrorHTTPRequest

	// CommandErrorReply something related to user's input failed
	// Response should be sent to the user in the Command.Run right before the return
	CommandErrorReply

	// CommandErrorMongo emits when a MongoDB operation failed / couldn't be performed
	CommandErrorMongo
)

func (CommandError) String

func (err CommandError) String() (str string)

type Flag

type Flag int

Flag flags that can be set with the set command and update corresponding properties in the database

const (
	FlagChannelMode Flag = iota
)

type Permission

type Permission int32
const (
	PermissionNone  Permission = 0
	PermissionAdmin Permission = 1 << (iota - 1)
	PermissionSkipCooldown
)

type QueuedMessage

type QueuedMessage struct {
	Message string
}

type Self

type Self struct {
	Login   string
	OAuth   string
	BotType BotType
}

Self contains properties related to bot's user account

type User

type User struct {
	ID         string     `bson:"id"`
	Permission Permission `bson:"permission"`
}

Jump to

Keyboard shortcuts

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