Move the avatar stuff into its own module to keep things clean
This commit is contained in:
parent
f9a82feb76
commit
22c9f954c5
18
app/avatar.py
Normal file
18
app/avatar.py
Normal file
@ -0,0 +1,18 @@
|
||||
import requests
|
||||
|
||||
import get_from_reddit
|
||||
|
||||
def change_avatar():
|
||||
image = None
|
||||
while not image:
|
||||
image = get_from_reddit.get_image(boards='smuganimegirls')
|
||||
extension = image.split('.')[-1]
|
||||
local_smug = "/tmp/smug.{}".format(extension)
|
||||
|
||||
# save an image locally
|
||||
if extension.lower() in ['png', 'jpg']:
|
||||
with open(local_smug, 'wb') as f:
|
||||
f.write(requests.get(image).content)
|
||||
return open(local_smug, 'rb').read()
|
||||
else:
|
||||
image = None
|
@ -8,6 +8,7 @@ then imported into the main bot
|
||||
import os
|
||||
import requests
|
||||
|
||||
import avatar
|
||||
import decide
|
||||
import define_word
|
||||
import discord
|
||||
@ -37,25 +38,8 @@ async def on_ready():
|
||||
game=discord.Game(name='Type !help to see what I can do')
|
||||
)
|
||||
|
||||
# Keep trying for a different smug anime girl until we get a jpg or png
|
||||
image = None
|
||||
while not image and not debug:
|
||||
image = get_from_reddit.get_image(boards='smuganimegirls')
|
||||
extension = image.split('.')[-1]
|
||||
local_smug = "/tmp/smug.{}".format(extension)
|
||||
|
||||
if extension.lower() in ['png', 'jpg']:
|
||||
with open(local_smug, 'wb') as f:
|
||||
f.write(requests.get(image).content)
|
||||
|
||||
# Set the profile picture
|
||||
try:
|
||||
await client.edit_profile(avatar=open(local_smug, 'rb').read())
|
||||
except discord.errors.HTTPException:
|
||||
print('Failed setting profile image. retrying')
|
||||
image = None
|
||||
else:
|
||||
image = None
|
||||
if not debug:
|
||||
await client.edit_profile(avatar=avatar.change_avatar())
|
||||
|
||||
print("\n********************************")
|
||||
print("\nDRAGON BOT RUNNING IN {} MODE".format(dragon_environment.upper()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user