Skip to content

Commit

Permalink
play ambient and volume fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Depado committed Nov 13, 2020
1 parent 0057230 commit afd62a1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 26 deletions.
28 changes: 28 additions & 0 deletions acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ func (a ACL) Check(r RoleRestriction, c ChannelRestriction, u *discordgo.Member,
return true
}

func RoleRestrictionString(r RoleRestriction) string {
var rr string

switch r {
case Admin:
rr = "🔐 Admin"
case Privileged:
rr = "🔒 Admin or DJ"
case Anyone:
rr = "🔓 No restriction"
}

return rr
}

func ChannelRestrictionString(c ChannelRestriction) string {
var cr string

switch c {
case Music:
cr = "🎶 Music text channel only"
case Anywhere:
cr = "🌍 No restriction"
}

return cr
}

// IsMusic will check if the provided message was sent to the music channel.
func (a ACL) IsMusic(m *discordgo.Message) bool {
return m.ChannelID == a.MusicChannelID
Expand Down
4 changes: 3 additions & 1 deletion bot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"time"

"github.com/Depado/fox/acl"
"github.com/Depado/fox/message"
"github.com/bwmarrin/discordgo"
)
Expand Down Expand Up @@ -71,7 +72,8 @@ func (b *Bot) MessageCreatedHandler(s *discordgo.Session, m *discordgo.MessageCr
// Check permissions
cr, rr := c.ACL()
if !b.acl.Check(rr, cr, member, m.Message) {
err := message.SendTimedReply(s, m.Message, "", "You do not have the permission to do that", "", 5*time.Second)
msg := fmt.Sprintf("You do not have permission to do that.\n%s\n%s", acl.RoleRestrictionString(rr), acl.ChannelRestrictionString(cr))
err := message.SendTimedReply(s, m.Message, "", msg, "", 5*time.Second)
if err != nil {
b.log.Err(err).Msg("unable to send timed reply")
}
Expand Down
28 changes: 8 additions & 20 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,14 @@ func (c BaseCommand) GetHelp() Help {

func (c BaseCommand) DisplayHelp(s *discordgo.Session, m *discordgo.Message, prefix string) {
desc := c.Help.Description

var cr string
switch c.ChannelRestriction {
case acl.Music:
cr = "🎶 Music text channel only"
case acl.Anywhere:
cr = "🌍 No restriction"
}
desc += fmt.Sprintf("\n\nChannel Restriction\n**%s**", cr)

var rr string
switch c.RoleRestriction {
case acl.Admin:
rr = "🔐 Admin"
case acl.Privileged:
rr = "🔒 Admin or DJ"
case acl.Anyone:
rr = "🔓 No restriction"
}
desc += fmt.Sprintf("\n\nRole Restriction\n**%s**", rr)
desc += fmt.Sprintf(
"\n\nChannel Restriction\n**%s**",
acl.ChannelRestrictionString(c.ChannelRestriction),
)
desc += fmt.Sprintf(
"\n\nRole Restriction\n**%s**",
acl.RoleRestrictionString(c.RoleRestriction),
)

var aliases string
if len(c.Aliases) > 0 {
Expand Down
22 changes: 18 additions & 4 deletions commands/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ func (c *play) Handler(s *discordgo.Session, m *discordgo.Message, args []string
}
return
}
c.Player.Play()

msg := fmt.Sprintf("▶️ Started playing for <@%s>", m.Author.ID)
if len(args) > 0 && args[0] == "ambient" {
if err := c.Player.SetVolumePercent(50); err != nil {
c.log.Err(err).Msg("unable to set volume")
} else {
msg += " in ambient mode"
}
}
c.Player.Play()
if err := message.SendReply(s, m, "", msg, ""); err != nil {
c.log.Err(err).Msg("unable to ")
c.log.Err(err).Msg("unable to send reply")
}
}

Expand All @@ -52,8 +60,14 @@ func NewPlayCommand(p *player.Player, log *zerolog.Logger) Command {
Usage: cmd,
ShortDesc: "Start playing the queue",
Description: "This command will start playing the queue. " +
"It has no effect if the queue is the player is already " +
"active.\nThe bot will join the vocal channel when playing starts",
"It has no effect if the player is already " +
"active.\nThe bot will join the vocal channel when playing " +
"starts.\n\n`ambient` can be passed as an extra argument " +
"to play in ambient mode with a lower volume.",
Examples: []Example{
{Command: "play", Explanation: "Start playing"},
{Command: "play ambient", Explanation: "Start playing in ambient mode"},
},
},
Player: p,
log: log.With().Str("command", cmd).Logger(),
Expand Down
2 changes: 1 addition & 1 deletion commands/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *volume) Handler(s *discordgo.Session, m *discordgo.Message, args []stri
var emoji = "🔉"

if len(args) < 1 {
v = c.Player.State.Volume / 256 * 100
v = c.Player.State.Volume * 100 / 256
if v > 100 {
emoji = "🔊"
} else if v < 100 {
Expand Down

0 comments on commit afd62a1

Please sign in to comment.