aboutsummaryrefslogtreecommitdiffstats
path: root/herald/respond.py
diff options
context:
space:
mode:
authorAhmed <git@gumx.cc>2026-06-14 01:46:29 +0300
committerAhmed <git@gumx.cc>2026-06-14 01:46:29 +0300
commit5a8d568931d9b23ce0df1265d05259a7012081c9 (patch)
tree4ea19b8bb1763a38246f342f172c285f6579e09b /herald/respond.py
init: mostly vibed
Diffstat (limited to 'herald/respond.py')
-rw-r--r--herald/respond.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/herald/respond.py b/herald/respond.py
new file mode 100644
index 0000000..066ea81
--- /dev/null
+++ b/herald/respond.py
@@ -0,0 +1,49 @@
+"""
+Sopel plugin: keyword responder
+
+Responds to any channel message containing one of the configured keywords
+with a randomly chosen response line. Matching is case-insensitive.
+Can be paused/resumed by the owner via !pause / !resume.
+
+ [respond]
+ keywords =
+ word1
+ word2
+ responses =
+ reply one
+ reply two
+"""
+
+import random
+
+from sopel import plugin
+from sopel.config.types import ListAttribute, StaticSection
+
+
+class RespondSection(StaticSection):
+ keywords = ListAttribute("keywords")
+ responses = ListAttribute("responses")
+
+
+def setup(bot):
+ bot.settings.define_section("respond", RespondSection)
+
+
+@plugin.rule(r"(?s:.*)")
+@plugin.require_chanmsg
+def respond(bot, trigger):
+ if bot.memory.get("herald_paused"):
+ return
+
+ keywords = bot.settings.respond.keywords
+ responses = bot.settings.respond.responses
+
+ if not keywords or not responses:
+ return
+
+ try:
+ msg = trigger.group(0).casefold()
+ if any(kw.casefold() in msg for kw in keywords):
+ bot.say(random.choice(responses))
+ except (UnicodeError, AttributeError):
+ pass