Add admin controls
This commit is contained in:
parent
f61a8fceba
commit
e357d6e4ce
1 changed files with 41 additions and 3 deletions
|
@ -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} <subcommand>`\n"
|
||||
f"Usage: `system <subcommand>`\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 <subcommand>`\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))
|
||||
|
|
Loading…
Add table
Reference in a new issue