soundboard

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 32 Imported by: 0

README

Soundboard

Soundboard plugin for YAGPDB

Folder structure:

Sounds waiting:

soundboard/queue/guildid/soundhash.extension

Transcoded sounds

soundboard/ready/guildid/soundhash.dca

Documentation

Index

Constants

View Source
const (
	MaxGuildSounds        = 50
	MaxGuildSoundsPremium = 250
)

Variables

View Source
var DBSchemas = []string{`
CREATE TABLE IF NOT EXISTS soundboard_sounds(
	id SERIAL PRIMARY KEY,
	created_at TIMESTAMP WITH TIME ZONE NOT NULL,
	updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
	
	guild_id BIGINT NOT NULL,
	required_role TEXT NOT NULL,
	name TEXT NOT NULL,
	status INT NOT NULL,

	required_roles BIGINT[],
	blacklisted_roles BIGINT[]
);
`, `
CREATE INDEX IF NOT EXISTS soundboard_sounds_guild_idx ON soundboard_sounds(guild_id);
`, `

-- i was using gorm way back, and that apperently didn't add not null constraints
-- so for existing tables make sure they're present

-- this SHOULD be impossible, but just to sure... (was 0 rows on prod db)
DELETE FROM soundboard_sounds WHERE guild_id IS NULL or required_role IS NULL or name IS NULL or status IS NULL or created_at IS NULL or updated_at IS NULL;
`, `

ALTER TABLE soundboard_sounds ALTER COLUMN guild_id SET NOT NULL;
`, `
ALTER TABLE soundboard_sounds ALTER COLUMN required_role SET NOT NULL;
`, `
ALTER TABLE soundboard_sounds ALTER COLUMN name SET NOT NULL;
`, `
ALTER TABLE soundboard_sounds ALTER COLUMN status SET NOT NULL;
`, `
ALTER TABLE soundboard_sounds ALTER COLUMN created_at SET NOT NULL;
`, `
ALTER TABLE soundboard_sounds ALTER COLUMN updated_at SET NOT NULL;

`, `
-- we migrate the data from the old system so that peoples settings dont dissapear
DO $$
BEGIN
	IF (SELECT COUNT(*) FROM information_schema.columns WHERE table_name='soundboard_sounds' and column_name='required_roles') < 1 THEN
		ALTER TABLE soundboard_sounds ADD COLUMN required_roles BIGINT[];
		ALTER TABLE soundboard_sounds ADD COLUMN blacklisted_roles BIGINT[];

		-- migrate
		UPDATE soundboard_sounds SET required_roles=ARRAY[required_role]::BIGINT[] WHERE required_role IS NOT NULL AND required_role != '';
	END IF;
END $$;
`}
View Source
var (
	ErrVoiceSendTimeout = errors.New("Voice send timeout")
)
View Source
var PageHTML string
View Source
var (
	Silence = []byte{0xF8, 0xFF, 0xFE}
)

Functions

func CanPlaySound added in v1.13.0

func CanPlaySound(s *models.SoundboardSound, roles []int64) bool

func DownloadNewSoundFile added in v1.4.1

func DownloadNewSoundFile(r io.Reader, w io.Writer, limit int) (tooBig bool, err error)

func GetSoundboardSounds added in v1.13.0

func GetSoundboardSounds(guildID int64, ctx context.Context) ([]*models.SoundboardSound, error)

func HandleDelete

func HandleDelete(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleGetCP

func HandleGetCP(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleNew

func HandleNew(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleUpdate

func HandleUpdate(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func KeySoundLock

func KeySoundLock(id int) string

func ListSounds

func ListSounds(sounds []*models.SoundboardSound, ms *dstate.MemberState) string

func MaxSoundsForContext added in v1.6.0

func MaxSoundsForContext(ctx context.Context) int

func RegisterPlugin

func RegisterPlugin()

func RequestPlaySound

func RequestPlaySound(guildID int64, channelID, channelRanFrom int64, soundID int) (queued bool)

RequestPlaySound either queues up a sound to be played in an existing player or creates a new one

func SoundFilePath

func SoundFilePath(id int, status TranscodingStatus) string

Types

type PlayRequest

type PlayRequest struct {
	ChannelID      int64
	GuildID        int64
	CommandRanFrom int64
	Sound          int
}

type Player added in v1.20.13

type Player struct {
	GuildID int64

	// below fields are safe to access with playersmu
	ChannelID int64
	// contains filtered or unexported fields
}

Player represends a voice connection playing a soundbaord file (or waiting for one)

func (*Player) Run added in v1.20.13

func (p *Player) Run()

Run runs the main player goroutine

type Plugin

type Plugin struct{}

func (*Plugin) AddCommands added in v1.4.1

func (p *Plugin) AddCommands()

func (*Plugin) InitWeb

func (p *Plugin) InitWeb()

func (*Plugin) LoadServerHomeWidget added in v1.17.0

func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func (*Plugin) PluginInfo added in v1.17.0

func (p *Plugin) PluginInfo() *common.PluginInfo

func (*Plugin) RunBackgroundWorker added in v1.11.0

func (p *Plugin) RunBackgroundWorker()

func (*Plugin) StopBackgroundWorker added in v1.11.0

func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup)

type PostForm added in v1.13.0

type PostForm struct {
	ID   int
	Name string `valid:",100"`

	RequiredRoles    []int64 `valid:"role"`
	BlacklistedRoles []int64 `valid:"role"`
}

func (*PostForm) ToDBModel added in v1.13.0

func (pf *PostForm) ToDBModel() *models.SoundboardSound

type TranscodingStatus

type TranscodingStatus int
const (
	// In the transcoding queue
	TranscodingStatusQueued TranscodingStatus = iota
	// Done transcoding and ready to be played
	TranscodingStatusReady
	// Currently transcoding
	TranscodingStatusTranscoding
	// Failed transcoding, too long
	TranscodingStatusFailedLong
	// Failed transcofing, contact support
	TranscodingStatusFailedOther
)

func (TranscodingStatus) String

func (s TranscodingStatus) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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