Fixed bug in lists cog.
This commit is contained in:
parent
ce74bbe138
commit
6bc7a0c4aa
1 changed files with 77 additions and 16 deletions
|
@ -88,6 +88,42 @@ class Lists(Cog):
|
||||||
|
|
||||||
await message.edit(embed=None)
|
await message.edit(embed=None)
|
||||||
|
|
||||||
|
async def cache_message(self, message):
|
||||||
|
msg = {
|
||||||
|
"has_attachment": False,
|
||||||
|
"attachment_filename": "",
|
||||||
|
"attachment_data": b"",
|
||||||
|
"content": message.content,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(message.attachments) != 0:
|
||||||
|
attachment = next(
|
||||||
|
(
|
||||||
|
a
|
||||||
|
for a in message.attachments
|
||||||
|
if a.filename.endswith(".png")
|
||||||
|
or a.filename.endswith(".jpg")
|
||||||
|
or a.filename.endswith(".jpeg")
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
if attachment is not None:
|
||||||
|
msg["has_attachment"] = True
|
||||||
|
msg["attachment_filename"] = attachment.filename
|
||||||
|
msg["attachment_data"] = await attachment.read()
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
|
async def send_cached_message(self, channel, message):
|
||||||
|
if message["has_attachment"] == True:
|
||||||
|
file = discord.File(
|
||||||
|
io.BytesIO(message["attachment_data"]),
|
||||||
|
filename=message["attachment_filename"],
|
||||||
|
)
|
||||||
|
await channel.send(content=message["content"], file=file)
|
||||||
|
else:
|
||||||
|
await channel.send(content=message["content"])
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
|
|
||||||
@commands.command(aliases=["list"])
|
@commands.command(aliases=["list"])
|
||||||
|
@ -285,14 +321,17 @@ class Lists(Cog):
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self.is_recycle(targeted_reaction):
|
elif self.is_recycle(targeted_reaction):
|
||||||
messages = await channel.history(
|
messages = [await self.cache_message(targeted_message)]
|
||||||
|
|
||||||
|
for message in await channel.history(
|
||||||
limit=None, after=targeted_message, oldest_first=True
|
limit=None, after=targeted_message, oldest_first=True
|
||||||
).flatten()
|
).flatten():
|
||||||
|
messages.append(await self.cache_message(message))
|
||||||
|
|
||||||
await channel.purge(limit=len(messages) + 1, bulk=True)
|
await channel.purge(limit=len(messages) + 1, bulk=True)
|
||||||
|
|
||||||
await channel.send(targeted_message.content)
|
|
||||||
for message in messages:
|
for message in messages:
|
||||||
await channel.send(message.content)
|
await self.send_cached_message(channel, message)
|
||||||
|
|
||||||
await log_channel.send(
|
await log_channel.send(
|
||||||
self.create_log_message(
|
self.create_log_message(
|
||||||
|
@ -301,30 +340,52 @@ class Lists(Cog):
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self.is_insert_above(targeted_reaction):
|
elif self.is_insert_above(targeted_reaction):
|
||||||
messages = await channel.history(
|
messages = [await self.cache_message(targeted_message)]
|
||||||
|
|
||||||
|
for message in await channel.history(
|
||||||
limit=None, after=targeted_message, oldest_first=True
|
limit=None, after=targeted_message, oldest_first=True
|
||||||
).flatten()
|
).flatten():
|
||||||
|
messages.append(await self.cache_message(message))
|
||||||
|
|
||||||
await channel.purge(limit=len(messages) + 1, bulk=True)
|
await channel.purge(limit=len(messages) + 1, bulk=True)
|
||||||
|
|
||||||
|
if attachment_filename is not None and attachment_data is not None:
|
||||||
|
file = discord.File(
|
||||||
|
io.BytesIO(attachment_data), filename=attachment_filename
|
||||||
|
)
|
||||||
|
await channel.send(content=content, file=file)
|
||||||
|
else:
|
||||||
await channel.send(content)
|
await channel.send(content)
|
||||||
await channel.send(targeted_message.content)
|
|
||||||
for message in messages:
|
for message in messages:
|
||||||
await channel.send(message.content)
|
await self.send_cached_message(channel, message)
|
||||||
|
|
||||||
await log_channel.send(
|
await log_channel.send(
|
||||||
self.create_log_message("💬", "List item added:", user, channel)
|
self.create_log_message("💬", "List item added:", user, channel)
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self.is_insert_below(targeted_reaction):
|
elif self.is_insert_below(targeted_reaction):
|
||||||
messages = await channel.history(
|
await targeted_reaction.remove(user)
|
||||||
limit=None, after=targeted_message, oldest_first=True
|
|
||||||
).flatten()
|
|
||||||
await channel.purge(limit=len(messages) + 1, bulk=True)
|
|
||||||
|
|
||||||
await channel.send(targeted_message.content)
|
messages = []
|
||||||
|
|
||||||
|
for message in await channel.history(
|
||||||
|
limit=None, after=targeted_message, oldest_first=True
|
||||||
|
).flatten():
|
||||||
|
messages.append(await self.cache_message(message))
|
||||||
|
|
||||||
|
await channel.purge(limit=len(messages), bulk=True)
|
||||||
|
|
||||||
|
if attachment_filename is not None and attachment_data is not None:
|
||||||
|
file = discord.File(
|
||||||
|
io.BytesIO(attachment_data), filename=attachment_filename
|
||||||
|
)
|
||||||
|
await channel.send(content=content, file=file)
|
||||||
|
else:
|
||||||
await channel.send(content)
|
await channel.send(content)
|
||||||
|
|
||||||
for message in messages:
|
for message in messages:
|
||||||
await channel.send(message.content)
|
await self.send_cached_message(channel, message)
|
||||||
|
|
||||||
await log_channel.send(
|
await log_channel.send(
|
||||||
self.create_log_message("💬", "List item added:", user, channel)
|
self.create_log_message("💬", "List item added:", user, channel)
|
||||||
|
|
Loading…
Reference in a new issue