diff --git a/jarvis/cogs/owner.py b/jarvis/cogs/owner.py index c11da7d..13e6039 100644 --- a/jarvis/cogs/owner.py +++ b/jarvis/cogs/owner.py @@ -1,8 +1,9 @@ import jarvis import discord +from discord import User from discord.ext import commands from jarvis.config import get_config, reload_config -from jarvis.utils import update, user_is_bot_admin +from jarvis.utils import update, user_is_bot_admin, db class OwnerCog(commands.Cog): @@ -14,7 +15,9 @@ class OwnerCog(commands.Cog): def __init__(self, bot): self.bot = bot - self.admins = get_config().admins + self.config = get_config() + self.admins = self.config.admins + self.db = db.DBManager(self.config.mongo) @commands.command(name="load", hidden=True) @user_is_bot_admin() @@ -85,7 +88,7 @@ class OwnerCog(commands.Cog): async def _system(self, ctx): if ctx.invoked_subcommand is None: await ctx.send( - f"Usage: `{ctx.message.content} `\n" + f"Usage: `system `\n" + "Subcommands: `restart`, `update`" ) @@ -150,6 +153,41 @@ class OwnerCog(commands.Cog): reload_config() await ctx.send("System refreshed") + @commands.group(name="admin", hidden=True, pass_context=True) + @commands.is_owner() + async def _admin(self, ctx): + if ctx.invoked_subcommand is None: + await ctx.send( + "Usage: `admin `\n" + + "Subcommands: `add`, `remove`" + ) + + @_admin.command(name="add", hidden=True) + @commands.is_owner() + async def _add(self, ctx, user: User): + if user.id in self.admins: + await ctx.send(f"{user.mention} is already an admin.") + return + self.admins.append(user.id) + self.db.mongo.jarvis.settings.update_one( + {"key": "admins"}, {"$set": {"value": self.admins}} + ) + await ctx.send( + f"{user.mention} is now an admin. Use this power carefully." + ) + + @_admin.command(name="remove", hidden=True) + @commands.is_owner() + async def _remove(self, ctx, user: User): + if user.id not in self.admins: + await ctx.send(f"{user.mention} is not an admin.") + return + self.admins.remove(user.id) + self.db.mongo.jarvis.settings.update_one( + {"key": "admins"}, {"$set": {"value": self.admins}} + ) + await ctx.send(f"{user.mention} is no longer an admin.") + def setup(bot): bot.add_cog(OwnerCog(bot))