Move the avatar stuff into its own module to keep things clean
This commit is contained in:
parent
c9ce94c73e
commit
560f8a503a
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 os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import avatar
|
||||||
import decide
|
import decide
|
||||||
import define_word
|
import define_word
|
||||||
import discord
|
import discord
|
||||||
@ -37,25 +38,8 @@ async def on_ready():
|
|||||||
game=discord.Game(name='Type !help to see what I can do')
|
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
|
if not debug:
|
||||||
image = None
|
await client.edit_profile(avatar=avatar.change_avatar())
|
||||||
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
|
|
||||||
|
|
||||||
print("\n********************************")
|
print("\n********************************")
|
||||||
print("\nDRAGON BOT RUNNING IN {} MODE".format(dragon_environment.upper()))
|
print("\nDRAGON BOT RUNNING IN {} MODE".format(dragon_environment.upper()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user