|
|
|
@ -5,7 +5,10 @@ from edmond.plugin import Plugin
|
|
|
|
|
|
|
|
|
|
class NotesPlugin(Plugin):
|
|
|
|
|
|
|
|
|
|
REQUIRED_CONFIGS = ["commands", "content_regex", "deliver_format"]
|
|
|
|
|
REQUIRED_CONFIGS = [
|
|
|
|
|
"commands", "content_regex", "confirmation", "deliver_format", "limit",
|
|
|
|
|
"too_many_notes"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
super().__init__(bot)
|
|
|
|
@ -48,6 +51,12 @@ class NotesPlugin(Plugin):
|
|
|
|
|
if any(k not in groups for k in ("target", "note")):
|
|
|
|
|
return False
|
|
|
|
|
target = groups["target"]
|
|
|
|
|
|
|
|
|
|
# Check we did not reach our note limits.
|
|
|
|
|
if self.count_user_notes(target) >= self.config["limit"]:
|
|
|
|
|
self.bot.say(event.target, self.config["too_many_notes"])
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
message = groups["note"]
|
|
|
|
|
self.bot.log_d(f"Noting for {target}: {message}")
|
|
|
|
|
note = {
|
|
|
|
@ -57,3 +66,8 @@ class NotesPlugin(Plugin):
|
|
|
|
|
}
|
|
|
|
|
self.append_storage_list_value("notes", note)
|
|
|
|
|
self.bot.say(event.target, self.config["confirmation"])
|
|
|
|
|
|
|
|
|
|
def count_user_notes(self, nick):
|
|
|
|
|
"""Count the number of undelivered notes this user has."""
|
|
|
|
|
notes = self.get_storage_value("notes", [])
|
|
|
|
|
return sum(note["dest"] == nick for note in notes)
|
|
|
|
|