43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import re
|
|
|
|
from edmond.plugin import Plugin
|
|
|
|
|
|
class NotesPlugin(Plugin):
|
|
|
|
REQUIRED_CONFIGS = ["commands", "content_regex"]
|
|
|
|
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_pubmsg(self, event):
|
|
if not self.should_handle_command(event.arguments[0], no_content=True):
|
|
return False
|
|
|
|
# "note down" command.
|
|
command0 = self.config["commands"][0]
|
|
if self.command.ident.startswith(command0):
|
|
content = self.command.ident[len(command0):].strip()
|
|
match = self.content_re.match(content)
|
|
if not match:
|
|
return False
|
|
groups = match.groupdict()
|
|
if any(k not in groups for k in ("target", "note")):
|
|
return False
|
|
target = groups["target"]
|
|
message = groups["note"]
|
|
self.bot.log_d(f"Noting for {target}: {message}")
|
|
note = {
|
|
"sender": event.source.nick,
|
|
"dest": target,
|
|
"message": message
|
|
}
|
|
self.append_storage_list_value("notes", note)
|