Add a new $grant command to let the owner give others the matcher scope
This commit is contained in:
parent
71147e963e
commit
d517ccb150
2 changed files with 34 additions and 11 deletions
|
@ -3,22 +3,27 @@ Owner bot cog
|
|||
"""
|
||||
import logging
|
||||
from discord.ext import commands
|
||||
from state import State, AuthScope, save_to_file
|
||||
|
||||
logger = logging.getLogger("owner")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
class OwnerCog(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
def __init__(self, bot: commands.Bot, state: State):
|
||||
self._bot = bot
|
||||
self._state = state
|
||||
|
||||
@commands.command()
|
||||
@commands.dm_only()
|
||||
@commands.is_owner()
|
||||
async def sync(self, ctx: commands.Context):
|
||||
"""Handle sync command"""
|
||||
"""
|
||||
Sync the bot commands
|
||||
You get rate limited if you do this too often so it's better to keep it on command
|
||||
"""
|
||||
msg = await ctx.reply(content="Syncing commands...", ephemeral=True)
|
||||
synced = await self.bot.tree.sync()
|
||||
synced = await self._bot.tree.sync()
|
||||
logger.info("Synced %s command(s)", len(synced))
|
||||
await msg.edit(content="Done!")
|
||||
|
||||
|
@ -26,7 +31,26 @@ class OwnerCog(commands.Cog):
|
|||
@commands.dm_only()
|
||||
@commands.is_owner()
|
||||
async def close(self, ctx: commands.Context):
|
||||
"""Handle restart command"""
|
||||
"""
|
||||
Handle close command
|
||||
Shuts down the bot when needed
|
||||
"""
|
||||
await ctx.reply("Closing bot...", ephemeral=True)
|
||||
logger.info("Closing down the bot")
|
||||
await self.bot.close()
|
||||
await self._bot.close()
|
||||
|
||||
@commands.command()
|
||||
@commands.dm_only()
|
||||
@commands.is_owner()
|
||||
async def grant(self, ctx: commands.Context, user: str):
|
||||
"""
|
||||
Handle grant command
|
||||
Grant the matcher scope to a given user
|
||||
"""
|
||||
if user.isdigit():
|
||||
self._state.set_user_scope(str(user), AuthScope.MATCHER)
|
||||
save_to_file(self._state)
|
||||
logger.info("Granting user %s matcher scope", user)
|
||||
await ctx.reply("Done!", ephemeral=True)
|
||||
else:
|
||||
await ctx.reply("Likely not a user...", ephemeral=True)
|
||||
|
|
|
@ -5,12 +5,11 @@ import logging
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
import config
|
||||
import state
|
||||
from state import load_from_file
|
||||
from cogs.matchy_cog import MatchyCog
|
||||
from cogs.owner_cog import OwnerCog
|
||||
|
||||
State = state.load_from_file()
|
||||
|
||||
state = load_from_file()
|
||||
|
||||
logger = logging.getLogger("matchy")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
@ -24,8 +23,8 @@ bot = commands.Bot(command_prefix='$',
|
|||
|
||||
@bot.event
|
||||
async def setup_hook():
|
||||
await bot.add_cog(MatchyCog(bot, State))
|
||||
await bot.add_cog(OwnerCog(bot))
|
||||
await bot.add_cog(MatchyCog(bot, state))
|
||||
await bot.add_cog(OwnerCog(bot, state))
|
||||
|
||||
|
||||
@bot.event
|
||||
|
|
Loading…
Add table
Reference in a new issue