70 lines
1.9 KiB
Python
Executable File
70 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Actions for the Racial Slurs Database table.
|
|
All data comes from http://www.rsdb.org/.
|
|
"""
|
|
import random
|
|
import sqlite3
|
|
|
|
import tools
|
|
from module import commands
|
|
|
|
|
|
def setup(bot):
|
|
con = bot.db.connect()
|
|
cur = con.cursor()
|
|
try:
|
|
cur.execute("SELECT * FROM slur").fetchone()
|
|
except OperationalError:
|
|
cur.execute("CREATE TABLE slur("
|
|
"slur TEXT,"
|
|
"race TEXT,"
|
|
"description TEXT")
|
|
con.commit()
|
|
con.close()
|
|
|
|
|
|
@commands("slur")
|
|
def slur(bot, trigger):
|
|
"""
|
|
Prints a random racial slur from the Racial Slurs Database.
|
|
|
|
-r, --race - specifies a particular race to pick on.
|
|
-s, --slur - specifies a particular slur to pick.
|
|
-l, --list - prints a list of available races.
|
|
"""
|
|
parser = tools.FulviaArgparse()
|
|
parser.add_argument("-r", "--race", type=str, nargs='+')
|
|
parser.add_argument("-s", "--slur", type=str)
|
|
parser.add_argument("-l", "--list", action="store_true")
|
|
try:
|
|
args = parser.parse_args(trigger.args[1:])
|
|
except Exception as e:
|
|
return bot.reply(type(e).__name__ + ": " + str(e))
|
|
|
|
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:
|
|
args.race = " ".join(args.race)
|
|
slur = bot.db.execute(
|
|
"SELECT * FROM `slur` WHERE `race` = ? COLLATE NOCASE " \
|
|
+ "ORDER BY RANDOM() LIMIT 1", (args.race,)).fetchone()
|
|
elif args.slur:
|
|
slur = bot.db.execute(
|
|
"SELECT * FROM `slur` WHERE `slur` LIKE ? COLLATE NOCASE " \
|
|
+ "LIMIT 1", (f"%{args.slur}%",)).fetchone()
|
|
else:
|
|
slur = bot.db.execute(
|
|
"SELECT * FROM `slur` ORDER BY RANDOM() LIMIT 1").fetchone()
|
|
if not slur:
|
|
return bot.msg("Could not find slur.")
|
|
msg = f"[\x0304SLUR\x03] \x0310Slur\x03: \x0312{slur[0]}\x03 | "
|
|
msg += f"\x0310Race\x03: \x0312{slur[1]}\x03 | "
|
|
msg += f"\x0310Description\x03: \x0312{slur[2]}\x03"
|
|
bot.msg(msg)
|