notes: add command to deliver messages now

master
dece 4 years ago
parent 263e9fd615
commit b26c68ed67

@ -39,7 +39,7 @@
}
},
"notes": {
"commands": ["note down"],
"commands": ["note down", "notes"],
"content_regex": "for (?P<target>\\S+) (?P<note>.+)",
"confirmation": "Ok.",
"deliver_format": "{dest}, {sender} tells you: {message}",

@ -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."""

Loading…
Cancel
Save