Skip to content

Commit

Permalink
command: add hte effect
Browse files Browse the repository at this point in the history
In memoriam
hte in Momo's chat
2024-2024
R.I.P.
  • Loading branch information
zephyrtronium committed Nov 19, 2024
1 parent 7d89fd8 commit 35fd063
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion command/effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Effect applies an effect to a message.
// The currently available effects include "OwO", "AAAAA", "o", and "".
// The currently available effects include "OwO", "AAAAA", "o", "hte", and "".
// Names are not case sensitive.
func Effect(log *slog.Logger, name, msg string) string {
var r string
Expand All @@ -20,6 +20,8 @@ func Effect(log *slog.Logger, name, msg string) string {
r = lenlimit(aaaaaize(msg), 40)
case strings.EqualFold(name, "o"):
r = oize(msg)
case strings.EqualFold(name, "hte"):
r = hteize(msg)
default:
log.Error("no such effect", slog.String("name", name), slog.String("msg", msg))
return msg
Expand Down Expand Up @@ -68,3 +70,26 @@ var oRep = strings.NewReplacer(
"a", "o", "e", "o", "i", "o", "u", "o",
"A", "O", "E", "O", "I", "O", "U", "O",
)

func hteize(msg string) string {
// We do a slightly higher effort replace-by-word for this effect because
// a naïve replacer would replace components of words we want to preserve.
f := strings.Fields(msg)
for i, w := range f {
switch w {
case "the", "The":
f[i] = "hte"
case "THE":
f[i] = "HTE"
case "a":
f[i] = "an"
case "A":
// skip this one
case "an", "An":
f[i] = "a"
case "AN":
f[i] = "A"
}
}
return strings.Join(f, " ")
}

0 comments on commit 35fd063

Please sign in to comment.