added a command to quotes.py to get a random quote from a category.
This commit is contained in:
parent
c1f8835653
commit
3a7481315d
1 changed files with 15 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
import time
|
import random, time
|
||||||
|
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -15,6 +15,10 @@ class Module(object):
|
||||||
"qdel").hook(self.quote_del, min_args=1,
|
"qdel").hook(self.quote_del, min_args=1,
|
||||||
help="Delete a quote from a category",
|
help="Delete a quote from a category",
|
||||||
usage="<category> = <quote>")
|
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):
|
def category_and_quote(self, s):
|
||||||
if "=" in s:
|
if "=" in s:
|
||||||
|
@ -69,3 +73,13 @@ class Module(object):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Please provide a category and a quote "
|
event["stderr"].write("Please provide a category and a quote "
|
||||||
"to remove")
|
"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")
|
||||||
|
|
Loading…
Reference in a new issue