jarvis-bot/jarvis/cogs/owner.py

47 lines
1.5 KiB
Python

"""J.A.R.V.I.S. Owner Cog."""
from dis_snek import MessageContext, Scale, Snake, message_command
from dis_snek.models.discord.user import User
from dis_snek.models.snek.checks import is_owner
from dis_snek.models.snek.command import check
from jarvis.config import reload_config
from jarvis.db.models import Config
class OwnerCog(Scale):
"""
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: Snake):
self.bot = bot
self.admins = Config.objects(key="admins").first()
@message_command(name="addadmin")
@check(is_owner())
async def _add(self, ctx: MessageContext, 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.")
@message_command(name="deladmin")
@is_owner()
async def _remove(self, ctx: MessageContext, 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: Snake) -> None:
"""Add OwnerCog to J.A.R.V.I.S."""
OwnerCog(bot)