framework

package
v0.0.0-...-340dc28 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OnError = func(str string, err error) {
	prefix := "dgVoice: " + str

	if err != nil {
		os.Stderr.WriteString(prefix + ": " + err.Error())
	} else {
		os.Stderr.WriteString(prefix)
	}
}

OnError gets called when an error is encountered. By default logs to STDERR

Functions

func DownloadMultipleYoutubeVideo

func DownloadMultipleYoutubeVideo(input string) (*[]VideoInfo, error)

DownloadMultipleYoutubeVideo will download an entire youtube playlist video a url to the playlist is required.

func DownloadSingleYoutubeVideo

func DownloadSingleYoutubeVideo(input string) (*[]VideoInfo, error)

DownloadSingleYoutubeVideo will download a single youtube video when a search term or a direct link is provided.

func DownloadYoutubeVideo

func DownloadYoutubeVideo(input string) (*[]VideoInfo, error)

DownloadYoutubeVideo will parse the input and grab the appropriate video. The input can either be a search term or a direct link to a single video or a playlist.

func Insert

func Insert(vi *VideoInfo, mc *discordgo.Message, ctx *Context)

Insert will add song to the queue for a specific server.

func JoinUserVoiceChannel

func JoinUserVoiceChannel(session *discordgo.Session, userID string) (*discordgo.VoiceConnection, error)

JoinUserVoiceChannel ...

func MaybePlaySong

func MaybePlaySong(ds *discordgo.Session, mc *discordgo.Message, ctx *Context)

MaybePlaySong will check if there is anything playing on the related Guild, if there is not and there is something in the queue it will start playing the next video in the queue.

func PlayAudioFile

func PlayAudioFile(v *discordgo.VoiceConnection, filename string, stop <-chan bool)

PlayAudioFile will play the given filename to the already connected Discord voice server/channel. voice websocket and udp socket must already be setup before this will work.

func ReceivePCM

func ReceivePCM(v *discordgo.VoiceConnection, c chan *discordgo.Packet)

ReceivePCM will receive on the the Discordgo OpusRecv channel and decode the opus audio into PCM then send it on the provided channel.

func RemoveSong

func RemoveSong(guildID string, store *Store)

RemoveSong will remove the song at the front of the queue for the related Guild

func SendPCM

func SendPCM(v *discordgo.VoiceConnection, pcm <-chan []int16)

SendPCM will receive on the provied channel encode received PCM data into Opus then send that to Discordgo

func UpsertUserInfo

func UpsertUserInfo(db *sql.DB, user *discordgo.User) error

UpsertUserInfo will query the database and return the value of the targetUserID's wallet If that user is not in the database they will be added and given the starting amount of currency

Types

type Context

type Context struct {
	Fields             []string
	Content            string
	DatabaseConnection *sql.DB
	GuildID            string
	IsDirected         bool
	IsPrivate          bool
	HasPrefix          bool
	HasMention         bool
	HasMentionFirst    bool
	Info               *Store
}

Context holds extra data that is passed along to route handlers This way processing some of this only need to happen once

type HandlerFunc

type HandlerFunc func(*discordgo.Session, *discordgo.Message, *Context)

HandlerFunc is the function signature required for a message route handler

type Mux

type Mux struct {
	Routes             []*Route
	Default            *Route
	Prefix             string
	DatabaseConnection *sql.DB
	Info               *Store
}

Mux is the main struct for all mux methods.

func NewMux

func NewMux() *Mux

NewMux returns a new Discord message route mux

func (*Mux) ConnectDB

func (m *Mux) ConnectDB(filename string)

ConnectDB will connect the multiplexer to a database that holds information about the users on the discord server

func (*Mux) ListRoutes

func (m *Mux) ListRoutes(ds *discordgo.Session)

ListRoutes will list all of the routes into the chat

func (*Mux) Match

func (m *Mux) Match(msg string) (*Route, error)

Match attempts to find the route for the given message

func (*Mux) OnMessageCreate

func (m *Mux) OnMessageCreate(ds *discordgo.Session, mc *discordgo.MessageCreate)

OnMessageCreate is a DiscordGo Event Handler function. This function will receive all Discord message and parse themm for matches to registered routes.

func (*Mux) Route

func (m *Mux) Route(pattern []string, desc string, cb HandlerFunc) (*Route, error)

Route allows you to register a route

type Route

type Route struct {
	Pattern     []string
	Description string
	Help        string
	Run         HandlerFunc
}

Route holds information about a specific message route handler

type Song

type Song struct {
	Media    string
	Title    string
	Duration *string
	ID       string
}

Song ...

func NewSong

func NewSong(media, title, id string) *Song

NewSong ...

func (Song) Ffmpeg

func (song Song) Ffmpeg() *exec.Cmd

Ffmpeg ...

type Store

type Store struct {
	SongQueue      map[string][]VideoInfo
	AudioIsPlaying map[string]bool
}

Store is a generic place to maintain long term information.

type VideoInfo

type VideoInfo struct {
	WebpageURL string
	Title      string
	ID         string
}

VideoInfo stores information needed to display in discord TODO(sandaluz) add the information about who added this song to the queue

Jump to

Keyboard shortcuts

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