2022-09-01 18:53:53 +02:00
|
|
|
from edmond.plugin import Plugin
|
|
|
|
|
|
|
|
|
|
|
|
class PlusPlugin(Plugin):
|
|
|
|
"""Plugin to store additional content from other plugins.
|
|
|
|
|
2022-09-04 15:26:52 +02:00
|
|
|
This plugin does not do much on its own, it lets other plugins register
|
|
|
|
additional content to compute on the fly when asked, e.g. the Wikipedia
|
|
|
|
plugin can store the Web page of the definition they just gave so users
|
|
|
|
wanting to know more about a definition can use the "plus" function to get
|
|
|
|
the URL to the Web page.
|
|
|
|
|
|
|
|
There can be only one handle registered at one time by target (so by
|
|
|
|
channel, user, etc). External plugins use the `add_handler` to set the
|
|
|
|
current handler for a target.
|
2022-09-01 18:53:53 +02:00
|
|
|
"""
|
|
|
|
|
2022-09-04 15:26:52 +02:00
|
|
|
REQUIRED_CONFIGS = ["commands"]
|
|
|
|
|
2022-09-01 18:53:53 +02:00
|
|
|
def __init__(self, bot):
|
|
|
|
super().__init__(bot)
|
|
|
|
self.handlers = {}
|
|
|
|
|
|
|
|
def on_pubmsg(self, event):
|
2022-09-13 18:23:39 +02:00
|
|
|
if not self.should_handle_command(event.arguments[0], no_content=True):
|
|
|
|
return False
|
|
|
|
self.process_handler(event)
|
|
|
|
return True
|
2022-09-04 15:26:52 +02:00
|
|
|
|
|
|
|
def process_handler(self, event):
|
2022-09-02 11:33:14 +02:00
|
|
|
if handler := self.handlers.pop(event.target, None):
|
2022-09-01 18:53:53 +02:00
|
|
|
handler(event)
|
|
|
|
else:
|
|
|
|
self.signal_failure(event.target)
|
|
|
|
|
|
|
|
def add_handler(self, target: str, handler):
|
|
|
|
self.handlers[target] = handler
|