quizbot

package module
v0.0.0-...-5f95d92 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

README

MusicQuizBot

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SpotifyRegex = regexp.MustCompile(`(https?://)?(www\.)?open\.spotify\.com/(user/[\w-]+/)?(?P<type>track|album|playlist|artist)/(?P<identifier>[\w-]+)`)

Functions

func SaveConfig

func SaveConfig(config Config) error

Types

type Bot

type Bot struct {
	Logger   log.Logger
	Config   Config
	Client   bot.Client
	Commands map[string]Command
	Players  *QuizPlayers
	Spotify  *Spotify
}

func New

func New(cfg Config, logger log.Logger) (*Bot, error)

func (*Bot) AddCommands

func (b *Bot) AddCommands(commands ...Command)

func (*Bot) Close

func (b *Bot) Close(ctx context.Context)

func (*Bot) OnApplicationCommandInteractionCreate

func (b *Bot) OnApplicationCommandInteractionCreate(event *events.ApplicationCommandInteractionCreate)

func (*Bot) OnAutocompleteInteractionCreate

func (b *Bot) OnAutocompleteInteractionCreate(event *events.AutocompleteInteractionCreate)

func (*Bot) Start

func (b *Bot) Start() error

type Command

type Command struct {
	Create              discord.ApplicationCommandCreate
	Handler             func(b *Bot, event *events.ApplicationCommandInteractionCreate) error
	AutocompleteHandler func(b *Bot, event *events.AutocompleteInteractionCreate) error
}

type Config

type Config struct {
	DevMode      bool          `json:"dev_mode"`
	GuildID      snowflake.ID  `json:"guild_id"`
	LogLevel     log.Level     `json:"log_level"`
	Token        string        `json:"token"`
	SyncCommands bool          `json:"sync_commands"`
	Database     db.Config     `json:"database"`
	Spotify      SpotifyConfig `json:"spotify"`
}

func LoadConfig

func LoadConfig() (*Config, error)

type HTTPError

type HTTPError int

func (HTTPError) Error

func (e HTTPError) Error() string

type PlaylistTrack

type PlaylistTrack struct {
	Track Track `json:"track"`
}

type QuizPlayer

type QuizPlayer struct {
	Queue        *QuizQueue
	CurrentTrack *QuizTrack
	// contains filtered or unexported fields
}

func (*QuizPlayer) Play

func (p *QuizPlayer) Play(errorHandler func(err error))

func (*QuizPlayer) PlayNext

func (p *QuizPlayer) PlayNext(errorHandler func(err error))

type QuizPlayers

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

func NewQuizPlayers

func NewQuizPlayers() *QuizPlayers

func (*QuizPlayers) Get

func (p *QuizPlayers) Get(guildID snowflake.ID) *QuizPlayer

func (*QuizPlayers) New

func (p *QuizPlayers) New(guildID snowflake.ID, client bot.Client, conn voice.Connection) *QuizPlayer

type QuizQueue

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

func NewQuizQueue

func NewQuizQueue() *QuizQueue

func (*QuizQueue) Pop

func (q *QuizQueue) Pop() (QuizTrack, bool)

func (*QuizQueue) Push

func (q *QuizQueue) Push(tracks ...QuizTrack)

type QuizTrack

type QuizTrack struct {
	ID     string
	Name   string
	Artist string
	Image  *string
	URL    string
}

type Response

type Response[T any] struct {
	HREF     string  `json:"href"`
	Items    []T     `json:"items"`
	Limit    int     `json:"limit"`
	Next     *string `json:"next"`
	Offset   int     `json:"offset"`
	Previous *string `json:"previous"`
	Total    int     `json:"total"`
}

type Spotify

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

func NewSpotify

func NewSpotify(cfg SpotifyConfig, logger log.Logger) *Spotify

func (*Spotify) Do

func (s *Spotify) Do(url string, rsBody any) error

func (*Spotify) GetPlaylist

func (s *Spotify) GetPlaylist(id string) ([]PlaylistTrack, error)

func (*Spotify) GetToken

func (s *Spotify) GetToken() (string, error)

type SpotifyConfig

type SpotifyConfig struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

type Track

type Track struct {
	Album *struct {
		Images []struct {
			URL *string `json:"url"`
		} `json:"images"`
	}
	Artists []struct {
		Name string `json:"name"`
	} `json:"artists"`

	ID         string  `json:"id"`
	Name       string  `json:"name"`
	PreviewURL *string `json:"preview_url"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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