ircbot

package
v0.0.0-...-fd00b2c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelTopic

func ChannelTopic(e Event) error

func CooldownMessageFromError

func CooldownMessageFromError(err error) string

CooldownMessageFromError returns a friendlier, coloured error message for cooldown related errors

func Execute

func Execute(ctx context.Context, cfg config.Config) error

Execute executes the ircbot with the context and configuration given. it returns with any error that occurs; Execution can be interrupted by canceling the context given.

func FaveList

func FaveList(e Event) error

func FaveTrack

func FaveTrack(e Event) error

func FindNamedSubmatches

func FindNamedSubmatches(re *regexp.Regexp, s string) map[string]string

FindNamedSubmatches runs re.FindStringSubmatch(s) and only returns the groups that are named in the regexp

func Fmt

func Fmt(message string, args ...interface{}) string

Fmt passes the message to girc.Fmt and then calls fmt.Sprintf with arguments given

func FormatDuration

func FormatDuration(t time.Duration, truncate time.Duration) string

FormatDuration formats a Duration similar to Duration.String except it adds a possible month and day value to the front if available. Such that instead of the form "72h3m0.5s" this returns "3d3m0.5s".

The truncate argument indicates the smallest unit returned in the string

func FormatLongDuration

func FormatLongDuration(t time.Duration) string

FormatLongDuration formats a Duration in a long form with each unit spelled out completely and spaced properly. For example a duration of 1d5h22s would be formatted as `1 day, 5 hours, 22 seconds`

func FormatPlaybackDuration

func FormatPlaybackDuration(t time.Duration) string

FormatPlaybackDuration formats a Duration in the form mm:ss where mm are minutes and ss are seconds.

func FormatPlaybackDurationHours

func FormatPlaybackDurationHours(t time.Duration) string

FormatPlaybackDurationHours is similar to FormatPlaybackDuration but also includes the hour part, making it "hh:mm:ss"

func HasAccess

func HasAccess(c *girc.Client, e girc.Event) bool

HasAccess checks if the user that send the PRIVMSG to us has access +h or higher in the channel it came from; HasAccess panics if the event is not PRIVMSG

func HasDeveloperAccess

func HasDeveloperAccess(e Event) (bool, error)

func HasStreamAccess

func HasStreamAccess(c *girc.Client, e girc.Event) bool

HasStreamAccess is similar to HasAccess but also includes special casing for streamers that don't have channel access, but do have the authorization to access the stream

func IsAuthed

func IsAuthed(e Event) bool

IsAuthed checks if the source of the event is authenticated with nickserv

func KillStreamer

func KillStreamer(e Event) error

func LastPlayed

func LastPlayed(e Event) error

func LastRequestInfo

func LastRequestInfo(e Event) error

func LuckyTrackRequest

func LuckyTrackRequest(e Event) error

func NewAnnounceService

func NewAnnounceService(cfg config.Config, storage radio.StorageService, bot *Bot) radio.AnnounceService

func NewHTTPServer

func NewHTTPServer(service radio.AnnounceService) (*grpc.Server, error)

func NowPlaying

func NowPlaying(e Event) error

func Pluralf

func Pluralf(format string, amount int64) string

Pluralf returns fmt.Sprintf(format, amount) but returns the string without its last character when amount == 1

func RandomTrackRequest

func RandomTrackRequest(e Event) error

func RegisterCommandHandlers

func RegisterCommandHandlers(ctx context.Context, b *Bot) error

func RegisterCommonHandlers

func RegisterCommonHandlers(b *Bot, c *girc.Client) error

RegisterCommonHandlers registers non-command handlers that are required for a functional client

func RequestTrack

func RequestTrack(e Event) error

func SearchTrack

func SearchTrack(e Event) error

func StreamerQueue

func StreamerQueue(e Event) error

func StreamerQueueLength

func StreamerQueueLength(e Event) error

func StreamerUserInfo

func StreamerUserInfo(e Event) error

func ThreadURL

func ThreadURL(e Event) error

func TrackInfo

func TrackInfo(e Event) error

func TrackTags

func TrackTags(e Event) error

Types

type Arguments

type Arguments map[string]string

Arguments is a map of key:value pairs from the named capturing groups used in the regular expression used for the command

func (Arguments) Bool

func (a Arguments) Bool(key string) bool

Bool returns true if the key exists and is non-empty

type Bot

type Bot struct {
	config.Config
	Storage radio.StorageService

	// interfaces to other components
	Manager  radio.ManagerService
	Streamer radio.StreamerService
	Searcher radio.SearchService

	// Values used by commands
	StatusValue    *util.Value[radio.Status]
	ListenersValue *util.Value[radio.Listeners]
	// contains filtered or unexported fields
}

func NewBot

func NewBot(ctx context.Context, cfg config.Config) (*Bot, error)

NewBot returns a Bot with configuration and handlers loaded

type CommonHandlers

type CommonHandlers struct {
	*Bot
}

CommonHandlers groups all handlers that should always be registered to function as basic irc bot

func (CommonHandlers) AuthenticateWithNickServ

func (h CommonHandlers) AuthenticateWithNickServ(c *girc.Client, e girc.Event)

AuthenticateWithNickServ tries to authenticate with nickserv with the password configured

func (CommonHandlers) JoinDefaultChannels

func (h CommonHandlers) JoinDefaultChannels(c *girc.Client, _ girc.Event)

JoinDefaultChannels joins all the channels listed in the configuration file

type Event

type Event struct {
	Ctx     context.Context
	Storage radio.StorageService

	girc.Event
	Arguments Arguments

	Bot    *Bot
	Client *girc.Client
}

Event is a collection of parameters to handler functions, all fields are guaranteed to be populated when passed through a RegexHandler

func (Event) ArgumentTrack

func (e Event) ArgumentTrack(key string) (*radio.Song, error)

ArgumentTrack returns the key given interpreted as a radio.TrackID and returns the song associated with it.

func (Event) CurrentTrack

func (e Event) CurrentTrack() (*radio.Song, error)

CurrentTrack returns the currently playing song on the main stream configured

func (Event) Echo

func (e Event) Echo(message string, args ...interface{})

Echo sends either a PRIVMSG to a channel or a NOTICE to a user based on the prefix used when running the command

func (Event) EchoPrivate

func (e Event) EchoPrivate(message string, args ...interface{})

EchoPrivate always sends a message as a NOTICE to the user that invoked the event

func (Event) EchoPublic

func (e Event) EchoPublic(message string, args ...interface{})

EchoPublic always sends a message as a PRIVMSG to the channel that the event was invoked on

type HandlerFn

type HandlerFn func(Event) error

type RegexHandler

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

type RegexHandlers

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

RegexHandlers is a collection of handlers that are triggered based on a regular expression.

An IRC events last parameter is used to match against.

func NewRegexHandlers

func NewRegexHandlers(ctx context.Context, bot *Bot, handlers ...RegexHandler) RegexHandlers

func (RegexHandlers) Execute

func (rh RegexHandlers) Execute(c *girc.Client, e girc.Event)

Execute implements girc.Handler

Jump to

Keyboard shortcuts

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