feat(music): add /music toggle and gate playback behind it
Music could be started and controlled with no way to turn it off for a server. Adds a music_settings table (mirrors the same one velox-dashboard-api's dashboard toggle reads/writes), a /music toggle command gated to Manage Server, and checks in /play, /queue, and /volume so they refuse to run when a server has music turned off.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package musicsettings
|
||||
|
||||
import (
|
||||
"context"
|
||||
"velox-bot/internal/db/repos/settingsrepo"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
settings *settingsrepo.Repo
|
||||
}
|
||||
|
||||
func New(settings *settingsrepo.Repo) *Service {
|
||||
return &Service{settings: settings}
|
||||
}
|
||||
|
||||
func (s *Service) ToggleMusic(ctx context.Context, guildID int64) (bool, error) {
|
||||
enabled, err := s.settings.IsMusicEnabled(ctx, guildID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
newEnabled := !enabled
|
||||
if err := s.settings.SetMusicEnabled(ctx, guildID, newEnabled); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return newEnabled, nil
|
||||
}
|
||||
|
||||
func (s *Service) IsMusicEnabled(ctx context.Context, guildID int64) (bool, error) {
|
||||
return s.settings.IsMusicEnabled(ctx, guildID)
|
||||
}
|
||||
Reference in New Issue
Block a user