diff --git a/python/ext/cmd_owner.py b/python/ext/cmd_owner.py new file mode 100644 index 0000000..4bab8d9 --- /dev/null +++ b/python/ext/cmd_owner.py @@ -0,0 +1,43 @@ +from discord.ext import commands +from datetime import datetime +from __main__ import startup_date +import discord +import asyncio + + +class OwnerCmds(commands.Cog, name='Owner commands'): + def __init__(self, bot): + self.bot = bot + + @commands.command(hidden=True, ignore_extra=False) + @commands.is_owner() + async def loadext(self, ctx, extension): + bot.load_extension(extension) + await ctx.send("Extension loaded.") + + + @commands.command(hidden=True, ignore_extra=False) + @commands.is_owner() + async def unloadext(self, ctx, extension): + bot.unload_extension(extension) + await ctx.send("Extension unloaded.") + + + @commands.command(hidden=True) + @commands.is_owner() + async def update(self, ctx): + result = str(os.popen('git pull').read()) + await ctx.send('``' + result + '``') + if 'Already up to date' not in result: + os.execl(sys.executable, os.path.abspath(__file__), *sys.argv) + + + @commands.command(hidden=True) + @commands.is_owner() + async def getlogs(self, ctx): + await ctx.send('Logs since ' + startup_date.strftime("``[%d-%m-%y | %H:%M:%S]``"), + file=discord.File('logs.txt')) + + +def setup(bot): + bot.add_cog(OwnerCmds(bot)) diff --git a/python/main.py b/python/main.py index 18cc5a0..826d393 100644 --- a/python/main.py +++ b/python/main.py @@ -11,7 +11,7 @@ import discord print('Loading started') bot = commands.Bot(command_prefix='$') -startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch"] +startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch", "cmd_owner"] startup_date = datetime.now() time_s = time() @@ -43,36 +43,6 @@ async def on_command_error(ctx, error): await ctx.send(error) -@bot.command(hidden=True, ignore_extra=False) -@commands.is_owner() -async def loadext(ctx, extension): - bot.load_extension(extension) - await ctx.send("Extension loaded.") - - -@bot.command(hidden=True, ignore_extra=False) -@commands.is_owner() -async def unloadext(ctx, extension): - bot.unload_extension(extension) - await ctx.send("Extension unloaded.") - - -@bot.command(hidden=True) -@commands.is_owner() -async def update(ctx): - result = str(os.popen('git pull').read()) - await ctx.send('``' + result + '``') - if 'Already up to date' not in result: - os.execl(sys.executable, os.path.abspath(__file__), *sys.argv) - - -@bot.command(hidden=True) -@commands.is_owner() -async def getlogs(ctx): - await ctx.send('Logs since ' + startup_date.strftime("``[%d-%m-%y | %H:%M:%S]``"), - file=discord.File('logs.txt')) - - if __name__ == "__main__": for extension in startup_extensions: bot.load_extension('ext.' + extension)