import random import sys import requests import os import eight_ball import excuse import define_word import help_methods import discord import docker from pybooru import Danbooru # Client object client = discord.Client() tokens = { 'test': 'MzQ1MjkwMTI5OTQ4Mjc4Nzg0.DG5IBw._9umb82PrL22bPe7GjmHClU-NtU', 'prod': 'MzM5NDQ2NTgwMTU3MzQ5ODg4.DG5K5Q.2kIonA_XHLXU4_Sq4O63OzCb0Jc' } dragon_environment = os.getenv('DRAGON_ENV') debug = dragon_environment == 'test' @client.event async def on_ready(): print("\n********************************") print("\nDRAGON BOT RUNNING IN {} MODE".format(dragon_environment.upper())) print("\n********************************") await client.change_presence(game=discord.Game(name='Type !help to see how to use me')) if debug: print("\nPress control+c to exit the bot") print("Followed by control+d or by typing") print("'exit' to exit the docker container") @client.event async def on_message(message): def is_me(m): """ is_me(m) takes a message as an argument and checks that the author of the 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 if client.user.mentioned_in(message): print('fuck u') if message.content.startswith('!8ball'): await client.send_message( message.channel, eight_ball.check_8ball(message.content) ) if message.content.startswith('!define'): await client.send_message( message.channel, define_word.get_definition(message.content) ) 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('!purge'): num = 20 if len(message.content.split()) > 1: try: num = int(message.content.split()[1]) except ValueError: # If they dont enter a number, show them an error and return out of the function 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'): choices = message.content.replace('!decide', '').lstrip().split(' or ') if len(choices) > 1: ####### debug ########### # await client.send_message(message.channel, "I see {} choices, {}".format(len(choices), 'and '.join(choices))) print("{} has initated a decide between {}".format(message.author, choices)) await client.send_message(message.channel, "{} {}".format(message.author.mention, random.choice(choices))) else: await client.send_message(message.channel, "{} {}".format(message.author.mention, random.choice(['yes', 'no']))) 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'): url = 'https://source.unsplash.com/3840x2160/' if len(message.content.split()) > 1: keyword = message.content.split()[1] 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) ################################### ###### +-------------------+ ###### ###### | | ###### ###### | 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') ################################### ###### +-------------------+ ###### ###### | | ###### ###### | Docker Functions | ###### ###### | | ###### ###### +-------------------+ ###### ################################### if message.content.startswith('!docker') and (message.author != client.user): # Check permissions roles = [] allowed_roles = ['MOD', 'Greasemonkey', 'Adminimodistrator'] for role in message.author.roles: roles.append(role.name) docker_privleges = not set(roles).isdisjoint(allowed_roles) if not docker_privleges: await client.send_message(message.channel, "Sorry {}, You dont have permission to run docker commands".format(message.author.mention)) return if len(message.content.split()) == 1: actions = ['restart', 'status', 'logs'] await client.send_message(message.channel, "\nSupported actions:\n{}".format(", ".join(actions))) else: docker_client = docker.from_env() minecraft_container = docker_client.containers.get('skyfactory') # Figure out what action they want to take action = message.content.split()[1] if action == 'restart': await client.send_message(message.channel, "{}, Are you sure you want to restart the container? [!yes/!no]".format(message.author.mention)) confirm_restart = await client.wait_for_message(author=message.author, channel=message.channel, content='!yes') if confirm_restart: await client.send_message(message.channel, "Sending restart action to {} container".format(minecraft_container.name)) minecraft_container.restart() if action == 'status': await client.send_message(message.channel, "{} is {}".format(minecraft_container.name, minecraft_container.status)) if action == 'logs': if len(message.content.split()) == 3: num_lines = int(message.content.split()[2]) else: num_lines = 10 log_stream = minecraft_container.logs(tail=num_lines).decode('utf-8') if len(log_stream) >= num_lines: await client.send_message(message.channel, "Pulling last {} lines from {} container".format(num_lines, minecraft_container.name)) await client.send_message(message.channel, "```{}```".format(minecraft_container.logs(tail=num_lines).decode('utf-8'))) else: await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines)) client.run(tokens[dragon_environment])