pkg

package
v0.0.0-...-486c946 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReportActionUnknown = 0
	ReportActionBan     = 1
	ReportActionTimeout = 2
	ReportActionDismiss = 3
	ReportActionUndo    = 4
)
View Source
const VerboseBenchmark = false
View Source
const VerboseMessages = false

Variables

This section is empty.

Functions

func GetReportActionByName

func GetReportActionByName(actionName string) uint8

func GetReportActionName

func GetReportActionName(action uint8) string

Types

type Account

type Account interface {
	// full id of user (i.e. 11148817)
	ID() string

	// full lowercase name (i.e. pajlada)
	Name() string
}

type Actions

type Actions interface {
	Timeout(user User, duration time.Duration) MuteAction

	Ban(user User) MuteAction

	Unban(user User) UnmuteAction

	Say(content string) MessageAction

	Delete(message string) DeleteAction

	Mention(user User, content string) MessageAction

	Whisper(user User, content string) WhisperAction

	Mutes() []MuteAction
	Unmutes() []UnmuteAction
	Deletes() []DeleteAction
	Messages() []MessageAction
	Whispers() []WhisperAction

	StopPropagation() bool
}

Actions is a list of actions that wants to be run An implementation of this can decide to filter out all mutes except for the "most grave one"

type Application

type Application interface {
	UserStore() UserStore
	ChannelStore() ChannelStore
	UserContext() UserContext
	StreamStore() StreamStore
	SQL() *sql.DB
	PubSub() PubSub
	TwitchBots() BotStore
	QuitChannel() chan string
	TwitchAuths() TwitchAuths
	MIMO() MIMO
}

Application is an instance of pajbot2 It's responsible for initializing all bot accounts (`Bot` class)

type Banphrase

type Banphrase interface {
	Triggers(text string) bool
	IsCaseSensitive() bool

	// IsAdvanced decides whether or not the banphrase should be run on all variations or only the first one
	IsAdvanced() bool

	GetName() string
	GetID() int
	GetDuration() time.Duration
}

type BaseEvent

type BaseEvent struct {
	UserStore UserStore
}

type BaseModule

type BaseModule interface {
	LoadSettings([]byte) error
	Parameters() map[string]ModuleParameter
	ID() string
	Type() ModuleType
	Priority() int
}

A BaseModule is local to a bots channel i.e. bot "pajbot" joins channels "pajlada" and "forsen" Module list looks like this: "pajbot":

  • "pajlada":
  • "MyTestModule"
  • "MyTestModule2"
  • "forsen":
  • "MyTestModule"

type BotChannel

type BotChannel interface {
	// Implement Channel interface
	GetName() string
	GetID() string

	MessageSender

	DatabaseID() int64
	Channel() Channel
	ChannelID() string
	ChannelName() string

	EnableModule(string) error
	DisableModule(string) error
	GetModule(string) (Module, error)

	// Implement ChannelWithStream interface
	Stream() Stream

	Events() *eventemitter.EventEmitter

	HandleMessage(user User, message Message) error
	HandleEventSubNotification(notification TwitchEventSubNotification) error
	OnModules(cb func(module Module) Actions, stop bool) []Actions

	SetSubscribers(state bool) error
	SetUniqueChat(state bool) error
	SetEmoteOnly(state bool) error
	SetSlowMode(state bool, durationS int) error
	SetFollowerMode(state bool, durationM int) error
	SetNonModChatDelay(state bool, durationS int) error

	Bot() Sender
}

type BotStore

type BotStore interface {
	Add(Sender)

	GetBotFromName(string) Sender
	GetBotFromID(string) Sender
	GetBotFromChannel(string) Sender

	Iterate() BotStoreIterator
}

type BotStoreIterator

type BotStoreIterator interface {
	Next() bool
	Value() Sender
}

type Channel

type Channel interface {
	GetName() string
	GetID() string
}

Channel is the most barebones way of accessing a Twitch channel For a Channel to 'live' we must be able to access its Name (Twitch User Login) and ID (Twitch User ID)

type ChannelStore

type ChannelStore interface {
	TwitchChannel(channelID string) Channel
	RegisterTwitchChannel(channel Channel)
}

type ChannelWithStream

type ChannelWithStream interface {
	Channel

	Stream() Stream
}

type CommandInfo

type CommandInfo struct {
	Name        string
	Description string

	Maker func() CustomCommand2 `json:"-"`
}

type CommandMatcher

type CommandMatcher interface {
	Register(aliases []string, command interface{}) interface{}
	Deregister(command interface{})
	DeregisterAliases(aliases []string)
	Match(text string) (interface{}, []string)
}

type CommandsManager

type CommandsManager interface {
	CommandMatcher
	OnMessage(event MessageEvent) Actions

	FindByCommandID(id int64) interface{}

	Register2(id int64, aliases []string, command interface{})
}

type CustomCommand2

type CustomCommand2 interface {
	SimpleCommand

	HasCooldown(User) bool
	AddCooldown(User)
}

type DeleteAction

type DeleteAction interface {
	Message() string
}

DeleteAction defines an action that will delete a message

type Emote

type Emote interface {
	// i.e. "8vn23893nvcakuj23" for a bttv emote, or "85489481" for a twitch emote
	GetID() string

	// i.e. "NaM" or "forsenE"
	GetName() string

	// "twitch" or "bttv"
	GetType() string

	GetCount() int
}

type EmoteReader

type EmoteReader interface {
	Next() bool
	Get() Emote
}

type EventSubNotificationEvent

type EventSubNotificationEvent struct {
	BaseEvent

	Notification TwitchEventSubNotification
}

type MIMO

type MIMO interface {
	Subscriber(channelNames ...string) chan interface{}
	Publisher(channelName string) chan interface{}
}

MIMO is a Many In Many Out interface Implementation for this exists in pkg/mimo/

type Message

type Message interface {
	GetText() string
	SetText(string)

	GetTwitchReader() EmoteReader

	GetBTTVReader() EmoteReader
	AddBTTVEmote(Emote)
}

type MessageAction

type MessageAction interface {
	// TODO: Add reply message action
	SetAction(v bool)
	Evaluate() string
}

MessageAction defines a message that will be publicly displayed

type MessageEvent

type MessageEvent struct {
	BaseEvent

	User    User
	Message Message
	Channel ChannelWithStream
}

type MessageSender

type MessageSender interface {
	Say(string)
	Mention(User, string)

	// Moderation
	Timeout(User, int, string)
	Ban(User, string)
}

type Module

type Module interface {
	BaseModule

	// Called when the module is disabled. The module can do any cleanup it needs to do here
	Disable() error

	// Returns the bot channel that the module has saved
	BotChannel() BotChannel

	OnWhisper(event MessageEvent) Actions
	OnMessage(event MessageEvent) Actions
	OnEventSubNotification(event EventSubNotificationEvent) Actions
}

type ModuleFactory

type ModuleFactory func() ModuleSpec

type ModuleParameter

type ModuleParameter interface {
	Description() string
	DefaultValue() interface{}
	Parse(string) error
	SetInterface(interface{})
	Get() interface{}
	Link(interface{})
	HasValue() bool
	HasBeenSet() bool
}

type ModuleParameterSpec

type ModuleParameterSpec func() ModuleParameter

type ModuleSpec

type ModuleSpec interface {
	ID() string
	Name() string
	Type() ModuleType
	EnabledByDefault() bool
	Parameters() map[string]ModuleParameterSpec

	Create(bot BotChannel) Module

	Priority() int
}

type ModuleType

type ModuleType uint
const (
	ModuleTypeUnsorted ModuleType = iota
	ModuleTypeFilter
)

The order of these values matter. Higher value means higher priority in the "OnModules" function

type MuteAction

type MuteAction interface {
	User() User
	SetReason(reason string)
	Reason() string

	Type() MuteType

	Duration() time.Duration
}

MuteAction defines an action that will mute/timeout/ban or otherwise stop a user from participating in chat, either temporarily or permanently

type MuteType

type MuteType uint
const (
	MuteTypeTemporary MuteType = iota
	MuteTypePermanent
)

type Permission

type Permission uint64
const (
	PermissionNone       Permission = 0
	PermissionReport     Permission = 1 << 0
	PermissionRaffle     Permission = 1 << 1
	PermissionAdmin      Permission = 1 << 2
	PermissionModeration Permission = 1 << 3
	PermissionReportAPI  Permission = 1 << 4

	PermissionImmuneToMessageLimits = 1 << 5
)

func GetPermissionBit

func GetPermissionBit(s string) Permission

GetPermissionBit converts a string (i.e. "admin") to the binary value it represents. 0b100 in this example

func GetPermissionBits

func GetPermissionBits(permissionNames []string) (permissions Permission)

GetPermissionBits converts a list of strings (i.e. ["admin", "raffle"]) to the binary value they represent. 0b110 in this example

type PubSub

type PubSub interface {
	Subscribe(source PubSubSource, topic string, parameters json.RawMessage)
	Publish(source PubSubSource, topic string, data interface{})

	HandleSubscribe(connection PubSubSubscriptionHandler, topic string)
	HandleJSON(source PubSubSource, bytes []byte) error
}

type PubSubBan

type PubSubBan struct {
	Channel string
	Target  string
	Reason  string
}

type PubSubBanEvent

type PubSubBanEvent struct {
	Channel PubSubUser
	Target  PubSubUser
	Source  PubSubUser
	Reason  string
}

type PubSubConnection

type PubSubConnection interface {
	MessageReceived(source PubSubSource, topic string, bytes []byte) error
}

PubSubConnection is an interface where a JSON message can be written to

type PubSubSource

type PubSubSource interface {
	IsApplication() bool
	Connection() PubSubConnection
	AuthenticatedUser() User
}

PubSubSource is an interface that is responsible for a message being written into pubsub This will be responsible for checking authorization

type PubSubSubscriptionHandler

type PubSubSubscriptionHandler interface {
	ConnectionSubscribed(source PubSubSource, topic string, parameters json.RawMessage) (bool, error)
}

type PubSubTimeout

type PubSubTimeout struct {
	Channel  string
	Target   string
	Reason   string
	Duration uint32
}

type PubSubTimeoutEvent

type PubSubTimeoutEvent struct {
	Channel  PubSubUser
	Target   PubSubUser
	Source   PubSubUser
	Duration int
	Reason   string
}

type PubSubUntimeout

type PubSubUntimeout struct {
	Channel string
	Target  string
}

type PubSubUser

type PubSubUser struct {
	ID   string
	Name string
}

type Sender

type Sender interface {
	TwitchAccount() TwitchAccount
	GetTokenSource() oauth2.TokenSource

	Connected() bool

	Say(Channel, string)
	Mention(Channel, User, string)
	Whisper(User, string)
	Whisperf(User, string, ...interface{})

	// Timeout times the user out a single time immediately
	Timeout(Channel, User, int, string)

	Ban(Channel, User, string)

	GetPoints(Channel, string) uint64

	// give or remove points from user in channel
	BulkEdit(string, []string, int32)

	AddPoints(Channel, string, uint64) (bool, uint64)
	RemovePoints(Channel, string, uint64) (bool, uint64)
	ForceRemovePoints(Channel, string, uint64) uint64

	PointRank(Channel, string) uint64

	// ChannelIDs returns a slice of the channels this bot is connected to
	ChannelIDs() []string

	InChannel(string) bool
	InChannelName(string) bool
	GetUserStore() UserStore
	GetUserContext() UserContext

	GetBotChannel(channelName string) BotChannel
	GetBotChannelByID(channelID string) BotChannel

	MakeUser(string) User
	MakeChannel(string) Channel

	// Permanently join channel with the given channel ID
	JoinChannel(channelID string) error

	// Permanently leave channel with the given channel ID
	LeaveChannel(channelID string) error

	// Connect to the OnNewChannelJoined callback
	OnNewChannelJoined(cb func(channel Channel))

	Quit(message string)

	Application() Application

	// DEV
	Disconnect()
}

type SimpleCommand

type SimpleCommand interface {
	Trigger([]string, MessageEvent) Actions
}

type Stream

type Stream interface {
	Status() StreamStatus

	// Update forwards the given helix data to its internal status
	Update(*helix.Stream)
}

type StreamStatus

type StreamStatus interface {
	Live() bool
	StartedAt() time.Time
}

type StreamStore

type StreamStore interface {
	// GetStream ensures that the given Account is being followed & polled for stream status updates
	// If the account is already being followed, the Stream that was already stored is returned.
	GetStream(Account) Stream
}

type TwitchAccount

type TwitchAccount interface {
	ID() string
	Name() string
}

type TwitchAuths

type TwitchAuths interface {
	Bot() *oauth2.Config
	Streamer() *oauth2.Config
	User() *oauth2.Config
}

type TwitchEventSubNotification

type TwitchEventSubNotification struct {
	Subscription helix.EventSubSubscription `json:"subscription"`
	Challenge    string                     `json:"challenge"`
	Event        json.RawMessage            `json:"event"`
}

type UnmuteAction

type UnmuteAction interface {
	User() User

	Type() MuteType
}

UnmuteAction defines an action that will unmute/untimeout or unban a user

type User

type User interface {
	// Has channel or global permission
	HasPermission(Channel, Permission) bool

	// Has global permission
	HasGlobalPermission(Permission) bool

	// Has channel permission
	HasChannelPermission(Channel, Permission) bool

	GetName() string
	GetDisplayName() string
	GetID() string
	IsModerator() bool
	IsBroadcaster() bool
	IsVIP() bool
	IsSubscriber() bool
	GetBadges() map[string]int

	// Set the ID of this user
	// Will return an error if the ID of this user was already set
	SetID(string) error

	// Set the Name of this user
	// Will return an error if the Name of this user was already set
	SetName(string) error
}

type UserContext

type UserContext interface {
	GetContext(channelID, userID string) []string

	// The message must be preformatted. i.e. [2018-09-13 502:501:201] username: message
	AddContext(channelID, userID, message string)
}

type UserStore

type UserStore interface {
	// Input: Lowercased twitch usernames
	// Returns: user IDs as strings in no specific order, and a bool indicating whether the user needs to exhaust the list first and wait
	GetIDs([]string) map[string]string

	GetID(string) string

	GetUserByLogin(string) (User, error)
	GetUserByID(string) (User, error)

	GetName(string) string

	// Input: list of twitch IDs
	// Returns: map of twitch IDs pointing at twitch usernames
	GetNames([]string) map[string]string

	Hydrate([]User) error
}

type UserStoreRequest

type UserStoreRequest struct {
	// contains filtered or unexported fields
}

func NewUserStoreRequest

func NewUserStoreRequest() *UserStoreRequest

func (*UserStoreRequest) AddID

func (r *UserStoreRequest) AddID(id string)

func (*UserStoreRequest) AddName

func (r *UserStoreRequest) AddName(name string)

func (*UserStoreRequest) Execute

func (r *UserStoreRequest) Execute(userStore UserStore) (names map[string]string, ids map[string]string)

Execute returns two values: First value: map where key is a user ID pointing at a user name Second value: map where key is a user name pointing at a user ID

type WhisperAction

type WhisperAction interface {
	User() User
	Content() string
}

WhisperAction defines a message that will be privately sent to a user

Jump to

Keyboard shortcuts

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