feat(aurora): added a listener to readd roles to a user on guild join

This commit is contained in:
Seaswimmer 2024-05-03 20:10:26 -04:00
parent f6b827c64f
commit ebf739b563
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -122,6 +122,20 @@ class Aurora(commands.Cog):
except ConnectionRefusedError:
return
@commands.Cog.listener("on_member_join")
async def addrole_on_member_join(self, member: discord.Member):
"""This method automatically adds roles to users when they join the server."""
if not await self.bot.cog_disabled_in_guild(self, member.guild):
query = f"""SELECT moderation_id, role_id, reason FROM moderation_{member.guild.id} WHERE target_id = ? AND action = 'ADDROLE' AND expired = 0 AND resolved = 0;"""
database = connect()
cursor = database.cursor()
cursor.execute(query, (member.id,))
results = cursor.fetchall()
for result in results:
role = member.guild.get_role(result[1])
reason = result[2]
await member.add_roles(role, reason=f"Role automatically added on member rejoin for: {reason} (Case #{result[0]:,})")
@commands.Cog.listener("on_audit_log_entry_create")
async def autologger(self, entry: discord.AuditLogEntry):
"""This method automatically logs moderations done by users manually ("right clicks")."""