capture_list: add plugin
This commit is contained in:
parent
7f5ed39722
commit
93d59ff30b
|
@ -28,6 +28,11 @@
|
||||||
"capture_sentence": "Catch!",
|
"capture_sentence": "Catch!",
|
||||||
"captured_sentence": "Well done {winner}, you got that {thing}!"
|
"captured_sentence": "Well done {winner}, you got that {thing}!"
|
||||||
},
|
},
|
||||||
|
"capturelist": {
|
||||||
|
"commands": ["collection"],
|
||||||
|
"reply": "{target} captured {num} things : {things}",
|
||||||
|
"empty_reply": "{target} did not capture anything yet!"
|
||||||
|
},
|
||||||
"common": {
|
"common": {
|
||||||
"command_suffix": "please",
|
"command_suffix": "please",
|
||||||
"handling_conditions": {
|
"handling_conditions": {
|
||||||
|
|
|
@ -95,9 +95,15 @@ class Plugin:
|
||||||
"""Set a value in the plugin runtime dict."""
|
"""Set a value in the plugin runtime dict."""
|
||||||
self.bot.values[self.name][key] = value
|
self.bot.values[self.name][key] = value
|
||||||
|
|
||||||
def get_storage_value(self, key, default=None):
|
def get_storage_value(self, key, default=None, ns=None):
|
||||||
"""Get a value from the plugin persistent storage."""
|
"""Get a value from the plugin persistent storage.
|
||||||
return self.bot.storage.get(self.name, {}).get(key, default)
|
|
||||||
|
This will get the value from the plugin namespace, but it is possible to
|
||||||
|
get storage values from other plugins using their name as `ns`.
|
||||||
|
"""
|
||||||
|
if ns is None:
|
||||||
|
ns = self.name
|
||||||
|
return self.bot.storage.get(ns, {}).get(key, default)
|
||||||
|
|
||||||
def set_storage_value(self, key, value):
|
def set_storage_value(self, key, value):
|
||||||
"""Set a value in the plugin persistent storage."""
|
"""Set a value in the plugin persistent storage."""
|
||||||
|
|
36
edmond/plugins/capture_list.py
Normal file
36
edmond/plugins/capture_list.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
collection = collections.get(collec_target, [])
|
||||||
|
if collection:
|
||||||
|
reply = self.config["reply"].format(
|
||||||
|
target=collec_target,
|
||||||
|
num=len(collection),
|
||||||
|
things="".join(collection)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
reply = self.config["empty_reply"].format(target=collec_target)
|
||||||
|
self.bot.say(event.target, reply)
|
||||||
|
return True
|
|
@ -28,7 +28,7 @@ class YoutubeParserPlugin(Plugin):
|
||||||
|
|
||||||
def on_welcome(self, _):
|
def on_welcome(self, _):
|
||||||
if not (self.youtube_plugin and self.youtube_plugin.is_ready):
|
if not (self.youtube_plugin and self.youtube_plugin.is_ready):
|
||||||
self.log_w("Youtube plugin is not available.")
|
self.bot.log_w("Youtube plugin is not available.")
|
||||||
self.is_ready = False
|
self.is_ready = False
|
||||||
|
|
||||||
def on_pubmsg(self, event):
|
def on_pubmsg(self, event):
|
||||||
|
|
Loading…
Reference in a new issue