async def on_message_edit(self, message_before, message_after): if not (message_before.content == message_after.content): webhook = await self._get_webhook(message_after.guild, 'message_log') if not webhook: return if message_after.author.bot: return embed = log_embed_warn( 'Message Edited', self.bot ) embed.add_field( name='Before:', value=message_before.content, inline=False) embed.add_field( name='After:', value=message_after.content, inline=False) embed.set_footer( text=f'Message ID: {message_after.id}', icon_url=message_after.author.avatar_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed )
async def on_guild_emojis_update(self, guild, emojis_before, emojis_after): webhook = await self._get_webhook(guild, 'server_log') if not webhook: return embed = log_embed_warn( 'Emojis updated', self.bot ) new_emojis = [ emoji for emoji in emojis_after if emoji not in emojis_before] removed_emojis = [ emoji for emoji in emojis_before if emoji not in emojis_after] if len(emojis_before) < len(emojis_after): # new emojis embed.add_field(name='Emojis Added:', value=', '.join( [str(emoji) for emoji in new_emojis]), inline=False) embed.set_footer( text=f'Total emojis: {len(emojis_after)}', icon_url=guild.icon_url) embed.set_thumbnail(url=guild.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) else: # emojis got removed embed.add_field(name='Emojis Deleted:', value=', '.join( [str(emoji) for emoji in removed_emojis]), inline=False) embed.set_footer( text=f'Total emojis: {len(emojis_after)}', icon_url=guild.icon_url) embed.set_thumbnail(url=guild.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed )
async def on_message(self, message): if message.author == self.bot.user: return invite_matches = re.findall(self.invite_regex, message.content) if invite_matches: invite_matches = list(dict.fromkeys( invite_matches)) # to remove duplicates for invite_match in invite_matches: try: invite = await self.bot.fetch_invite(invite_match) except: return webhook = await self._get_webhook(message.guild, 'message_log') if not webhook: return embed = log_embed_warn( 'Invite link detected', self.bot ) embed.add_field(name='ID:', value=invite.id, inline=True) embed.add_field(name='Guild:', value=invite.guild.name, inline=True) embed.add_field(name='Inviter:', value=invite.inviter, inline=True) embed.add_field(name='Members:', value=invite.approximate_member_count) embed.add_field(name='URL', value=invite.url) embed.set_footer( text=f'Channel: {message.channel.name}', icon_url=message.author.avatar_url) embed.set_thumbnail(url=invite.guild.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed )
async def on_guild_role_update(self, role_before, role_after): guild = role_after.guild webhook = await self._get_webhook(guild, 'server_log') if not webhook: return embed = log_embed_warn( 'Role updated', self.bot ) embed.add_field(name='Name:', value=role_after.name, inline=True) embed.set_footer( text=f'Role ID: {role_after.id}', icon_url=guild.icon_url) embed.set_thumbnail(url=guild.icon_url) if not (role_before.name == role_after.name): # name update embed.add_field( name='Name update:', value=f'**Before**: {role_before.name}\n**After**: {role_after.name}', inline=False) if not (role_before.hoist == role_after.hoist): # hoist update embed.add_field( name='Hoist update:', value=f'**Before**: {role_before.hoist}\n**After**: {role_after.hoist}', inline=False) if not (role_before.mentionable == role_after.mentionable): # mentionable update embed.add_field( name='Mentionable update:', value=f'**Before**: {role_before.mentionable}\n**After**: {role_after.mentionable}', inline=False) if not (role_before.color == role_after.color): # color update embed.add_field( name='Color update:', value=f'**Before**: {role_before.color}\n**After**: {role_after.color}', inline=False) if not (role_before.permissions == role_after.permissions): # role permissions update old_perms = list(iter(role_before.permissions)) new_perms = list(iter(role_after.permissions)) changed_perms = [] for i, perm in enumerate(new_perms): if perm != old_perms[i]: changed_perms.append(perm) changed_perms_string = '' for perm in changed_perms: to_be_added = f'`{perm[0]}`: ' if perm[1] is None: to_be_added += 'Overwrites removed' else: to_be_added += 'Allowed' if perm[1] else 'Denied' to_be_added += '\n' changed_perms_string += to_be_added embed.add_field( name='Perms update:', value=changed_perms_string, inline=False) await send_webhook( webhook.url, self.bot.aio_session, embed=embed )
async def on_guild_update(self, guild_before, guild_after): webhook = await self._get_webhook(guild_after, 'server_log') if not webhook: return embed = log_embed_warn( 'Guild update', self.bot ) if not (guild_before.name == guild_after.name): # name update embed.add_field(name='Name:', value=guild_after.name, inline=True) embed.add_field( name='Name update:', value=f'**Before**: {guild_before.name}\n**After**: {guild_after.name}', inline=False) embed.set_footer( text=f'Guild ID: {guild_after.id}', icon_url=guild_after.icon_url) embed.set_thumbnail(url=guild_after.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (guild_before.region == guild_after.region): # region update embed.add_field(name='Name:', value=guild_after.name, inline=True) embed.add_field( name='Region update:', value=f'**Before**: {guild_before.region}\n**After**: {guild_after.region}', inline=False) embed.set_footer( text=f'Guild ID: {guild_after.id}', icon_url=guild_after.icon_url) embed.set_thumbnail(url=guild_after.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (guild_before.icon == guild_after.icon): # icon update embed.add_field(name='Name:', value=guild_after.name, inline=True) embed.add_field( name='Icon update:', value=f'**Before**: {guild_before.icon_url}\n**After**: {guild_after.icon_url}', inline=False) embed.set_footer( text=f'Guild ID: {guild_after.id}', icon_url=guild_after.icon_url) embed.set_thumbnail(url=guild_after.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (guild_before.owner == guild_after.owner): # ownership update embed.add_field(name='Name:', value=guild_after.name, inline=True) embed.add_field( name='Ownership update:', value=f'**Before**: {guild_before.owner.name}\n**After**: {guild_after.owner.name}', inline=False) embed.set_footer( text=f'Guild ID: {guild_after.id}', icon_url=guild_after.icon_url) embed.set_thumbnail(url=guild_after.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (guild_before.verification_level == guild_after.verification_level): # verification_level update embed.add_field(name='Name:', value=guild_after.name, inline=True) embed.add_field( name='Verification level update:', value=f'**Before**: {guild_before.verification_level}\n**After**: {guild_after.verification_level}', inline=False) embed.set_footer( text=f'Guild ID: {guild_after.id}', icon_url=guild_after.icon_url) embed.set_thumbnail(url=guild_after.icon_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return
async def on_user_update(self, user_before, user_after): all_guilds = self.bot.guilds guilds_which_user_shares = [ guild for guild in all_guilds if user_after in guild.members] webhooks = [] for guild in guilds_which_user_shares: webhook = await self._get_webhook(guild, 'people_log') if not webhook: continue webhooks.append(webhook) if not webhooks: return embed = log_embed_warn( 'User updated', self.bot ) if not (user_before.name == user_after.name): # username update embed.add_field(name='Name:', value=user_after.name, inline=True) embed.add_field(name='Username update:', value=f'**Before**: {user_before.name}\n**After**: {user_after.name}', inline=False) embed.set_footer( text=f'User ID: {user_after.id}', icon_url=user_after.avatar_url) embed.set_thumbnail(url=user_after.avatar_url) for webhook in webhooks: await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (user_before.discriminator == user_after.discriminator): # discriminator update embed.add_field(name='Name:', value=user_after.name, inline=True) embed.add_field(name='Discriminator update:', value=f'**Before**: {user_before.discriminator}\n**After**: {user_after.discriminator}', inline=False) embed.set_footer( text=f'User ID: {user_after.id}', icon_url=user_after.avatar_url) embed.set_thumbnail(url=user_after.avatar_url) for webhook in webhooks: await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (user_before.avatar == user_after.avatar): # avatar update embed.add_field(name='Name:', value=user_after.name, inline=True) embed.add_field( name='Avatar update:', value=f'**Before**: {user_before.avatar_url}\n**After**: {user_after.avatar_url}', inline=False) embed.set_footer( text=f'User ID: {user_after.id}', icon_url=user_after.avatar_url) embed.set_thumbnail(url=user_after.avatar_url) for webhook in webhooks: await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return
async def on_member_update(self, member_before, member_after): webhook = await self._get_webhook(member_after.guild, 'people_log') if not webhook: return embed = log_embed_warn( 'Member update', self.bot ) if not (member_before.nick == member_after.nick): # nickname change embed.add_field(name='Name:', value=member_after.name, inline=True) embed.add_field(name='Nickname change:', value=f'**Before**: {member_before.nick}\n**After**: {member_after.nick}', inline=False) embed.set_footer( text=f'Member ID: {member_after.id}', icon_url=member_after.avatar_url) embed.set_thumbnail(url=member_after.avatar_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (member_before.roles == member_after.roles): new_roles = [ role for role in member_after.roles if role not in member_before.roles] removed_roles = [ role for role in member_before.roles if role not in member_after.roles] if len(member_before.roles) < len(member_after.roles): # added roles embed.add_field( name='Name:', value=member_after.name, inline=True) embed.add_field(name='Roles added:', value=', '.join( [role.mention for role in new_roles]), inline=False) embed.set_footer( text=f'Member ID: {member_after.id}', icon_url=member_after.avatar_url) embed.set_thumbnail(url=member_after.avatar_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) else: # removed roles embed.add_field( name='Name:', value=member_after.name, inline=True) embed.add_field(name='Roles removed:', value=', '.join( [role.mention for role in removed_roles]), inline=False) embed.set_footer( text=f'Member ID: {member_after.id}', icon_url=member_after.avatar_url) embed.set_thumbnail(url=member_after.avatar_url) await send_webhook( webhook.url, self.bot.aio_session, embed=embed )
async def on_guild_channel_update(self, channel_before, channel_after): webhook = await self._get_webhook(channel_after.guild, 'server_log') if not webhook: return embed = log_embed_warn( 'Channel updated', self.bot ) if not (channel_before.name == channel_after.name): embed.add_field( name='Name:', value=channel_before.name, inline=True) embed.add_field( name='Name Changed:', value=f'**Before**: {channel_before.name}\n**After**: {channel_after.name}', inline=False) embed.set_footer(text=f'Channel ID: {channel_after.id}') await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if str(channel_after.type) == 'text': if not (channel_before.topic == channel_after.topic): embed.add_field( name='Name:', value=channel_before.name, inline=True) embed.add_field( name='Topic Changed:', value=f'**Before**: {channel_before.topic}\n**After**: {channel_after.topic}', inline=False) embed.set_footer(text=f'Channel ID: {channel_after.id}') await send_webhook( webhook.url, self.bot.aio_session, embed=embed ) return if not (channel_before.overwrites == channel_after.overwrites): embed.add_field( name='Name:', value=channel_before.name, inline=True) overwrites_before = channel_before.overwrites overwrites_after = channel_after.overwrites ov_before_list_objs = list(overwrites_before.values()) new_ov = [ ov for ov in overwrites_after if ov not in overwrites_before] removed_ov = [ ov for ov in overwrites_before if ov not in overwrites_after] if new_ov: embed.add_field( name='Overwrites created', value=f'Permission overwrites created for `{new_ov[0]}`', inline=False) elif removed_ov: embed.add_field( name='Overwrites removed', value=f'Permission overwrites removed for `{removed_ov[0]}`', inline=False) else: role_or_member = None ov_modified_before = None ov_modified_after = None for i, ov in enumerate(overwrites_after.values()): if ov != ov_before_list_objs[i]: ov_modified_before = ov_before_list_objs[i] ov_modified_after = ov role_or_member = list(overwrites_after)[i] old_perms = list(iter(ov_modified_before)) new_perms = list(iter(ov_modified_after)) changed_perms = [] for i, perm in enumerate(new_perms): if perm != old_perms[i]: changed_perms.append(perm) changed_perms_string = '' for perm in changed_perms: to_be_added = f'`{perm[0]}`: ' if perm[1] is None: to_be_added += 'Overwrites removed' else: to_be_added += 'Allowed' if perm[1] else 'Denied' to_be_added += '\n' changed_perms_string += to_be_added embed.add_field(name='Permission overwrites updated:', value=f'Permission overwrites updated for `{role_or_member.name}`', inline=False) embed.add_field(name='Changes:', value=changed_perms_string, inline=False) embed.set_footer(text=f'Channel ID: {channel_after.id}') await send_webhook( webhook.url, self.bot.aio_session, embed=embed )