This commit is contained in:
2025-08-16 18:55:07 +02:00
parent 5204c257cf
commit 340a2e706b
+4 -1
View File
@@ -31,18 +31,21 @@ class LatexModule(commands.Cog):
) )
@commands.has_any_role(*ALLOWED_ROLES) @commands.has_any_role(*ALLOWED_ROLES)
async def tex(self, ctx: commands.Context, include_source_excerpt: Optional[bool] = True): async def tex(self, ctx: commands.Context, include_source_excerpt: Optional[bool] = True):
self.logger.info("LaTeX command invoked by %s", ctx.author)
ch = ctx.message.channel ch = ctx.message.channel
async with ch.typing(): async with ch.typing():
atts = [a for a in (ctx.message.attachments or []) if is_tex_attachment(a, LATEX_MAX_ATTACH_MB)] atts = [a for a in (ctx.message.attachments or []) if is_tex_attachment(a, LATEX_MAX_ATTACH_MB)]
if not atts: if not atts:
return await ctx.reply(f"Dołącz .tex (≤{LATEX_MAX_ATTACH_MB} MiB).", mention_author=False) return await ctx.reply(f"Dołącz .tex (≤{LATEX_MAX_ATTACH_MB} MiB).", mention_author=False)
self.logger.debug("LaTeX attachments: %s", ", ".join(a.filename for a in atts))
files: List[discord.File] = [] files: List[discord.File] = []
parts: List[str] = [] parts: List[str] = []
for att in atts: for att in atts:
try: try:
data = await att.read() data = await att.read()
self.logger.debug("LaTeX read %s bytes from %s", len(data), att.filename)
res = await compile_single_tex_bytes(data, att.filename, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger) res = await compile_single_tex_bytes(data, att.filename, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger)
self.logger.debug("LaTeX result for %s: %s", att.filename, res)
self.logger.debug("LaTeX log (%s)\n%s", att.filename, (res["log_text"] or "")[-2000:]) self.logger.debug("LaTeX log (%s)\n%s", att.filename, (res["log_text"] or "")[-2000:])
if res["ok"] and res["pdf_bytes"]: if res["ok"] and res["pdf_bytes"]:
b = io.BytesIO(res["pdf_bytes"]) b = io.BytesIO(res["pdf_bytes"])