plus: add shortcut
This commit is contained in:
parent
0f31807909
commit
e8a18c6a90
|
@ -151,7 +151,8 @@
|
||||||
"commands": ["plus"],
|
"commands": ["plus"],
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"plus": "more"
|
"plus": "more"
|
||||||
}
|
},
|
||||||
|
"shortcut": "+"
|
||||||
},
|
},
|
||||||
"randomchoice": {
|
"randomchoice": {
|
||||||
"commands": ["choose"],
|
"commands": ["choose"],
|
||||||
|
|
|
@ -4,29 +4,38 @@ from edmond.plugin import Plugin
|
||||||
class PlusPlugin(Plugin):
|
class PlusPlugin(Plugin):
|
||||||
"""Plugin to store additional content from other plugins.
|
"""Plugin to store additional content from other plugins.
|
||||||
|
|
||||||
This plugin does not do much on its own, it lets other plugins register additional
|
This plugin does not do much on its own, it lets other plugins register
|
||||||
content to compute on the fly when asked, e.g. the Wikipedia plugin can store the
|
additional content to compute on the fly when asked, e.g. the Wikipedia
|
||||||
Web page of the definition they just gave so users wanting to know more about a
|
plugin can store the Web page of the definition they just gave so users
|
||||||
definition can use the "plus" function to get the URL to the Web page.
|
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,
|
There can be only one handle registered at one time by target (so by
|
||||||
etc). External plugins use the `add_handler` to set the current handler for a
|
channel, user, etc). External plugins use the `add_handler` to set the
|
||||||
target.
|
current handler for a target.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
REQUIRED_CONFIGS = ["commands"]
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
self.handlers = {}
|
self.handlers = {}
|
||||||
|
self.shortcut = self.config.get("shortcut")
|
||||||
|
|
||||||
def on_pubmsg(self, event):
|
def on_pubmsg(self, event):
|
||||||
if not self.should_handle_command(event.arguments[0], no_content=True):
|
if (
|
||||||
|
(self.shortcut and event.arguments[0].strip() == self.shortcut)
|
||||||
|
or self.should_handle_command(event.arguments[0], no_content=True)
|
||||||
|
):
|
||||||
|
self.process_handler(event)
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def process_handler(self, event):
|
||||||
if handler := self.handlers.pop(event.target, None):
|
if handler := self.handlers.pop(event.target, None):
|
||||||
handler(event)
|
handler(event)
|
||||||
else:
|
else:
|
||||||
self.signal_failure(event.target)
|
self.signal_failure(event.target)
|
||||||
return True
|
|
||||||
|
|
||||||
def add_handler(self, target: str, handler):
|
def add_handler(self, target: str, handler):
|
||||||
self.handlers[target] = handler
|
self.handlers[target] = handler
|
||||||
|
|
Loading…
Reference in a new issue