from pybooru import Danbooru import asyncio import discord import docker import json import logging import os import random import requests import time # Client object client = discord.Client() botToken = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app discord_server_id = '97456282729996288' @client.event async def on_ready(): print("Dragon bot up and ready to roll.\n") @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', 'imgur.com', ] 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('!help')): supported_methods = { 'decide': 'Dragon-bot will help make the tough decisions for you\n!decide option 1 or option 2.\n\nIf only one option, it will give you a yes or no', 'docker': 'Two supported actions: logs and restart\n\nlogs: Shows you the last X number of lines from the minecraft server. If no number is specified, defaults to 10.\n\nrestart: will restart the minecraft server if something is fucky', 'excuse': 'Generates a random excuse you can give your boss', 'help': 'Prints out a list of everything dragon-bot can do', 'lewd': 'Returns a URL for a lewd image. Can only be used in NSFW channels', 'purge': 'Deletes the last 100 messages you sent from the channel you typed purge in', 'triggered': 'REEEEEEEEEEEEEEEEEE', 'wallpaper': 'Returns the URL for a 4k wallpaper. You can enter a search term as well, for example, !wallpaper, or, !wallpaper flowers', } if len(message.content.split()) > 1: method = message.content.split()[1] if method not in supported_methods.keys(): await client.send_message(message.channel, "I cant help you with that") return await client.send_message(message.channel,"```{}```".format(supported_methods[method])) else: await client.send_message(message.channel, "I currently have {} methods,\n\n```{}```\n\nYou can get information about a specific method by typing !help ".format(len(supported_methods), ', '.join(supported_methods.keys()))) if('autis' in message.content): await client.send_message(message.channel, 'https://i.imgur.com/g6yOJjp.gif') if(message.content.startswith('!triggered')): await client.send_message(message.channel, 'https://i.imgur.com/g6yOJjp.gif') if(message.content.startswith('!excuse')): excuses = requests.get( 'https://gist.githubusercontent.com/AndrewBrinker/6763cdd5d79d6e3eaa3f/raw/624b946ebcca71ac76b74afa5ea41280540c1b97/excuses.txt' ).text.split("\n") await client.send_message(message.channel, random.choice(excuses)) if(message.content.startswith('!purge')): deleted = await client.purge_from(message.channel, limit=20, 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 '144986109804412928' == message.author.id: def is_bot(m): return m.author == client.user deleted = 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(botToken)