60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
import math
|
|
import os
|
|
import discord
|
|
|
|
|
|
async def send_message_with_embed(
|
|
message: discord.Message, files, title: str, tmp_dir: str, url: str
|
|
):
|
|
to_send_files = []
|
|
to_send_embeds = []
|
|
|
|
for file in files:
|
|
joined = os.path.join(tmp_dir, file)
|
|
embed = discord.Embed(url=url)
|
|
embed.set_image(url=f"attachment://{file}")
|
|
to_send_files.append(discord.File(joined, file))
|
|
to_send_embeds.append(embed)
|
|
if len(to_send_embeds) > 4:
|
|
parts = math.ceil(len(to_send_embeds) / 4)
|
|
i = 1
|
|
while len(to_send_embeds) > 4:
|
|
splited_file = to_send_files[:4]
|
|
to_send_files = to_send_files[4:]
|
|
splited_embed = to_send_embeds[:4]
|
|
to_send_embeds = to_send_embeds[4:]
|
|
for embed in splited_embed:
|
|
embed.title = f"{title} - Part {i}/{parts}"
|
|
if i == 1:
|
|
await message.reply(files=splited_file, embeds=splited_embed)
|
|
else:
|
|
await message.channel.send(files=splited_file, embeds=splited_embed)
|
|
i = i + 1
|
|
for embed in to_send_embeds:
|
|
embed.title = f"{title} - Part {i}/{parts}"
|
|
await message.channel.send(files=to_send_files, embeds=to_send_embeds)
|
|
else:
|
|
for embed in to_send_embeds:
|
|
embed.title = title
|
|
await message.reply(files=to_send_files, embeds=to_send_embeds)
|
|
|
|
|
|
async def send_message(message: discord.Message, files, tmp_dir: str):
|
|
to_send_files = []
|
|
for file in files:
|
|
joined = os.path.join(tmp_dir, file)
|
|
to_send_files.append(discord.File(joined, file))
|
|
if len(to_send_files) > 10:
|
|
first = True
|
|
while len(to_send_files) > 10:
|
|
splited_file = to_send_files[:4]
|
|
to_send_files = to_send_files[4:]
|
|
if first:
|
|
await message.reply(files=splited_file)
|
|
first = False
|
|
else:
|
|
await message.channel.send(files=splited_file)
|
|
await message.channel.send(files=to_send_files)
|
|
else:
|
|
await message.reply(files=to_send_files)
|