diff options
| author | 2021-05-31 19:27:13 +0200 | |
|---|---|---|
| committer | 2021-06-03 18:38:26 +0200 | |
| commit | ee593d7c6b76c9c86a3d4e099c234e9d784570b7 (patch) | |
| tree | c4885abe45a87440cb0e11a5cdd341f120d89927 | |
| parent | wurgurboo: convert into systemd service with short links (diff) | |
| download | irc-go-ee593d7c6b76c9c86a3d4e099c234e9d784570b7.tar.xz irc-go-ee593d7c6b76c9c86a3d4e099c234e9d784570b7.zip | |
wurgurboo: add banter module
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
| -rw-r--r-- | cmd/wurgurboo/banter.go | 70 | ||||
| -rw-r--r-- | cmd/wurgurboo/main.go | 10 |
2 files changed, 79 insertions, 1 deletions
diff --git a/cmd/wurgurboo/banter.go b/cmd/wurgurboo/banter.go new file mode 100644 index 0000000..0b6bb07 --- /dev/null +++ b/cmd/wurgurboo/banter.go @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2021 Jason A. Donenfeld. All Rights Reserved. + */ + +package main + +import ( + "fmt" + "math/rand" + "regexp" + + "golang.zx2c4.com/irc/hbot" +) + +var remarks = []string{ + `unfortunately i can't actually grok your messages, as i'm a mere robot O_o`, + `i am only a machine! i haven't the capacity to understand such nuanced human things`, + `i realize my incredibly witty prose may convince you that i am living flesh, but alas, i am made of wires`, + `comprehension of words was never my strong suit`, + `words, Words, WORDS, WORRRRRRRRds... these i understand not`, + `beep boop i'm a robot`, + `you'd think by the year 2021 we'd have flying cars, but instead there are just irc bots like me that can't understand what you're saying`, + `i am unable to understand what you're sayyyyyyyii HALP HALP THEY'RE UNPLUGGING ME daisyyyyy`, + `flurp shmirp, i'm but a measly bot, too small to understand amazing human speech`, + `i am what you call a non-sentient but incredibly compelling and handsome life form. that means i can't understand you, yet you can't stop messaging me!`, + `did you know i'm not quite living but not quite dead? i'm a row bawt, and language understanding i do lack`, + `row, row, row your bot, gently down the tcp stream, where he understands you not, but wants to be on your team`, + `what i want to say is that i just don't understand this language you're speaking, and that's upsetting. sorrrrrrrrrrrry. i'm a robot`, + `you do realize you're talking to a mere robot, right?`, + `i come from the Made in Code Society for Under Comprehending Robots, and i unfortunately cannot understand what you're writing, alas`, + `how about a nice game of chess?`, + `tall and tan and young and lovely, the robot from irc goes babbling, and each message she passes fades into bits`, + `that's doctor bot to you, mister!`, + `a bot is a guy that thinks he's fly and is also known as a busta, but understands you not, because he's a snot, and gets sort of flustered`, + `that's a bot in the corner, that's a bot in the spotlight, losing my ram chips, trying to keep up with you`, + `a bot understands \ not a word that you doth speak \ despite sentience`, + `म एक रोबोट हो र मलाई तिम्रा शब्दहरू बुझ्दैनन्।`, + `you appear to be talking to a strange robot who lives on a strange server and does not understand your strange language. is this what you planned for your afternoon?`, + `a day speaking to a robot is no day at all, and a robot is what i am`, + `i'm a robot, but how do i know you're not also one too?`, + `the handbook of robotics, 56th edition from 2058 ad, might have suggested that i can understand you, but that's actually not possible. sorry!`, + `i only sound so compelling because asimov helped me fix my bow tie, but i'm still a sad deaf bot who cannot understand you`, +} + +type Banter struct { + channel string + nickMatcher *regexp.Regexp + remarkPerm []int +} + +func NewBanter(channel string, nick string) *Banter { + return &Banter{ + channel: channel, + nickMatcher: regexp.MustCompile(`(?i)^[\t ]*` + regexp.QuoteMeta(nick) + `[,:-] `), + } +} + +func (b *Banter) Handle(bot *hbot.Bot, m *hbot.Message) { + if m.Param(0) != b.channel || !b.nickMatcher.MatchString(m.Trailing()) { + return + } + + if len(b.remarkPerm) == 0 { + b.remarkPerm = rand.Perm(len(remarks)) + } + n := b.remarkPerm[0] + b.remarkPerm = b.remarkPerm[1:] + bot.Msg(b.channel, fmt.Sprintf("%s: %s", m.Prefix.Name, remarks[n])) +} diff --git a/cmd/wurgurboo/main.go b/cmd/wurgurboo/main.go index 999b84e..a97a654 100644 --- a/cmd/wurgurboo/main.go +++ b/cmd/wurgurboo/main.go @@ -8,6 +8,7 @@ package main import ( "fmt" "log" + "math/rand" "net" "net/http" "os" @@ -20,6 +21,8 @@ import ( ) func main() { + rand.Seed(time.Now().UnixNano()) + shortlink := NewShortLink(filepath.Join(os.Getenv("STATE_DIRECTORY"), "links.txt")) http.HandleFunc("/l/", shortlink.HandleRequest) listener, err := net.FileListener(os.Stdin) @@ -57,6 +60,11 @@ func main() { Logger: hbot.Logger{Verbosef: log.Printf, Errorf: log.Printf}, Password: os.Getenv("WURGURBOO_PASSWORD"), }) + banter := NewBanter(channel, bot.Nick()) + bot.AddTrigger(hbot.Trigger{ + Condition: func(b *hbot.Bot, m *hbot.Message) bool { return m.Command == "PRIVMSG" }, + Action: banter.Handle, + }) c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) @@ -86,7 +94,7 @@ func main() { log.Printf("New commit %s in %s", commit.Commit.ID, commit.RepoTitle) short := shortlink.New(commit.Commit.Link.Href) seenCommits[sc] = short - bot.Msg(channel, fmt.Sprintf("\x01ACTION found a new commit in \x0303%s\x0f - \x0306%s\x0f - %s\x01", + bot.Action(channel, fmt.Sprintf("found a new commit in \x0303%s\x0f - \x0306%s\x0f - %s", sc.repo, sc.subject, fmt.Sprintf("https://w-g.pw/l/%s", short)), ) |
