Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Status] Add statusdev clearchannels command #104

Merged
merged 3 commits into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions status/commands/statusdev_com.py
Expand Up @@ -213,3 +213,21 @@ async def devenvvars(self, ctx: commands.Context):
except Exception:
_log.exception("Unable to add dev env vars.")
await ctx.send("I was unable to add them. Check the logs.")

@commands.before_invoke(unsupported)
@statusdev.command(aliases=["cl"], hidden=True)
async def clearchannels(self, ctx: commands.Context):
"""Clear channels from Config that no longer exists."""
data = await self.config.all_channels()
count = 0
for channel_id in data.keys():
channel = self.bot.get_channel(channel_id)
if channel is None:
await self.config.channel_from_id(channel_id).clear()
count += 1

await ctx.send(
f"Successfully cleared out {count:,} channels."
if count
else "There was no channels to clear."
)
6 changes: 5 additions & 1 deletion status/updateloop/utils.py
Expand Up @@ -60,7 +60,11 @@ async def get_channel_data(bot: Red, c_id: int, settings: ConfChannelSettings) -
channel = bot.get_channel(c_id)
if channel is None:
# TODO: maybe remove from config
_log.info(f"I can't find the channel with id {c_id} - skipping")
_log.info(
f"I can't find the channel with id {c_id} - skipping. "
"You can use the [p]statusdev clearchannels in order to "
"remove all no longer existing channels"
)
raise NotFound

if TYPE_CHECKING:
Expand Down