Migrate owner, closes #99
This commit is contained in:
parent
3489fb1ec3
commit
93381d7da0
1 changed files with 12 additions and 17 deletions
|
@ -1,31 +1,26 @@
|
|||
"""J.A.R.V.I.S. Owner Cog."""
|
||||
from discord import User
|
||||
from discord.ext import commands
|
||||
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 jarvis.config import reload_config
|
||||
from jarvis.db.models import Config
|
||||
|
||||
|
||||
class OwnerCog(commands.Cog):
|
||||
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: commands.Cog):
|
||||
def __init__(self, bot: Snake):
|
||||
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:
|
||||
@message_command(name="addadmin")
|
||||
@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
|
||||
|
@ -34,9 +29,9 @@ class OwnerCog(commands.Cog):
|
|||
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:
|
||||
@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
|
||||
|
@ -46,6 +41,6 @@ class OwnerCog(commands.Cog):
|
|||
await ctx.send(f"{user.mention} is no longer an admin.")
|
||||
|
||||
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
def setup(bot: Snake) -> None:
|
||||
"""Add OwnerCog to J.A.R.V.I.S."""
|
||||
bot.add_cog(OwnerCog(bot))
|
||||
|
|
Loading…
Add table
Reference in a new issue