Skip to content

Commit

Permalink
Remove unsupported CST time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Llamas committed Feb 27, 2024
1 parent b146997 commit 64b92b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
11 changes: 5 additions & 6 deletions internal/bot/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error {
return err
}

if !isValidTimezone(timezone) {
if !IsValidTimezone(timezone) {
embedBuilder.SetDescription("Invalid timezone.")

return ctx.Respond(discordgo.InteractionResponseChannelMessageWithSource, &discordgo.InteractionResponseData{
Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *ConfigCommand) handleAutocomplete(ctx *bot.InteractionContext) error {
timezone := focusedOption.StringValue()
results := make([]*discordgo.ApplicationCommandOptionChoice, 0, maxResults)

for _, tz := range validTimezones {
for _, tz := range ValidTimezones {
target := getComparableTimezoneString(timezone)
compare := getComparableTimezoneString(tz)

Expand Down Expand Up @@ -253,10 +253,9 @@ func (c *ConfigCommand) handleAutocomplete(ctx *bot.InteractionContext) error {
})
}

var validTimezones = []string{
var ValidTimezones = []string{
"UTC",
"GMT",
"CST",
"EET",
"WET",
"CET",
Expand Down Expand Up @@ -302,8 +301,8 @@ var validTimezones = []string{
"Australia/Darwin",
}

func isValidTimezone(timezone string) bool {
for _, tz := range validTimezones {
func IsValidTimezone(timezone string) bool {
for _, tz := range ValidTimezones {
if timezone == tz {
return true
}
Expand Down
23 changes: 23 additions & 0 deletions internal/bot/commands/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package commands_test

import (
"testing"
"time"

"github.com/UTD-JLA/botsu/internal/bot/commands"
)

func TestTimeZone(t *testing.T) {
valid := true

for _, tz := range commands.ValidTimezones {
if _, err := time.LoadLocation(tz); err != nil {
t.Logf("Invalid time zone: %s", tz)
valid = false
}
}

if !valid {
t.Fail()
}
}
6 changes: 3 additions & 3 deletions internal/bot/commands/guild_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *GuildConfigCommand) Handle(ctx *bot.InteractionContext) error {
return err
}

if !isValidTimezone(timezone) {
if !IsValidTimezone(timezone) {
return ctx.Respond(discordgo.InteractionResponseChannelMessageWithSource, &discordgo.InteractionResponseData{
Content: "Invalid timezone",
})
Expand Down Expand Up @@ -89,7 +89,7 @@ func (c *GuildConfigCommand) handleAutocomplete(ctx *bot.InteractionContext) err
results := make([]*discordgo.ApplicationCommandOptionChoice, 0, maxResults)

if timezone == "" {
for i, tz := range validTimezones {
for i, tz := range ValidTimezones {
if i >= maxResults {
break
}
Expand All @@ -101,7 +101,7 @@ func (c *GuildConfigCommand) handleAutocomplete(ctx *bot.InteractionContext) err
}

} else {
for _, tz := range validTimezones {
for _, tz := range ValidTimezones {
target := getComparableTimezoneString(timezone)
compare := getComparableTimezoneString(tz)

Expand Down

0 comments on commit 64b92b8

Please sign in to comment.