Skip to content

Commit

Permalink
remove role mapping on role deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
LBlend committed Oct 28, 2024
1 parent 9212e3a commit 10aa23a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/cogs/rank_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import dataclasses
from datetime import datetime, timedelta

import discord
Expand Down Expand Up @@ -137,6 +138,27 @@ async def on_member_join(self, member: discord.Member):
else:
self.bot.logger.info(f'Rank not updated for user ({member.id}) - {update["reason"]}')

@commands.Cog.listener('on_guild_role_delete')
async def on_guild_role_delete(self, role: discord.Role):
"""
Clear database mapping if role is deleted
Parameters
----------
role (discord.Role): Role instance
"""

guild = await database.GuildTable().get(role.guild.id)
if not guild:
return

attributes = dataclasses.asdict(guild)
for key, value in attributes.items():
if value == role.id:
setattr(guild, key, None)

self.bot.logger.info(f'Registered role {role.id} deleted! Removed the mapping!')


async def setup(bot: commands.Bot):
"""
Expand Down

0 comments on commit 10aa23a

Please sign in to comment.