diff options
| author | 2016-05-01 17:47:35 +0100 | |
|---|---|---|
| committer | 2016-05-01 17:47:35 +0100 | |
| commit | 3a7481315d95dfc5559219b01ec356e9feeb7b44 (patch) | |
| tree | dbc7649443f02008b1a372e63c39010b4aa87f32 /modules | |
| parent | added quotes.py. (diff) | |
added a command to quotes.py to get a random quote from a category.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/quotes.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/quotes.py b/modules/quotes.py index 351ae395..58f4075e 100644 --- a/modules/quotes.py +++ b/modules/quotes.py @@ -1,4 +1,4 @@ -import time +import random, time class Module(object): def __init__(self, bot): @@ -15,6 +15,10 @@ class Module(object): "qdel").hook(self.quote_del, min_args=1, help="Delete a quote from a category", usage="<category> = <quote>") + bot.events.on("received").on("command").on("quote", + "q").hook(self.quote, min_args=1, + help="Get a random quote from a category", + usage="<category>") def category_and_quote(self, s): if "=" in s: @@ -69,3 +73,13 @@ class Module(object): else: event["stderr"].write("Please provide a category and a quote " "to remove") + + def quote(self, event): + category = event["args"].strip().lower() + quotes = event["server"].get_setting("quotes-%s" % category, []) + if quotes: + index = random.randint(0, len(quotes)-1) + nickname, time_added, quote = quotes[index] + event["stdout"].write("%s: %s" % (category, quote)) + else: + event["stderr"].write("There are no quotes for this category") |
