Fix parse order for course range, remove TODO

This commit is contained in:
2024-02-16 17:14:34 -06:00
parent 44abcd605a
commit 595228df15

View File

@@ -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)
}