From a101282b62e112781258a5cea19bf473c3ee980d Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 17 Aug 2017 00:26:58 -0700 Subject: [PATCH] Moving lewds into its own module and alphabatizing all the if statements in dragon-bot.py --- Dockerfile-test-env | 2 +- app/dragon-bot.py | 145 ++++++-------------------------------------- app/help_methods.py | 2 - app/lewds.py | 103 +++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 128 deletions(-) create mode 100644 app/lewds.py diff --git a/Dockerfile-test-env b/Dockerfile-test-env index 2ed533b9..4613d3aa 100644 --- a/Dockerfile-test-env +++ b/Dockerfile-test-env @@ -5,7 +5,7 @@ RUN apk update && apk add --no-cache vim docker RUN pip install requests discord.py docker pybooru pylint ADD app /app -RUN echo "\nTesting your python code for errors\n" && \ +RUN printf "\n\nTesting your python code for errors\n\n" && \ pylint -E /app/*.py RUN printf "\n#########################\nRun dragon bot by typing \npython dragon-bot.py\n#########################\n\n" diff --git a/app/dragon-bot.py b/app/dragon-bot.py index da68e14a..bab230a0 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -10,6 +10,7 @@ import define_word import help_methods import discord import docker +import lewds import wallpaper from pybooru import Danbooru @@ -46,93 +47,6 @@ async def on_message(message): is the same as the person who initiated the command """ return m.author == message.author - def get_from_danbooru(): - """ - get_from_danbooru() - - returns a URL to an image on danbooru that matches a random tag - defined in the tag_list list - """ - booru = Danbooru('danbooru') - tag_list = [ - '1girl', - '2girls', - 'ass_visible_through_thighs', - 'bare_legs' - 'bikini', - 'black_bikini', - 'black_panties', - 'blue_eyes', - 'bra_pull', - 'bra', - 'breasts', - 'cameltoe', - 'clevage', - 'condom_in_mouth', - 'condom', - 'from_below', - 'gloves', - 'highleg_bikini', - 'highleg', - 'highres', - 'horns', - 'large_breasts', - 'leash', - 'medium_breasts' - 'miniskirt', - 'nier_automata', - 'nier', - 'nipples', - 'partially_visible_vulva', - 'pencil_skirt', - 'pussy_juice', - 'pussy', - 'skirt', - 'small_breasts', - 'thong_bikini', - 'topless', - 'wet_clothes', - 'wet_panties', - 'wet', - ] - - tag = random.choice(tag_list) - return "https://danbooru.donmai.us{}".format( - random.choice( - booru.post_list( - limit=500, - tags=tag, - random=True, - ) - )['large_file_url']) - - def get_from_reddit(): - """ - get_from_reddit() - - returns a URL to an image on reddit from a random board in the boards list - as long as it is hosted on one of the domains in the domains list - """ - boards = [ - '2Booty', - 'bakunyuu_hentai', - 'ecchi', - 'hentai', - 'rule34', - 'WesternHentai', - ] - domains = [ - 'my.mixtape.moe', - 'i.imgur.com', - 'i.redd.it', - ] - response = requests.get( - "https://reddit.com/r/{}.json?limit=500".format(random.choice(boards)), - headers = {'User-agent':'discord dragon-bot'} - ).json()['data']['children'] - - image_urls = list(filter(lambda x: x['data']['domain'] in domains, response)) - return random.choice(image_urls)['data']['url'].replace('http://', 'https://') ##### Looks like discord supports mentioning the bot. #### Need to think of something to do here @@ -145,23 +59,37 @@ async def on_message(message): eight_ball.check_8ball(message.content) ) + if message.content.startswith('!cleanup') and message.author.id == '144986109804412928': + def is_bot(m): + return m.author == client.user + await client.purge_from(message.channel, limit=100, check=is_bot) + + if message.content.startswith('!decide'): + await client.send_message( + message.channel, + "{} {}".format( + message.author.mention, + decide.decide(message.content) + ) + ) + if message.content.startswith('!define'): await client.send_message( message.channel, define_word.get_definition(message.content) ) + if message.content.startswith('!excuse'): + await client.send_message(message.channel, excuse.get_excuse()) + if message.content.startswith('!help'): await client.send_message( message.channel, help_methods.parse_message(message.content) ) - if 'autis' in message.content or message.content.startswith('!triggered'): - await client.send_message(message.channel, 'https://i.imgur.com/g6yOJjp.gif') - - if message.content.startswith('!excuse'): - await client.send_message(message.channel, excuse.get_excuse()) + if message.content.startswith('!lewd'): + await client.send_message(message.channel, lewds.get_lewd(channel_name=message.channel.name)) if message.content.startswith('!purge'): num = 20 @@ -173,23 +101,6 @@ async def on_message(message): await client.send_message(message.channel, "You need to give me a number, you entered {}".format(message.content.split()[1])) return await client.purge_from(message.channel, limit=num, check=is_me) - # await client.send_message(message.channel, 'Deleted {} message(s)'.format(len(deleted))) - - if message.content.startswith('!decide'): - await client.send_message( - message.channel, - "{} {}".format( - message.author.mention, - decide.decide(message.content) - ) - ) - - - if message.content.startswith('!cleanup') and message.author.id == '144986109804412928': - def is_bot(m): - return m.author == client.user - await client.purge_from(message.channel, limit=100, check=is_bot) - # await client.send_message(message.channel, 'Deleted {} message(s)'.format(len(deleted))) if message.content.startswith('!wallpaper'): await client.send_message( @@ -197,22 +108,6 @@ async def on_message(message): wallpaper.get_wall(message.content) ) - ################################### - ###### +-------------------+ ###### - ###### | | ###### - ###### | Lewd Functions | ###### - ###### | | ###### - ###### +-------------------+ ###### - ################################### - if message.content.startswith('!lewd'): - if 'nsfw' in message.channel.name: - if random.randint(0, 100) % 2 == 0: - await client.send_message(message.channel, "Heres a random image from reddit\n{}".format(get_from_reddit())) - else: - await client.send_message(message.channel, "Heres a random image from danbooru\n{}".format(get_from_danbooru())) - else: - await client.send_message(message.channel, 'You can only use this command in NSFW channels') - ################################### ###### +-------------------+ ###### ###### | | ###### diff --git a/app/help_methods.py b/app/help_methods.py index ce4ee995..43d4403f 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -40,8 +40,6 @@ def get_help_message(method): 'Deletes the last 20 messages you sent from the channel you', 'typed purge in, unless otherwise specified. eg. !purge 8' ], - 'triggered': [ - 'REEEEEEEEEEEEEEEEEE'], 'wallpaper': [ 'Returns the URL for a 4k wallpaper. You can enter', 'a search term as well, for example, !wallpaper, or', diff --git a/app/lewds.py b/app/lewds.py new file mode 100644 index 00000000..aa523818 --- /dev/null +++ b/app/lewds.py @@ -0,0 +1,103 @@ +import random +import requests + +import help_methods +from pybooru import Danbooru + + +def get_from_danbooru(): + """ + get_from_danbooru() + + returns a URL to an image on danbooru that matches a random tag + defined in the tag_list list + """ + booru = Danbooru('danbooru') + tag_list = [ + '1girl', + '2girls', + 'ass_visible_through_thighs', + 'bare_legs' + 'bikini', + 'black_bikini', + 'black_panties', + 'blue_eyes', + 'bra_pull', + 'bra', + 'breasts', + 'cameltoe', + 'clevage', + 'condom_in_mouth', + 'condom', + 'from_below', + 'gloves', + 'highleg_bikini', + 'highleg', + 'highres', + 'horns', + 'large_breasts', + 'leash', + 'medium_breasts' + 'miniskirt', + 'nier_automata', + 'nier', + 'nipples', + 'partially_visible_vulva', + 'pencil_skirt', + 'pussy_juice', + 'pussy', + 'skirt', + 'small_breasts', + 'thong_bikini', + 'topless', + 'wet_clothes', + 'wet_panties', + 'wet', + ] + + tag = random.choice(tag_list) + return "https://danbooru.donmai.us{}".format( + random.choice( + booru.post_list( + limit=500, + tags=tag, + random=True, + ) + )['large_file_url']) + + +def get_from_reddit(): + """ + get_from_reddit() + + returns a URL to an image on reddit from a random board in the boards list + as long as it is hosted on one of the domains in the domains list + """ + boards = [ + '2Booty', + 'bakunyuu_hentai', + 'ecchi', + 'hentai', + 'rule34', + 'WesternHentai', + ] + domains = [ + 'my.mixtape.moe', + 'i.imgur.com', + 'imgur.com', + 'i.redd.it', + ] + response = requests.get( + "https://reddit.com/r/{}.json?limit=500".format(random.choice(boards)), + headers = {'User-agent':'discord dragon-bot'} + ).json()['data']['children'] + + image_urls = list(filter(lambda x: x['data']['domain'] in domains, response)) + return random.choice(image_urls)['data']['url'].replace('http://', 'https://') + + +def get_lewd(channel_name): + if 'nsfw' in channel_name: + random.choice([get_from_reddit, get_from_danbooru])() + else: + return 'You can only use this command in NSFW channels'