Merged in wallpaper_module (pull request #27)

wallpaper_module isolation

Approved-by: Luke Robles <lukelrobles@gmail.com>
This commit is contained in:
Kyler E Juresic 2017-08-17 06:12:19 +00:00
commit b29da1b857
3 changed files with 32 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import define_word
import help_methods import help_methods
import discord import discord
import docker import docker
import wallpaper
from pybooru import Danbooru from pybooru import Danbooru
# Client object # Client object
@ -191,17 +192,10 @@ async def on_message(message):
# await client.send_message(message.channel, 'Deleted {} message(s)'.format(len(deleted))) # await client.send_message(message.channel, 'Deleted {} message(s)'.format(len(deleted)))
if message.content.startswith('!wallpaper'): if message.content.startswith('!wallpaper'):
url = 'https://source.unsplash.com/3840x2160/' await client.send_message(
if len(message.content.split()) > 1: message.channel,
keyword = message.content.split()[1] wallpaper.get_wall(message.content)
url = "?".join((url, keyword)) )
if 'waifu' in keyword:
url = 'https://media0.giphy.com/media/C79RKZ7nOcK8U/giphy.gif'
results = requests.get(url).url
await client.send_message(message.channel, results)
################################### ###################################
###### +-------------------+ ###### ###### +-------------------+ ######

View File

@ -45,7 +45,7 @@ def get_help_message(method):
'wallpaper': [ 'wallpaper': [
'Returns the URL for a 4k wallpaper. You can enter', 'Returns the URL for a 4k wallpaper. You can enter',
'a search term as well, for example, !wallpaper, or', 'a search term as well, for example, !wallpaper, or',
', !wallpaper flowers' ', !wallpaper flowers. Supports multiple tags.'
] ]
} }

26
app/wallpaper.py Normal file
View File

@ -0,0 +1,26 @@
import requests
def get_wall(message):
unsplash_url = "https://source.unsplash.com/3840x2160/?"
if len(message.split()) > 2:
search_terms = message.split()[1:]
# Turn search_terms into strings separated by commas
joined_terms = ','.join(search_terms)
# Add those comma separated strings onto the end of the URL variable
url = unsplash_url + joined_terms
elif len(message.split()) > 1:
term = message.split()[1]
url = unsplash_url + term
else:
url = unsplash_url
response = requests.get(url).url
if 'photo-1446704477871-62a4972035cd' in response:
return "Could not find an image for those tags."
else:
return response