From e770ed86a6587cbabed3f366e23192b268ef60e6 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Tue, 5 May 2020 17:47:35 -0700 Subject: [PATCH] Adding minecraft map functionality back to the bot --- app/dragon-bot.py | 167 ++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 87 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 4baff0d0..d61179c5 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -412,104 +412,97 @@ async def on_message(message): - # if message.content.startswith('!minecraft'): - # # Check permissions - # if not role_check.docker_permissions(message.author.roles): - # await client.send_message( - # message.channel, - # "You dont have permission to run docker commands" - # ) - # return + if message.content.startswith('!minecraft'): + # Figure out what action they want to take + action = message.content.split()[1] + if action == 'map': + await client.send_message( + message.channel, + "https://luker.gq/minecraft" + ) - # if len(message.content.split()) == 1: - # actions = ['restart', 'status', 'logs', 'map'] - # await client.send_message( - # message.channel, - # "\nSupported actions:```\n{}```".format(", ".join(actions)) - # ) - # else: - # docker_client = docker.from_env() - # try: - # minecraft_container = docker_client.containers.get('beyondreality') - # except: - # await client.send_message( - # message.channel, - # "The minecraft server is not running" - # ) - # 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() + # try: + # minecraft_container = docker_client.containers.get('minecraft_eternal') + # except: + # await client.send_message( + # message.channel, + # "The minecraft server is not running" + # ) + # return - # # Figure out what action they want to take - # action = message.content.split()[1] - # if action == 'restart': - # await client.send_message( - # message.channel, - # "{}, restart the server? [!yes/!no]".format( - # message.author.mention) - # ) + # if action == 'restart': + # await client.send_message( + # message.channel, + # "{}, restart the server? [!yes/!no]".format( + # message.author.mention) + # ) - # confirm_restart = await client.wait_for_message( - # author=message.author, - # channel=message.channel, - # content='!yes' - # ) + # 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 {} server".format( - # minecraft_container.name - # ) - # ) + # if confirm_restart: + # await client.send_message( + # message.channel, + # "Sending restart action to {} server".format( + # minecraft_container.name + # ) + # ) - # minecraft_container.restart() + # minecraft_container.restart() - # if action == 'status': - # await client.send_message( - # message.channel, - # "{} server is {}".format( - # minecraft_container.name, - # minecraft_container.status - # ) - # ) + # if action == 'status': + # await client.send_message( + # message.channel, + # "{} server 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 + # 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') + # 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 the {} server ".format( - # num_lines, - # minecraft_container.name - # ) - # ) + # if len(log_stream) >= num_lines: + # await client.send_message( + # message.channel, + # "Pulling last {} lines from the {} server ".format( + # num_lines, + # minecraft_container.name + # ) + # ) - # await client.send_message( - # message.channel, - # "```{}```".format( - # minecraft_container.logs( - # tail=num_lines - # ).decode('utf-8') - # ) - # ) + # 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) - # ) - # if action == 'map': - # await client.send_message( - # message.channel, - # "https://luker.gq/minecraft" - # ) + # else: + # await client.send_message( + # message.channel, + # "There arent {} lines of output yet".format(num_lines) + # ) client.run(os.getenv('token'))