summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruakci <uakci@uakci.pl>2022-08-15 18:38:21 +0200
committeruakci <uakci@uakci.pl>2022-08-15 18:38:21 +0200
commit7ebfd3d5ff86bbabdd95c8d0a395e0690db90792 (patch)
treeead5dfa37ae30302cbc07456fa8239462d3e5b9c
parentanti- 30 byte images; rudimentary fixes (diff)
downloadnuogai-7ebfd3d5ff86bbabdd95c8d0a395e0690db90792.tar.gz
nuogai-7ebfd3d5ff86bbabdd95c8d0a395e0690db90792.zip
fix !'s chattiness; fix / handling in ?
-rw-r--r--bot.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/bot.go b/bot.go
index 3eea7d4..2ea9075 100644
--- a/bot.go
+++ b/bot.go
@@ -32,8 +32,9 @@ const (
)
var (
- markdownLinkRegex = regexp.MustCompile(`!?\[(.*)\]\((.*)\)`)
- ports struct {
+ markdownLinkRe = regexp.MustCompile(`!?\[(.*)\]\((.*)\)`)
+ alphaHyphenRe = regexp.MustCompile(`^[a-z-]+$`)
+ ports struct {
toa, spe, nui string
}
)
@@ -191,9 +192,17 @@ func respond(message string, callback func(Response)) {
return
}
} else if strings.HasPrefix(cmd, "?") && len(cmd) > 1 {
- returnText(fmt.Sprintf(wikiPageUrl, strings.ReplaceAll(strings.TrimSpace(cmd[1:]+" "+rest), " ", "_")))
+ fragments := strings.Split(strings.TrimSpace(cmd[1:]+" "+rest), "/")
+ for i, fragment := range fragments {
+ _, offset, err := strings.NewReader(fragment).ReadRune()
+ if err != nil {
+ continue
+ }
+ fragments[i] = strings.ToUpper(fragment[:offset]) + strings.ReplaceAll(fragment[offset:], " ", "_")
+ }
+ returnText(fmt.Sprintf(wikiPageUrl, strings.Join(fragments, "/")))
return
- } else if strings.HasPrefix(cmd, "!") && len(cmd) > 1 && cmd != "!iamvoicechat" {
+ } else if strings.HasPrefix(cmd, "!") && len(args) == 0 && alphaHyphenRe.MatchString(cmd[1:]) && cmd != "!iamvoicechat" {
all, err := get(wikiCommandsUrl)
if err != nil {
returnText(err.Error())
@@ -226,7 +235,7 @@ func respond(message string, callback func(Response)) {
}
}
if selected != "" {
- selected = markdownLinkRegex.ReplaceAllString(selected, "$2")
+ selected = markdownLinkRe.ReplaceAllString(selected, "$2")
returnText(selected)
} else {
returnText(fmt.Sprintf("could not find !%s", cmd[1:]))