summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruakci <git@uakci.space>2024-08-19 00:48:52 +0200
committeruakci <git@uakci.space>2024-08-19 00:48:52 +0200
commit586a27b1a27608a333b159eeb3ffa1600c650d20 (patch)
treeefd2740b797042270468dfd9e8d0480a82664278
parenttweak logic (bad code but am tired) (diff)
downloadnuogai-586a27b1a27608a333b159eeb3ffa1600c650d20.tar.gz
nuogai-586a27b1a27608a333b159eeb3ffa1600c650d20.zip
add links to each entryHEADmain
-rw-r--r--bot.go47
-rw-r--r--module.nix11
2 files changed, 30 insertions, 28 deletions
diff --git a/bot.go b/bot.go
index 1172f10..7d3ac17 100644
--- a/bot.go
+++ b/bot.go
@@ -28,17 +28,20 @@ const (
wikiHelpUrl = "https://toaq.me/Nuogaı"
wikiPageUrl = "https://toaq.me/%s"
wikiCommandsUrl = "https://toaq.me/Discord/Help_text?action=render"
- toaduaUrl = "%s/api"
+ toaduaApiUrl = "%s/api"
+ toaduaUrlForId = "%s/##%s"
zugaiUrl = "%s/zugai?to=%s&text=%s"
- lozenge = '▯'
+ lozenge = '□'
)
var (
- markdownLinkRe = regexp.MustCompile(`!?\[(.*)\]\((.*)\)`)
- alphaHyphenRe = regexp.MustCompile(`^[a-z-]+$`)
- allBangsRe = regexp.MustCompile(`^[!?]*$`)
- toaduaCmdRe = regexp.MustCompile(`^%([1-9][0-9]*)?$`)
- toaduaHost, zugaiHost string
+ markdownLinkRe = regexp.MustCompile(`!?\[(.*)\]\((.*)\)`)
+ alphaHyphenRe = regexp.MustCompile(`^[a-z-]+$`)
+ allBangsRe = regexp.MustCompile(`^[!?]*$`)
+ toaduaCmdRe = regexp.MustCompile(`^%([1-9][0-9]*)?$`)
+ hostInternal string
+ hostExternal string
+ zugaiHost string
)
func mustGetenv(name string) (env string) {
@@ -50,7 +53,8 @@ func mustGetenv(name string) (env string) {
}
func init() {
- toaduaHost = mustGetenv("TOADUA_HOST")
+ hostInternal = mustGetenv("TOADUA_HOST_INTERNAL")
+ hostExternal = mustGetenv("TOADUA_HOST_EXTERNAL")
zugaiHost = mustGetenv("ZUGAI_HOST")
}
@@ -413,7 +417,7 @@ func Toadua(args []string, howMany int, returnText func(string)) {
returnText("error")
return
}
- raw, err := http.Post(fmt.Sprintf(toaduaUrl, toaduaHost),
+ raw, err := http.Post(fmt.Sprintf(toaduaApiUrl, hostInternal),
"application/json", bytes.NewReader(mars))
if err != nil {
log.Print(err)
@@ -455,28 +459,25 @@ func Toadua(args []string, howMany int, returnText func(string)) {
searchProngs += "–" + strconv.Itoa(last)
}
fmt.Fprintf(&b, "\u2003(%s/%d)", searchProngs, len(resp.Entries))
+
soFar := b.String()
for _, e := range resp.Entries[first:last] {
- // if i != 0 {
- b.WriteString("\n")
- // }
- // b.WriteString(" — ")
- b.WriteString("**" + e.Head + "**")
- fmt.Fprintf(&b, " (%s)", e.User)
- if e.Score != 0 {
- b.WriteString(" ")
- if e.Score > 0 {
- b.WriteString(strings.Repeat("+", e.Score))
- } else {
- b.WriteString(strings.Repeat("−", -e.Score))
- }
+ pageUrl := fmt.Sprintf(toaduaUrlForId, hostExternal, e.Id)
+ fmt.Fprintf(&b, "\n**[%s](<%s>)** (%s) ", e.Head, pageUrl, e.User)
+
+ if e.Score > 0 {
+ b.WriteString(strings.Repeat("+", e.Score))
+ } else {
+ b.WriteString(strings.Repeat("−", -e.Score))
}
- // b.WriteString(" — ")
+
b.WriteString("\n\u2003")
b.WriteString(strings.Join(strings.Split(e.Body, "\n"), "\n\u2003"))
+
for _, note := range e.Notes {
fmt.Fprintf(&b, "\n\u2003\u2003• (%s) %s", note.User, note.Content)
}
+
old := soFar
soFar = b.String()
if len(soFar) > 2000 {
diff --git a/module.nix b/module.nix
index f1435c4..5b6f960 100644
--- a/module.nix
+++ b/module.nix
@@ -3,21 +3,22 @@ let cfg = config.services.nuogai;
in with lib; {
options.services.nuogai = {
enable = mkEnableOption "Enables the nuogaı Discord Bot";
- toaduaHost = mkOption { type = types.str; };
+ hostInternal = mkOption { type = types.str; };
+ hostExternal = mkOption { type = types.str; };
zugaiHost = mkOption { type = types.str; };
tokenPath = mkOption { type = types.path; };
};
config = {
fonts.fonts = optionals cfg.enable [ self.packages.${system}.toaqScript ];
- services.nuogai.zugaiHost = lib.mkDefault "https://zugai.toaq.me";
systemd.services.nuogai = {
inherit (cfg) enable;
description = "Toaq Discord bot";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
- environment = {
- TOADUA_HOST = cfg.toaduaHost;
- ZUGAI_HOST = cfg.zugaiHost;
+ environment = with cfg; {
+ TOADUA_HOST_INTERNAL = hostInternal;
+ TOADUA_HOST_EXTERNAL = hostExternal;
+ ZUGAI_HOST = zugaiHost;
};
script = ''
export NUOGAI_TOKEN=$(cat ${cfg.tokenPath})