Logging emoji name updates + reformatting

pull/9/head
sgoudham 4 years ago
parent bd4f8405b6
commit a689c763a4

@ -1018,44 +1018,63 @@ class Moderation(Cog):
if modlogs := self.bot.get_modlog_for_guild(guild.id): if modlogs := self.bot.get_modlog_for_guild(guild.id):
modlogs_channel = self.bot.get_channel(modlogs) modlogs_channel = self.bot.get_channel(modlogs)
# Retrieve the emoji that were removed/added to the guild # Logging emoji additions/deletions
new_emojis = [emojis for emojis in after if emojis not in before] if before != after:
old_emojis = [emojis for emojis in before if emojis not in after] # Retrieve the emoji that were removed/added to the guild
new_emojis = [emojis for emojis in after if emojis not in before]
# Assuming that only one emoji is returned all the time old_emojis = [emojis for emojis in before if emojis not in after]
new_emojis_string = str(new_emojis[0]) if new_emojis else None
old_emojis_string = str(old_emojis[0]) if old_emojis else None # Determining whether emoji was added or removed
if len(new_emojis) == 1:
# Determining whether emoji was added or removed text = "Emoji Added"
if len(new_emojis) == 1: emoji_id = new_emojis[0].id
field = ("Emoji Added", new_emojis_string, False) name = new_emojis[0].name
emoji_id = new_emojis[0].id animated = self.bot.tick if new_emojis[0].animated else self.bot.cross
animated = self.bot.tick if new_emojis[0].animated else self.bot.cross managed = self.bot.tick if new_emojis[0].managed else self.bot.cross
managed = self.bot.tick if new_emojis[0].managed else self.bot.cross url = new_emojis[0].url
url = new_emojis[0].url if len(old_emojis) == 1:
if len(old_emojis) == 1: text = "Emoji Removed"
field = ("Emoji Removed", old_emojis_string, False) emoji_id = old_emojis[0].id
emoji_id = old_emojis[0].id name = old_emojis[0].name
animated = self.bot.tick if old_emojis[0].animated else self.bot.cross animated = self.bot.tick if old_emojis[0].animated else self.bot.cross
managed = self.bot.tick if old_emojis[0].managed else self.bot.cross managed = self.bot.tick if old_emojis[0].managed else self.bot.cross
url = old_emojis[0].url url = old_emojis[0].url
# Get total emojis # Get total emojis
emojis = string_list(after, 30, "Emoji") emojis = string_list(after, 30, "Emoji")
embed = Embed(title=field[0], embed = Embed(title=text,
description=f"**ID -->** {emoji_id}" description=f"**ID -->** {emoji_id}"
f"\n**Animated? -->** {animated}" f"\n**Name -->** {name}"
f"\n**Managed? -->** {managed}", f"\n**Animated? -->** {animated}"
colour=self.bot.admin_colour, f"\n**Managed? -->** {managed}",
url=str(url), colour=self.bot.admin_colour,
timestamp=datetime.datetime.utcnow()) url=str(url),
embed.set_author(name=guild, icon_url=guild.icon_url) timestamp=datetime.datetime.utcnow())
embed.add_field(name=field[0], value=field[1], inline=field[2]) embed.set_author(name=guild, icon_url=guild.icon_url)
embed.add_field(name=f"All Emojis --> {len(guild.emojis)}", value=emojis or "No Emojis", inline=False) embed.add_field(name=f"All Emojis --> {len(guild.emojis)}", value=emojis or "No Emojis", inline=False)
embed.set_thumbnail(url=str(url)) embed.set_thumbnail(url=str(url))
embed.set_footer(text=field[0]) embed.set_footer(text=text)
await modlogs_channel.send(embed=embed) await modlogs_channel.send(embed=embed)
# Log emoji name updates
elif before is not after:
for b, a in zip(before, after):
if b.name != a.name:
embed = Embed(title="Name Updated",
description=f"**ID -->** {a.id}"
f"\n**Name -->** {a.name}"
f"\n**Animated? -->** {a.animated}"
f"\n**Managed? -->** {a.managed}",
colour=self.bot.admin_colour,
url=str(a.url),
timestamp=datetime.datetime.utcnow())
embed.set_author(name=guild, icon_url=guild.icon_url)
embed.set_thumbnail(url=str(a.url))
embed.set_footer(text="Name Updated")
await modlogs_channel.send(embed=embed)
break
def setup(bot): def setup(bot):

Loading…
Cancel
Save