Skip to content

Commit

Permalink
[Status] Add statusdev clearchannels command (#104)
Browse files Browse the repository at this point in the history
Closes #101
  • Loading branch information
PredaaA authored Nov 10, 2022
1 parent 7b32136 commit 1b37ac6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions status/commands/statusdev_com.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 1b37ac6

Please sign in to comment.