added --list to .slur

This commit is contained in:
iou1name 2019-03-14 07:30:17 -04:00
parent a2554f3c2f
commit f7cbd18f6e

View File

@ -31,13 +31,23 @@ def slur(bot, trigger):
-r, --race - specifies a particular race to pick on. -r, --race - specifies a particular race to pick on.
-s, --slur - specifies a particular slur to pick. -s, --slur - specifies a particular slur to pick.
-l, --list - prints a list of available races.
""" """
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-r", "--race", type=str) parser.add_argument("-r", "--race", type=str, nargs='+')
parser.add_argument("-s", "--slur", type=str) parser.add_argument("-s", "--slur", type=str)
parser.add_argument("-l", "--list", action="store_true")
args = parser.parse_args(trigger.group[3:]) args = parser.parse_args(trigger.group[3:])
if args.list:
races = bot.db.execute("SELECT DISTINCT race FROM slur").fetchall()
races = [race[0] for race in races]
races.sort()
bot.msg(", ".join(races))
return
if args.race: if args.race:
args.race = " ".join(args.race)
slur = bot.db.execute( slur = bot.db.execute(
"SELECT * FROM `slur` WHERE `race` = ? COLLATE NOCASE " \ "SELECT * FROM `slur` WHERE `race` = ? COLLATE NOCASE " \
+ "ORDER BY RANDOM() LIMIT 1", (args.race,)).fetchone() + "ORDER BY RANDOM() LIMIT 1", (args.race,)).fetchone()