randomize profile pic on launch and create a get from reddit function
This commit is contained in:
parent
d5dcf5d51c
commit
726c8424bb
@ -6,6 +6,7 @@ then imported into the main bot
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
import decide
|
import decide
|
||||||
import define_word
|
import define_word
|
||||||
@ -13,6 +14,7 @@ import discord
|
|||||||
import docker
|
import docker
|
||||||
import eight_ball
|
import eight_ball
|
||||||
import excuse
|
import excuse
|
||||||
|
import get_from_reddit
|
||||||
import help_methods
|
import help_methods
|
||||||
import lewds
|
import lewds
|
||||||
import role_check
|
import role_check
|
||||||
@ -30,14 +32,35 @@ dragon_environment = os.getenv('DRAGON_ENV')
|
|||||||
debug = dragon_environment == 'test'
|
debug = dragon_environment == 'test'
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("\n********************************")
|
# Update the bot's status
|
||||||
print("\nDRAGON BOT RUNNING IN {} MODE".format(dragon_environment.upper()))
|
|
||||||
print("\n********************************")
|
|
||||||
|
|
||||||
await client.change_presence(
|
await client.change_presence(
|
||||||
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
|
||||||
|
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
|
||||||
|
|
||||||
|
print("\n********************************")
|
||||||
|
print("\nDRAGON BOT RUNNING IN {} MODE".format(dragon_environment.upper()))
|
||||||
|
print("\n********************************")
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print("\nPress control+c to exit the bot")
|
print("\nPress control+c to exit the bot")
|
||||||
print("Followed by control+d or by typing")
|
print("Followed by control+d or by typing")
|
||||||
@ -217,5 +240,4 @@ async def on_message(message):
|
|||||||
"There arent {} lines of output yet".format(num_lines)
|
"There arent {} lines of output yet".format(num_lines)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
client.run(tokens[dragon_environment])
|
client.run(tokens[dragon_environment])
|
||||||
|
29
app/get_from_reddit.py
Normal file
29
app/get_from_reddit.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import random
|
||||||
|
import requests
|
||||||
|
|
||||||
|
def get_image(boards):
|
||||||
|
"""
|
||||||
|
get_image(boards)
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
if isinstance(boards, list):
|
||||||
|
boards = random.choice(boards)
|
||||||
|
|
||||||
|
domains = [
|
||||||
|
'my.mixtape.moe',
|
||||||
|
'i.imgur.com',
|
||||||
|
'imgur.com',
|
||||||
|
'i.redd.it',
|
||||||
|
'i.reddituploads.com',
|
||||||
|
]
|
||||||
|
|
||||||
|
response = requests.get(
|
||||||
|
"https://reddit.com/r/{}.json?limit=500".format(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://')
|
33
app/lewds.py
33
app/lewds.py
@ -1,12 +1,13 @@
|
|||||||
import random
|
import random
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import get_from_reddit
|
||||||
from pybooru import Danbooru
|
from pybooru import Danbooru
|
||||||
|
|
||||||
|
|
||||||
def get_from_danbooru():
|
def get_from_danbooru(boards):
|
||||||
"""
|
"""
|
||||||
get_from_danbooru()
|
get_from_danbooru(boards)
|
||||||
|
|
||||||
returns a URL to an image on danbooru that matches a random tag
|
returns a URL to an image on danbooru that matches a random tag
|
||||||
defined in the tag_list list
|
defined in the tag_list list
|
||||||
@ -65,13 +66,8 @@ def get_from_danbooru():
|
|||||||
)['large_file_url'])
|
)['large_file_url'])
|
||||||
|
|
||||||
|
|
||||||
def get_from_reddit():
|
def get_lewd(channel_name):
|
||||||
"""
|
if 'nsfw' in channel_name:
|
||||||
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 = [
|
boards = [
|
||||||
'2Booty',
|
'2Booty',
|
||||||
'bakunyuu_hentai',
|
'bakunyuu_hentai',
|
||||||
@ -80,22 +76,7 @@ def get_from_reddit():
|
|||||||
'rule34',
|
'rule34',
|
||||||
'WesternHentai',
|
'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))
|
# This is really bad practice but pass boards to get_from_reddit AND danbooru so it doesnt error
|
||||||
return random.choice(image_urls)['data']['url'].replace('http://', 'https://')
|
return random.choice([get_from_reddit.get_image, get_from_danbooru])(boards=boards)
|
||||||
|
|
||||||
|
|
||||||
def get_lewd(channel_name):
|
|
||||||
if 'nsfw' in channel_name:
|
|
||||||
return random.choice([get_from_reddit, get_from_danbooru])()
|
|
||||||
return 'You can only use this command in NSFW channels'
|
return 'You can only use this command in NSFW channels'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user