Pull out the owner cog parts
Also make them use is_owner() rather than custom auth
This commit is contained in:
parent
723fa5dfba
commit
f4f6df90fb
2 changed files with 36 additions and 34 deletions
38
py/matchy.py
38
py/matchy.py
|
@ -6,7 +6,8 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import config
|
import config
|
||||||
import state
|
import state
|
||||||
import cog
|
from matchy_cog import MatchyCog
|
||||||
|
from owner_cog import OwnerCog
|
||||||
import match_button
|
import match_button
|
||||||
|
|
||||||
State = state.load_from_file()
|
State = state.load_from_file()
|
||||||
|
@ -24,7 +25,8 @@ bot = commands.Bot(command_prefix='$',
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def setup_hook():
|
async def setup_hook():
|
||||||
await bot.add_cog(cog.MatchyCog(bot, State))
|
await bot.add_cog(MatchyCog(bot, State))
|
||||||
|
await bot.add_cog(OwnerCog(bot))
|
||||||
# TODO: This line feels like it should be in the cog?
|
# TODO: This line feels like it should be in the cog?
|
||||||
bot.add_dynamic_items(match_button.DynamicGroupButton)
|
bot.add_dynamic_items(match_button.DynamicGroupButton)
|
||||||
|
|
||||||
|
@ -34,38 +36,6 @@ async def on_ready():
|
||||||
logger.info("Logged in as %s", bot.user.name)
|
logger.info("Logged in as %s", bot.user.name)
|
||||||
|
|
||||||
|
|
||||||
def owner_only(ctx: commands.Context) -> bool:
|
|
||||||
"""Checks the author is an owner"""
|
|
||||||
return State.get_user_has_scope(ctx.message.author.id, state.AuthScope.OWNER)
|
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
|
||||||
@commands.dm_only()
|
|
||||||
@commands.check(owner_only)
|
|
||||||
async def sync(ctx: commands.Context):
|
|
||||||
"""Handle sync command"""
|
|
||||||
msg = await ctx.reply("Reloading state...", ephemeral=True)
|
|
||||||
global State
|
|
||||||
State = state.load_from_file()
|
|
||||||
logger.info("Reloaded state")
|
|
||||||
|
|
||||||
await msg.edit(content="Syncing commands...")
|
|
||||||
synced = await bot.tree.sync()
|
|
||||||
logger.info("Synced %s command(s)", len(synced))
|
|
||||||
|
|
||||||
await msg.edit(content="Done!")
|
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
|
||||||
@commands.dm_only()
|
|
||||||
@commands.check(owner_only)
|
|
||||||
async def close(ctx: commands.Context):
|
|
||||||
"""Handle restart command"""
|
|
||||||
await ctx.reply("Closing bot...", ephemeral=True)
|
|
||||||
logger.info("Closing down the bot")
|
|
||||||
await bot.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
bot.run(config.Config.token, log_handler=handler, root_logger=True)
|
bot.run(config.Config.token, log_handler=handler, root_logger=True)
|
||||||
|
|
32
py/owner_cog.py
Normal file
32
py/owner_cog.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
"""
|
||||||
|
Owner bot cog
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
logger = logging.getLogger("owner")
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
class OwnerCog(commands.Cog):
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.dm_only()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def sync(self, ctx: commands.Context):
|
||||||
|
"""Handle sync command"""
|
||||||
|
msg = await ctx.reply(content="Syncing commands...", ephemeral=True)
|
||||||
|
synced = await self.bot.tree.sync()
|
||||||
|
logger.info("Synced %s command(s)", len(synced))
|
||||||
|
await msg.edit(content="Done!")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.dm_only()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def close(self, ctx: commands.Context):
|
||||||
|
"""Handle restart command"""
|
||||||
|
await ctx.reply("Closing bot...", ephemeral=True)
|
||||||
|
logger.info("Closing down the bot")
|
||||||
|
await self.bot.close()
|
Loading…
Add table
Reference in a new issue