Compare commits
4 commits
bec9ff4d76
...
dd3ebcaa35
Author | SHA1 | Date | |
---|---|---|---|
dece | dd3ebcaa35 | ||
dece | f9dca68fb0 | ||
dece | 3a85e5a23c | ||
dece | 6841b01e8d |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ resources/*
|
|||
!resources/.gitkeep
|
||||
venv/
|
||||
.vim/
|
||||
__pycache__/
|
||||
|
|
|
@ -46,6 +46,11 @@
|
|||
"reply": "{target} captured {num} things : {things}",
|
||||
"empty_reply": "{target} did not capture anything yet!"
|
||||
},
|
||||
"capturegive": {
|
||||
"commands": ["give"],
|
||||
"content_regex": "my (?P<thing>\\S+) to (?P<person>\\S+)",
|
||||
"no_such_thing_reply": "You don't have such {thing}."
|
||||
},
|
||||
"common": {
|
||||
"command_suffix": "please",
|
||||
"handling_conditions": {
|
||||
|
|
|
@ -179,6 +179,7 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
|||
def handle_sigterm(self, *args):
|
||||
"""Handle SIGTERM (keyboard interrupt, systemd stop, etc)."""
|
||||
self.cleanup()
|
||||
exit("Exiting after received SIGTERM.")
|
||||
|
||||
def cleanup(self):
|
||||
"""Save the storage file and close the connection. Run only once."""
|
||||
|
|
|
@ -105,12 +105,13 @@ class Plugin:
|
|||
ns = self.name
|
||||
return self.bot.storage.get(ns, {}).get(key, default)
|
||||
|
||||
def set_storage_value(self, key, value):
|
||||
def set_storage_value(self, key, value, ns=None):
|
||||
"""Set a value in the plugin persistent storage."""
|
||||
if self.name not in self.bot.storage:
|
||||
self.bot.storage[self.name] = {key: value}
|
||||
name = ns or self.name
|
||||
if name not in self.bot.storage:
|
||||
self.bot.storage[name] = {key: value}
|
||||
else:
|
||||
self.bot.storage[self.name][key] = value
|
||||
self.bot.storage[name][key] = value
|
||||
|
||||
def append_storage_list_value(self, key, value):
|
||||
"""Append a value to a list in the plugin persistent storage."""
|
||||
|
|
69
edmond/plugins/capture_give.py
Normal file
69
edmond/plugins/capture_give.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
import re
|
||||
import time
|
||||
|
||||
from edmond.plugin import Plugin
|
||||
|
||||
|
||||
class CaptureGivePlugin(Plugin):
|
||||
|
||||
REQUIRED_CONFIGS = ["commands", "content_regex", "no_such_thing_reply"]
|
||||
|
||||
def __init__(self, bot):
|
||||
super().__init__(bot)
|
||||
self._content_re = None
|
||||
|
||||
@property
|
||||
def content_re(self):
|
||||
if self._content_re is None:
|
||||
self._content_re = re.compile(self.config["content_regex"])
|
||||
return self._content_re
|
||||
|
||||
def on_welcome(self, _):
|
||||
if not self.bot.get_plugin("capture"):
|
||||
self.bot.log_w("Capture plugin is not available.")
|
||||
self.is_ready = False
|
||||
|
||||
def on_pubmsg(self, event):
|
||||
if not self.should_handle_command(event.arguments[0]):
|
||||
return False
|
||||
|
||||
# "give" command.
|
||||
if self.command.ident == self.config["commands"][0]:
|
||||
content = self.command.raw[len(self.command.match):].strip()
|
||||
match = self.content_re.match(content)
|
||||
if not match:
|
||||
return False
|
||||
groups = match.groupdict()
|
||||
if any(k not in groups for k in ("thing", "person")):
|
||||
return False
|
||||
thing = groups["thing"]
|
||||
person = groups["person"]
|
||||
|
||||
# Check the sender has the thing they attempt to give.
|
||||
collections = self.get_storage_value(
|
||||
"collections",
|
||||
default={},
|
||||
ns="capture"
|
||||
)
|
||||
source = event.source.nick
|
||||
source_collection = collections.get(source, [])
|
||||
if thing not in source_collection:
|
||||
reply = self.config["no_such_thing_reply"].format(thing=thing)
|
||||
self.bot.say(event.target, reply)
|
||||
return True
|
||||
|
||||
source_collection.remove(thing)
|
||||
collections[source] = source_collection
|
||||
|
||||
target_collection = collections.get(person, [])
|
||||
target_collection.append(thing)
|
||||
collections[person] = target_collection
|
||||
|
||||
self.set_storage_value("collections", collections, ns="capture")
|
||||
|
||||
dance_text_1 = f"[{source}] {thing}<(OvO<) [{person}]"
|
||||
self.bot.say(event.target, dance_text_1)
|
||||
time.sleep(1)
|
||||
dance_text_2 = f"[{source}] (>OvO)>{thing} [{person}]"
|
||||
self.bot.say(event.target, dance_text_2)
|
||||
return True
|
|
@ -33,6 +33,8 @@ class YoutubeParserPlugin(Plugin):
|
|||
self.is_ready = False
|
||||
|
||||
def on_pubmsg(self, event):
|
||||
if not self.respects_handling_conditions():
|
||||
return False
|
||||
words = event.arguments[0].split()
|
||||
for word in words:
|
||||
match = self.VIDEO_URL_RE.match(word)
|
||||
|
|
Loading…
Reference in a new issue