mirror of
https://github.com/Xevion/banner.git
synced 2025-12-08 16:06:31 -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
|
var err error
|
||||||
valueRaw := strings.TrimSpace(option.StringValue())
|
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
|
// Partially/fully specified range
|
||||||
if strings.Contains(valueRaw, "-") {
|
if strings.Contains(valueRaw, "-") {
|
||||||
match := regexp.MustCompile(`(\d{1,4})-(\d{1,4})?`).FindSubmatch([]byte(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 strings.Contains(valueRaw, "x") {
|
||||||
if len(valueRaw) != 4 {
|
if len(valueRaw) != 4 {
|
||||||
return fmt.Errorf("code range format invalid: must be 1 or more digits followed by x's (%s)", valueRaw)
|
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 {
|
if low == -1 || high == -1 {
|
||||||
return fmt.Errorf("course code range was specified but was ignored silently (%s)", valueRaw)
|
return fmt.Errorf("course code range was specified but was ignored silently (%s)", valueRaw)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user