Edm0nd/edmond/plugins/capture_list.py

35 lines
1 KiB
Python
Raw Normal View History

2021-06-06 19:02:19 +02:00
from edmond.plugin import Plugin
class CaptureListPlugin(Plugin):
REQUIRED_CONFIGS = ["commands", "reply", "empty_reply"]
def __init__(self, bot):
super().__init__(bot)
def on_welcome(self, _):
if not self.bot.get_plugin("capture"):
self.bot.log_w("Capture plugin is not available.")
self.is_ready = False
def on_pubmsg(self, event):
if not self.should_handle_command(event.arguments[0]):
return False
collec_target = self.command.content or event.source.nick
collections = self.get_storage_value(
"collections", default={}, ns="capture"
2021-06-06 19:02:19 +02:00
)
collection = collections.get(collec_target, [])
if collection:
reply = self.config["reply"].format(
target=collec_target,
num=len(collection),
things="".join(collection),
2021-06-06 19:02:19 +02:00
)
else:
reply = self.config["empty_reply"].format(target=collec_target)
self.bot.say(event.target, reply)
return True