From b26c68ed671d8e4866ca9f262520f39f5590db8d Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 12 Oct 2020 19:26:06 +0200 Subject: [PATCH] notes: add command to deliver messages now --- config.json.example | 2 +- edmond/plugins/notes.py | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/config.json.example b/config.json.example index 6b7abe5..252cf5d 100644 --- a/config.json.example +++ b/config.json.example @@ -39,7 +39,7 @@ } }, "notes": { - "commands": ["note down"], + "commands": ["note down", "notes"], "content_regex": "for (?P\\S+) (?P.+)", "confirmation": "Ok.", "deliver_format": "{dest}, {sender} tells you: {message}", diff --git a/edmond/plugins/notes.py b/edmond/plugins/notes.py index 7b33522..f6fa279 100644 --- a/edmond/plugins/notes.py +++ b/edmond/plugins/notes.py @@ -24,17 +24,7 @@ class NotesPlugin(Plugin): nick = event.source.nick if nick == self.bot.nick: return - notes = self.get_storage_value("notes", []) - notes = list(filter(lambda n: n["dest"] == nick, notes)) - self.bot.log_d(f"Delivering {len(notes)} notes to {nick}.") - for note in notes: - message = self.config["deliver_format"].format( - sender=note["sender"], - dest=nick, - message=note["message"], - ) - self.bot.say(event.target, message) - self.remove_storage_list_value("notes", note) + self.deliver_notes(event.target, nick) def on_pubmsg(self, event): if not self.should_handle_command(event.arguments[0], no_content=True): @@ -66,6 +56,27 @@ class NotesPlugin(Plugin): } self.append_storage_list_value("notes", note) self.bot.say(event.target, self.config["confirmation"]) + return True + + # "deliver notes for me" command. + command1 = self.config["commands"][1] + if self.command.ident == command1: + self.deliver_notes(event.target, event.source.nick) + return True + + def deliver_notes(self, target, nick): + """Deliver all notes for this user in the target channel/user.""" + notes = self.get_storage_value("notes", []) + notes = list(filter(lambda n: n["dest"] == nick, notes)) + self.bot.log_d(f"Delivering {len(notes)} notes to {nick}.") + for note in notes: + message = self.config["deliver_format"].format( + sender=note["sender"], + dest=nick, + message=note["message"], + ) + self.bot.say(target, message) + self.remove_storage_list_value("notes", note) def count_user_notes(self, nick): """Count the number of undelivered notes this user has."""