jarvis-bot/jarvis/cogs/owner.py
2022-02-02 20:25:04 -07:00

51 lines
1.7 KiB
Python

"""J.A.R.V.I.S. Owner Cog."""
from discord import User
from discord.ext import commands
from jarvis.config import reload_config
from jarvis.db.models import Config
class OwnerCog(commands.Cog):
"""
J.A.R.V.I.S. management cog.
Used by admins to control core J.A.R.V.I.S. systems
"""
def __init__(self, bot: commands.Cog):
self.bot = bot
self.admins = Config.objects(key="admins").first()
@commands.group(name="admin", hidden=True, pass_context=True)
@commands.is_owner()
async def _admin(self, ctx: commands.Context) -> None:
if ctx.invoked_subcommand is None:
await ctx.send("Usage: `admin <subcommand>`\n" + "Subcommands: `add`, `remove`")
@_admin.command(name="add", hidden=True)
@commands.is_owner()
async def _add(self, ctx: commands.Context, user: User) -> None:
if user.id in self.admins.value:
await ctx.send(f"{user.mention} is already an admin.")
return
self.admins.value.append(user.id)
self.admins.save()
reload_config()
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: commands.Context, user: User) -> None:
if user.id not in self.admins.value:
await ctx.send(f"{user.mention} is not an admin.")
return
self.admins.value.remove(user.id)
self.admins.save()
reload_config()
await ctx.send(f"{user.mention} is no longer an admin.")
def setup(bot: commands.Bot) -> None:
"""Add OwnerCog to J.A.R.V.I.S."""
bot.add_cog(OwnerCog(bot))