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."""
|
"""J.A.R.V.I.S. Owner Cog."""
|
||||||
from discord import User
|
from dis_snek import MessageContext, Scale, Snake, message_command
|
||||||
from discord.ext import commands
|
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.config import reload_config
|
||||||
from jarvis.db.models import Config
|
from jarvis.db.models import Config
|
||||||
|
|
||||||
|
|
||||||
class OwnerCog(commands.Cog):
|
class OwnerCog(Scale):
|
||||||
"""
|
"""
|
||||||
J.A.R.V.I.S. management cog.
|
J.A.R.V.I.S. management cog.
|
||||||
|
|
||||||
Used by admins to control core J.A.R.V.I.S. systems
|
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.bot = bot
|
||||||
self.admins = Config.objects(key="admins").first()
|
self.admins = Config.objects(key="admins").first()
|
||||||
|
|
||||||
@commands.group(name="admin", hidden=True, pass_context=True)
|
@message_command(name="addadmin")
|
||||||
@commands.is_owner()
|
@is_owner()
|
||||||
async def _admin(self, ctx: commands.Context) -> None:
|
async def _add(self, ctx: MessageContext, user: User) -> 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:
|
if user.id in self.admins.value:
|
||||||
await ctx.send(f"{user.mention} is already an admin.")
|
await ctx.send(f"{user.mention} is already an admin.")
|
||||||
return
|
return
|
||||||
|
@ -34,9 +29,9 @@ class OwnerCog(commands.Cog):
|
||||||
reload_config()
|
reload_config()
|
||||||
await ctx.send(f"{user.mention} is now an admin. Use this power carefully.")
|
await ctx.send(f"{user.mention} is now an admin. Use this power carefully.")
|
||||||
|
|
||||||
@_admin.command(name="remove", hidden=True)
|
@message_command(name="deladmin")
|
||||||
@commands.is_owner()
|
@is_owner()
|
||||||
async def _remove(self, ctx: commands.Context, user: User) -> None:
|
async def _remove(self, ctx: MessageContext, user: User) -> None:
|
||||||
if user.id not in self.admins.value:
|
if user.id not in self.admins.value:
|
||||||
await ctx.send(f"{user.mention} is not an admin.")
|
await ctx.send(f"{user.mention} is not an admin.")
|
||||||
return
|
return
|
||||||
|
@ -46,6 +41,6 @@ class OwnerCog(commands.Cog):
|
||||||
await ctx.send(f"{user.mention} is no longer an admin.")
|
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."""
|
"""Add OwnerCog to J.A.R.V.I.S."""
|
||||||
bot.add_cog(OwnerCog(bot))
|
bot.add_cog(OwnerCog(bot))
|
||||||
|
|
Loading…
Add table
Reference in a new issue