aboutsummaryrefslogtreecommitdiff
path: root/modules/quotes.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-26 18:27:17 +0100
committerGravatar jesopo2018-09-26 18:27:17 +0100
commit51a52e2b0e54031cce5876f54d1d48c268b5441c (patch)
treea4c0e8e86c55aa701b06297d5b5a2ceebeaab60d /modules/quotes.py
parentAlso use docstrings to check if a command has help available, allow one-string (diff)
Switch to using @Utils.hook and docstrings for event hooks
Diffstat (limited to 'modules/quotes.py')
-rw-r--r--modules/quotes.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/modules/quotes.py b/modules/quotes.py
index f8cf83c0..6cb1637a 100644
--- a/modules/quotes.py
+++ b/modules/quotes.py
@@ -1,27 +1,18 @@
import random, time
+from src import ModuleManager, Utils
-class Module(object):
- def __init__(self, bot, events, exports):
- self.bot = bot
- events.on("received.command").on("quoteadd", "qadd").hook(
- self.quote_add, min_args=1, help="Added a quote to a category",
- usage="<category> = <quote>")
- events.on("received.command").on("quoteget", "qget").hook(
- self.quote_get, min_args=1, help="Find a quote within a category",
- usage="<category> = <search>")
- events.on("received.command").on("quotedel", "qdel").hook(
- self.quote_del, min_args=1, help="Delete a quote from a category",
- usage="<category> = <quote>")
- events.on("received.command").on("quote", "q").hook(self.quote,
- help="Get a random quote from a category",
- usage="<category>", min_args=1)
-
+class Module(ModuleManager.BaseModule):
def category_and_quote(self, s):
if "=" in s:
return [part.strip() for part in s.split("=", 1)]
return None, None
+ @Utils.hook("received.command.quoteadd|qadd", min_args=1,
+ usage="<category> = <quote>")
def quote_add(self, event):
+ """
+ Add a quote to a category
+ """
category, quote = self.category_and_quote(event["args"])
if category and quote:
setting = "quotes-%s" % category
@@ -32,7 +23,12 @@ class Module(object):
else:
event["stderr"].write("Please provide a category AND quote")
+ @Utils.hook("received.command.quoteget|qget", min_args=1,
+ usage="<category> = <search>")
def quote_get(self, event):
+ """
+ Get a quote from a ccategory
+ """
category, to_find = self.category_and_quote(event["args"])
if category and to_find:
to_find = to_find.lower()
@@ -50,7 +46,12 @@ class Module(object):
event["stderr"].write("Please provide a category and a "
"part of a quote to find")
+ @Utils.hook("received.command.quotedel|qdel", min_args=1,
+ usage="<category> = <quote>")
def quote_del(self, event):
+ """
+ Delete a quote from a category
+ """
category, remove_quote = self.category_and_quote(event["args"])
remove_quote_lower = remove_quote.lower()
if category and remove_quote:
@@ -70,7 +71,11 @@ class Module(object):
event["stderr"].write("Please provide a category and a quote "
"to remove")
+ @Utils.hook("received.command.quote|q", usage="<category>", min_args=1)
def quote(self, event):
+ """
+ Get a random quote from a category
+ """
category = event["args"].strip().lower()
quotes = event["server"].get_setting("quotes-%s" % category, [])
if quotes: