-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Restructure `SlashSync` according to SFUAnime/Ren#608. No functional changes. - Remove module docstring for `slashsync.py` as it is already included in `__init__.py`.
- Loading branch information
1 parent
5d6f33c
commit 25108f8
Showing
4 changed files
with
46 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from redbot.core import checks, commands | ||
from redbot.core.commands import Context | ||
|
||
from .commandsCore import SlashSyncCommandsCore | ||
|
||
|
||
class SlashSyncCommandHandlers(SlashSyncCommandsCore): | ||
@commands.command(name="sync") | ||
@checks.is_owner() | ||
async def _cmdSync(self, ctx: Context): | ||
await self.cmdSync(ctx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from redbot.core.commands.context import Context | ||
from redbot.core.utils.chat_formatting import info, success | ||
|
||
from .core import SlashSyncCore | ||
|
||
|
||
class SlashSyncCommandsCore(SlashSyncCore): | ||
async def cmdSync(self, ctx: Context): | ||
msg = await ctx.send(info("Syncing slash commands to Discord, please wait...")) | ||
await self.bot.tree.sync() | ||
await msg.edit(content=success("Synchronized slash commands to Discord.")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
|
||
from redbot.core.bot import Red | ||
|
||
|
||
class SlashSyncCore: | ||
def __init__(self, bot: Red): | ||
self.bot = bot | ||
self.logger = logging.getLogger("red.luicogs.SlashSync") | ||
self.bgTask = self.bot.loop.create_task(self.waitUntilBotReady()) | ||
|
||
async def waitUntilBotReady(self): | ||
self.logger.debug("Waiting for bot to be ready") | ||
await self.bot.wait_until_red_ready() | ||
self.logger.debug("Bot is ready, synchronizing command tree") | ||
await self.bot.tree.sync() | ||
self.logger.debug("Command tree synchronized") | ||
|
||
def cog_unload(self): | ||
self.logger.debug("Clean up background task") | ||
self.bgTask.cancel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,7 @@ | ||
"""SlashSync | ||
from redbot.core import commands | ||
|
||
Sync slash commands from the bot to the server. | ||
""" | ||
import logging | ||
from .commandHandlers import SlashSyncCommandHandlers | ||
|
||
from redbot.core import checks, commands | ||
from redbot.core.bot import Red | ||
from redbot.core.commands.context import Context | ||
from redbot.core.utils.chat_formatting import info, success | ||
|
||
|
||
class SlashSync(commands.Cog): | ||
class SlashSync(commands.Cog, SlashSyncCommandHandlers): | ||
"""Synchronize slash commands on the bot to Discord""" | ||
|
||
def __init__(self, bot: Red): | ||
self.bot = bot | ||
self.logger = logging.getLogger("red.luicogs.SlashSync") | ||
self.bgTask = self.bot.loop.create_task(self.waitUntilBotReady()) | ||
|
||
async def waitUntilBotReady(self): | ||
self.logger.debug("Waiting for bot to be ready") | ||
await self.bot.wait_until_red_ready() | ||
self.logger.debug("Bot is ready, synchronizing command tree") | ||
await self.bot.tree.sync() | ||
self.logger.debug("Command tree synchronized") | ||
|
||
def cog_unload(self): | ||
self.logger.debug("Clean up background task") | ||
self.bgTask.cancel() | ||
|
||
@commands.command(name="sync") | ||
@checks.is_owner() | ||
async def sync(self, ctx: Context): | ||
"""Synchronize slash commands to Discord""" | ||
msg = await ctx.send(info("Syncing slash commands to Discord, please wait...")) | ||
await self.bot.tree.sync() | ||
await msg.edit(content=success("Synchronized slash commands to Discord.")) |