diff --git a/code/cogs/chat.py b/code/cogs/chat.py index 00472d3..502e026 100644 --- a/code/cogs/chat.py +++ b/code/cogs/chat.py @@ -9,7 +9,8 @@ class MyModal(discord.ui.Modal): def __init__(self, message): super().__init__(title="Downvote") self.add_item( - discord.ui.InputText(label="Reason", style=discord.InputTextStyle.long) + discord.ui.InputText( + label="Reason", style=discord.InputTextStyle.long) ) self.message = message @@ -30,26 +31,35 @@ class MyModal(discord.ui.Modal): description=f"Downvote recieved!", color=discord.Color.og_blurple(), ) - embed.add_field(name="Reason", value=self.children[0].value, inline=True) - embed.add_field(name="Author", value=interaction.user.mention, inline=True) + + embed.add_field( + name="Reason", value=self.children[0].value, inline=True) + embed.add_field( + name="Author", value=interaction.user.mention, inline=True) embed.add_field( name="Channel", value=self.message.channel.name, inline=True ) - embed.add_field(name="Guild", value=self.message.guild.name, inline=True) + embed.add_field( + name="Guild", value=self.message.guild.name, inline=True) + history = await self.message.channel.history( limit=5, before=self.message ).flatten() history.reverse() + users = [] fake_users = [] + for user in history: if user.author not in users: # we anonimize the user, so user1, user2, user3, etc fake_users.append(f"user{len(fake_users)+1}") users.append(user.author) + if self.message.author not in users: fake_users.append(f"user{len(fake_users)+1}") users.append(self.message.author) + for msg in history: uname = fake_users[users.index(msg.author)] @@ -61,20 +71,15 @@ class MyModal(discord.ui.Modal): embed.add_field( name=f"{uname} said", value=msg.content, inline=False ) - if len(self.message.content) > 1021: - uname = fake_users[users.index(self.message.author)] - embed.add_field( - name=f"{uname} said", - value="*" + self.message.content[:1021] + "*", - inline=False, - ) - else: - uname = fake_users[users.index(self.message.author)] - embed.add_field( - name=f"{uname} said", - value="*" + self.message.content + "*", - inline=False, - ) + + uname = fake_users[users.index(self.message.author)] + embed.add_field( + name=f"{uname} said", + value="*" + self.message.content[:1021] + "*" if len( + self.message.content) > 1021 else "*" + self.message.content + "*", # [:1021] if len(self.message.content) > 1021, + # means that if the message is longer than 1021 characters, it will be cut at 1021 characters + inline=False, + ) await webhook.send(embed=embed) else: debug(