aboutsummaryrefslogtreecommitdiffstats
path: root/jeeves/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 /jeeves/respond.py
init: mostly vibed
Diffstat (limited to 'jeeves/respond.py')
-rw-r--r--jeeves/respond.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/jeeves/respond.py b/jeeves/respond.py
new file mode 100644
index 0000000..c39883b
--- /dev/null
+++ b/jeeves/respond.py
@@ -0,0 +1,52 @@
+"""
+Sopel plugin: jeeves keyword responder
+
+Responds to channel messages containing configured keywords with a random reply.
+Can be paused/resumed via !pause / !resume (admin.py).
+
+Config (in jeeves.cfg):
+ [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.config.define_section("respond", RespondSection, validate=False)
+
+
+@plugin.rule(r"(?s:.*)")
+@plugin.require_chanmsg
+def on_message(bot, trigger):
+ if bot.memory.get("jv_paused"):
+ return
+
+ try:
+ keywords = bot.config.respond.keywords or []
+ responses = bot.config.respond.responses or []
+ except Exception:
+ return
+
+ 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), trigger.sender)
+ except (UnicodeError, AttributeError):
+ pass