From 449c3bfe18b712d9ae127c6b35d352b8d375293d Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Thu, 14 Jun 2018 10:25:26 -0800 Subject: [PATCH] Add restart command and processing --- src/__main__.py | 6 ++++++ src/cogs/contributors.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/__main__.py b/src/__main__.py index e3a96fb..95b05ee 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -71,6 +71,12 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): async def on_ready(self): """On ready function""" self.maintenance and self.logger.warning('MAINTENANCE ACTIVE') + with open(f'src/config/reboot', 'r') as f: + reboot = f.readlines() + if int(reboot[0]) == 1: + await self.get_channel(int(reboot[1])).send('Restart Finished.') + with open(f'src/config/reboot', 'w') as f: + f.write(f'0') async def on_command_error(self, ctx, error): """ diff --git a/src/cogs/contributors.py b/src/cogs/contributors.py index 159b8b6..4f69c2a 100644 --- a/src/cogs/contributors.py +++ b/src/cogs/contributors.py @@ -5,6 +5,7 @@ from discord.ext import commands import discord import traceback import aiofiles +import os class Upload: """ @@ -114,5 +115,16 @@ class Upload: await ctx.send("Extension not found") + @commands.command(hidden=True) + async def reboot(self, ctx): + if ctx.author.id not in self.bot.ownerlist: + return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10) + await ctx.send('Sebi-Machine is restarting.') + with open(f'src/config/reboot', 'w') as f: + f.write(f'1\n{ctx.channel.id}') + # noinspection PyProtectedMember + os._exit(1) + + def setup(bot): bot.add_cog(Upload(bot))