mirror of
https://github.com/Xevion/banner.git
synced 2025-12-06 15:14:25 -06:00
Fix parse order for course range, remove TODO
This commit is contained in:
22
commands.go
22
commands.go
@@ -87,16 +87,6 @@ func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.Int
|
||||
var err error
|
||||
valueRaw := strings.TrimSpace(option.StringValue())
|
||||
|
||||
// 4 digit code
|
||||
if len(valueRaw) == 4 {
|
||||
low, err = strconv.Atoi(valueRaw)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing course code")
|
||||
}
|
||||
|
||||
high = low
|
||||
}
|
||||
|
||||
// Partially/fully specified range
|
||||
if strings.Contains(valueRaw, "-") {
|
||||
match := regexp.MustCompile(`(\d{1,4})-(\d{1,4})?`).FindSubmatch([]byte(valueRaw))
|
||||
@@ -126,7 +116,7 @@ func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.Int
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: #xxx, ##xx, ###x format
|
||||
// #xxx, ##xx, ###x format (34xx -> 3400-3499)
|
||||
if strings.Contains(valueRaw, "x") {
|
||||
if len(valueRaw) != 4 {
|
||||
return fmt.Errorf("code range format invalid: must be 1 or more digits followed by x's (%s)", valueRaw)
|
||||
@@ -150,6 +140,16 @@ func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.Int
|
||||
}
|
||||
}
|
||||
|
||||
// 4 digit code
|
||||
if len(valueRaw) == 4 {
|
||||
low, err = strconv.Atoi(valueRaw)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing course code")
|
||||
}
|
||||
|
||||
high = low
|
||||
}
|
||||
|
||||
if low == -1 || high == -1 {
|
||||
return fmt.Errorf("course code range was specified but was ignored silently (%s)", valueRaw)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user