manager

package
v0.0.0-...-e4f0057 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Notifications = make(chan notification.NotificationMessage, 1)
)

Functions

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI formats bytes into a readable format

func CmdsKill

func CmdsKill(cmds []*exec.Cmd)

CmdsKill kills all the exec.Cmd inside the slice

func CmdsStart

func CmdsStart(cmds []*exec.Cmd)

CmdsStart starts all the exec.Cmd inside the slice

func CmdsWait

func CmdsWait(cmds []*exec.Cmd)

CmdsWait waits for all the exec.Cmd inside the slice to finish processing, to free up resources

func DeleteInteraction

func DeleteInteraction(s *discordgo.Session, i *discordgo.Interaction, c <-chan struct{})

func FindUserVoiceState

func FindUserVoiceState(s *discordgo.Session, guildID, userID string) *discordgo.VoiceState

FindUserVoiceState finds user current voice channel

func FolderStats

func FolderStats(path string) (size int64, i int)

FolderStats gets the size of a directory and the number of files in it

func FormatDuration

func FormatDuration(duration float64) string

FormatDuration Formats a string given its duration in seconds

func HasRole

func HasRole(roles []string, role string) bool

func IsCommandNotAvailable

func IsCommandNotAvailable(name string) bool

IsCommandNotAvailable isCommandNotAvailable checks whatever a command is available

func IsValidURL

func IsValidURL(toTest string) bool

IsValidURL Checks if a string is a valid URL

func JoinVC

func JoinVC(i *discordgo.Interaction, channelID string, s *discordgo.Session, server *Server, isDeferred chan struct{}) bool

JoinVC joins the voice channel if not already joined, returns true if joined successfully

func QuitVC

func QuitVC(server *Server)

QuitVC disconnects the bot from the voice channel after 1 minute if nothing is playing

func Stream

func Stream(link string) (io.ReadCloser, []*exec.Cmd)

Stream substitutes the old scripts for streaming directly to discord from a given source

Types

type Clients

type Clients struct {
	Spotify  *spotify.Spotify
	Youtube  *youtube.YouTube
	Discord  *discordgo.Session
	Database *database.Database
}

Clients holds all the clients used for interacting with the various APIs

type PlayEvent

type PlayEvent struct {
	Username    string
	Song        string
	Clients     *Clients
	Interaction *discordgo.Interaction
	Random      bool
	Loop        bool
	Priority    bool
	IsDeferred  chan struct{}
}

PlayEvent is the struct for playing songs

type PlayStatus

type PlayStatus int8
const (
	Success PlayStatus = iota
	NotInVC
	Playlist
	DjMode
)

type RequestedFormats

type RequestedFormats []struct {
	Resolution string `json:"resolution"`
}

RequestedFormats is used to detect if an audio only codec is available

type Server

type Server struct {
	// The queue
	Queue queue.Queue
	// Voice connection
	VC *vc.VC
	// Custom commands, maps a command to a song
	Custom map[string]*database.CustomCommand
	// Frames
	Frames atomic.Uint64
	// Quit channel
	Skip chan SkipReason
	// Whether the job scheduler has started
	Started atomic.Bool
	// Whether to clear the queue
	Clear atomic.Bool
	// Guild ID
	GuildID string
	// Whether the bot is paused
	Paused atomic.Bool
	// Channel for pausing
	Pause chan struct{}
	// Channel for resuming
	Resume chan struct{}
	// Wait group for waiting for spotify to finish before lowering the clear flag
	WG *sync.WaitGroup
	// Role ID for the DJ role
	DjRole string
	// Whether the DJ mode is enabled
	DjMode bool
	// Clients used for interacting with the various APIs
	Clients *Clients
}

Server holds all info about a single server

func NewServer

func NewServer(guildID string, clients *Clients) *Server

NewServer creates a new server manager

func (*Server) AddSong

func (server *Server) AddSong(priority bool, el ...queue.Element)

AddSong adds a song to the queue

func (*Server) Clean

func (server *Server) Clean()

Clean clears the queue

func (*Server) DjModeCheck

func (server *Server) DjModeCheck(s *discordgo.Session, i *discordgo.InteractionCreate, owner string, isDeferred chan struct{}) bool

func (*Server) IsPlaying

func (server *Server) IsPlaying() bool

IsPlaying returns whether the bot is playing

func (*Server) Play

func (server *Server) Play(p PlayEvent)

Wrapper function for playing songs

func (*Server) PlayCommand

func (server *Server) PlayCommand(clients *Clients, i *discordgo.InteractionCreate, playlist bool, owner string) (status PlayStatus)

type SkipReason

type SkipReason int8

SkipReason is used to determine why playSound returned

const (
	Error SkipReason = iota
	Finished
	Skip
	Clear
)

type YtDLP

type YtDLP struct {
	Duration         float64          `json:"duration"`
	Thumbnail        string           `json:"thumbnail"`
	Extractor        string           `json:"extractor"`
	ID               string           `json:"id"`
	WebpageURL       string           `json:"webpage_url"`
	Title            string           `json:"title"`
	RequestedFormats RequestedFormats `json:"requested_formats"`
}

YtDLP structure for holding yt-dlp data

Jump to

Keyboard shortcuts

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