From 35e2cd0b10fe6a7ef8fb463905c38737ffca833e Mon Sep 17 00:00:00 2001 From: luke Date: Mon, 19 Mar 2018 13:54:54 -0700 Subject: [PATCH] Fixing the lewd error message if someone tries to use it in a not lewd channel --- app/dragon-bot.py | 18 ++++++++++++------ app/lewds.py | 48 ++++++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 3c10064e..2f250930 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -226,13 +226,19 @@ async def on_message(message): ) if message.content.startswith('!lewd'): - await client.send_message( - message.channel, - embed=generate_embed( - embed_url=lewds.get_lewd(channel_name=message.channel.name), - embed_title="{} is being lewd".format(message.author.name) + if 'nsfw' in message.channel.name: + await client.send_message( + message.channel, + embed=generate_embed( + embed_url=lewds.get_lewd(channel_name=message.channel.name), + embed_title="{} is being lewd".format(message.author.name) + ) + ) + else: + await client.send_message( + message.channel, + 'You can only use this command in NSFW channels' ) - ) if message.content.startswith('!weather'): await client.send_message( diff --git a/app/lewds.py b/app/lewds.py index 92060bb4..e83fd117 100644 --- a/app/lewds.py +++ b/app/lewds.py @@ -41,25 +41,31 @@ def get_from_danbooru(boards, nsfw=True): return get_from_danbooru(boards) -def get_lewd(channel_name): - if 'nsfw' in channel_name: - boards = [ - '2Booty', - 'ahegao', - 'bakunyuu_hentai', - 'ecchi', - 'hentai', - 'rule34', - 'WesternHentai', - 'doujinshi', - 'hentai_gif', - 'muchihentai', - 'chiisaihentai', - 'dekaihentai', - 'WaifusGonewild', - 'thighdeology' - ] +def get_lewd(): + """ + get_lewd() - # This is really bad practice but pass boards to get_from_reddit AND danbooru so it doesnt error - return random.choice([get_from_reddit.get_image, get_from_danbooru])(boards=boards, nsfw=True) - return 'You can only use this command in NSFW channels' + Chooses between getting from reddit or danbooru + If reddit is chosen, picks a random subreddit from the list of boards and + grabs a random image using the get_from_reddit() method + """ + # List of subreddits that have the lewds we seek + boards = [ + '2Booty', + 'ahegao', + 'bakunyuu_hentai', + 'ecchi', + 'hentai', + 'rule34', + 'WesternHentai', + 'doujinshi', + 'hentai_gif', + 'muchihentai', + 'chiisaihentai', + 'dekaihentai', + 'WaifusGonewild', + 'thighdeology' + ] + + # This is really bad practice but pass boards to get_from_reddit AND danbooru so it doesnt error + return random.choice([get_from_reddit.get_image, get_from_danbooru])(boards=boards, nsfw=True)