Skip to content

Commit

Permalink
[PersonalChannels] wipe config if chan is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
japandotorg committed Sep 15, 2023
1 parent 06962bf commit 8b2b112
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions personalchannels/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import asyncio
import io
from textwrap import shorten
from typing import Dict, Final, List, Literal, Optional, Union
from tabulate import tabulate
from typing import Dict, Final, List, Literal, Optional, Union, Any

import discord
from discord.ext.commands._types import Check
Expand All @@ -39,7 +40,6 @@
from redbot.core.utils.mod import get_audit_reason
from redbot.core.utils.predicates import MessagePredicate
from redbot.core.utils.views import SimpleMenu
from tabulate import tabulate

RequestType = Literal["discord_deleted_user", "owner", "user", "user_strict"]

Expand Down Expand Up @@ -608,7 +608,7 @@ async def _delete(self, ctx: commands.Context):
)
try:
pred = MessagePredicate.yes_or_no(ctx, user=ctx.author)
await ctx.bot.wait_for("message", check=pred, timeout=20)
await self.bot.wait_for("message", check=pred, timeout=20)
except asyncio.TimeoutError:
await ctx.send("Exiting operation.")
return
Expand Down Expand Up @@ -679,3 +679,10 @@ async def on_member_remove(self, member: discord.Member):
if member.id in data["friends"]:
data["friends"].remove(member.id)
await self.config.member_from_ids(member.guild.id, member_id).set(data)

@commands.Cog.listener()
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel):
all_data: Dict[int, Any] = await self.config.all_members(guild=channel.guild)
for member_id, data in all_data.items():
if channel.id in data["channel"]: # type: ignore
await self.config.member_from_ids(channel.guild.id, member_id).clear()

0 comments on commit 8b2b112

Please sign in to comment.