parent
9ab1812938
commit
70cdcad604
@ -1,3 +1,4 @@
|
||||
config.json
|
||||
storage.json
|
||||
resources/*
|
||||
!resources/.gitkeep
|
||||
|
@ -0,0 +1,42 @@
|
||||
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)
|
Loading…
Reference in new issue