Skip to content

Commit

Permalink
add config for music theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Pavoni committed Mar 29, 2022
1 parent 5363c97 commit 56badbb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
deploy_rpi.sh
build/

dist/
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Features are inspired by [chillybot](https://github.com/jaycammarano/chillybot),
- [ ] Rest time for DJ who has reached max songs limit and has been escorted (eg: default 5 mins)
- [x] Enforce song length limit (10 minutes by default)
- [x] Show song stats when song finishes (only when enabled, and bot is moderator)
- [ ] Show DJ stats when DJ leaves the stage (only when enabled, and bot is moderator)
- [x] Room greeting (only when enabled, and bot is moderator)
- [ ] Greeting message configurable
- [x] Playlists
Expand All @@ -28,7 +27,7 @@ Features are inspired by [chillybot](https://github.com/jaycammarano/chillybot),
- [x] Favorite rooms
- [x] Manage the list of favorite rooms
- [x] Join another room
- [x] Auto DJ when there are `1` or less djs
- [x] Auto DJ when there are `1` (default) or less djs
- [x] GIF reactions
- [x] Use as many reactions you want
- [x] Add new reactions or new GIFs to an existing one
Expand All @@ -42,7 +41,7 @@ Features are inspired by [chillybot](https://github.com/jaycammarano/chillybot),
- [ ] afk audience limit(separate from afk limit, both can be toggled on and off)
- [x] DJ stats (shown when dj goes off the stage)
- [ ] Print room rules (by command and/or when user joins)
- [ ] Room music current theme (default "free play")
- [x] Room music current theme (default "free play")
- [ ] Bot info (by command: print version, uptime, ...)
- [ ] custom prefix for commands (actual is `!`)
- [x] kill switch command (kills/disconnects bot, useful when it turns unresponsive/misbehaved)
Expand Down
2 changes: 1 addition & 1 deletion ttfm/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (a *Actions) RegisterUser(userId, userName string) {

a.bot.Users.AddUser(userId, userName)
if a.bot.Config.AutoWelcomeEnabled && a.bot.Users.UserIsModerator(a.bot.Identity.Id) {
msg := fmt.Sprintf("Hey @%s, welcome to %s! Type `!help` to know how to interact with me.", userName, a.bot.Room.Name)
msg := fmt.Sprintf("Hey @%s, welcome to `%s`! Current theme is [%s]. Type `!help` to know how to interact with me 🤖", userName, a.bot.Room.Name, a.bot.Config.MusicTheme)
a.bot.RoomMessage(msg)
}
}
Expand Down
18 changes: 18 additions & 0 deletions ttfm/commands/set_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/andreapavoni/ttfm_bot/ttfm"
)
Expand Down Expand Up @@ -57,6 +58,8 @@ func setConfigCommandHandler(b *ttfm.Bot, cmd *ttfm.CommandInput) *ttfm.CommandO
out = handleConfigValue(user, cmd, &b.Config.QueueEnabled)
case "songstats":
out = handleConfigValue(user, cmd, &b.Config.AutoShowSongStatsEnabled)
case "theme":
out = handleConfigStringValue(user, cmd, &b.Config.MusicTheme)
default:
return &ttfm.CommandOutput{User: user, ReplyType: cmd.Source, Err: errors.New("I can't find the setting you specified")}
}
Expand All @@ -67,6 +70,21 @@ func setConfigCommandHandler(b *ttfm.Bot, cmd *ttfm.CommandInput) *ttfm.CommandO
return &ttfm.CommandOutput{Msg: msg, User: user, ReplyType: cmd.Source}
}

func handleConfigStringValue(user *ttfm.User, cmd *ttfm.CommandInput, configKey *string) *ttfm.CommandOutput {
if len(cmd.Args) == 1 {
msg := fmt.Sprintf("Current setting for `%s` is: %s", cmd.Args[0], *configKey)
return &ttfm.CommandOutput{Msg: msg, User: user, ReplyType: cmd.Source}
}

if len(cmd.Args) >= 2 {
key := cmd.Args[0]
*configKey = strings.Join(cmd.Args[1:], " ")
msg := fmt.Sprintf("/me has set `%s` to: %v", key, *configKey)
return &ttfm.CommandOutput{Msg: msg, User: user, ReplyType: cmd.Source}
}
return &ttfm.CommandOutput{ReplyType: ttfm.MessageTypeNone}
}

func handleConfigValue[T any](user *ttfm.User, cmd *ttfm.CommandInput, configKey *T) *ttfm.CommandOutput {
if len(cmd.Args) == 1 {
msg := fmt.Sprintf("Current setting for `%s` is: %s", cmd.Args[0], configValueToString(*configKey))
Expand Down
2 changes: 2 additions & 0 deletions ttfm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
CurrentPlaylist string
SetBot bool
brain *Brain
MusicTheme string
}

func NewConfig(b *Brain) *Config {
Expand Down Expand Up @@ -93,4 +94,5 @@ func (c *Config) loadDefaultConfig() {
c.MaxSongsPerDj = 0
c.CurrentPlaylist = "default"
c.SetBot = false
c.MusicTheme = "FREE PLAY"
}

0 comments on commit 56badbb

Please sign in to comment.