Difficulty and Topic Display Update

This commit is contained in:
2025-11-23 14:10:47 -05:00
parent bb6a4887c2
commit a44babed9f
3 changed files with 26 additions and 4 deletions

View File

@@ -45,7 +45,10 @@ export default class DailyCommand extends BotCommand {
return interaction.editReply({ content: "You've already submitted an answer for today's question! Check back tomorrow." });
}
const imagePath = await client.typst.renderToImage(question.typst_source);
const imagePath = await client.typst.renderToImage(question.typst_source, {
topic: question.topic,
difficulty: question.difficulty_rating
});
if (!imagePath) {
// Log error to logs channel

View File

@@ -45,7 +45,10 @@ export default class WeeklyCommand extends BotCommand {
return interaction.editReply({ content: "You've already submitted an answer for this week's question! Check back next Sunday." });
}
const imagePath = await client.typst.renderToImage(question.typst_source);
const imagePath = await client.typst.renderToImage(question.typst_source, {
topic: question.topic,
difficulty: question.difficulty_rating
});
if (!imagePath) {
// Log error to logs channel

View File

@@ -92,14 +92,30 @@ export default class Typst {
return result;
}
async renderToImage(typstCode: string): Promise<string | null> {
async renderToImage(typstCode: string, metadata?: { topic?: string; difficulty?: string }): Promise<string | null> {
const metadataHeader = metadata ? `
#align(center)[
#block(
fill: rgb("#e0f2fe"),
inset: 10pt,
radius: 4pt,
[
#text(weight: "bold", size: 14pt)[Topic: ${metadata.topic || "N/A"}] \
#text(size: 12pt, fill: rgb("#64748b"))[Difficulty: ${metadata.difficulty || "N/A"}]
]
)
]
#v(0.8em)
` : '';
const styledCode = `
#set page(width: 210mm, height: auto, margin: (x: 20pt, y: 25pt), fill: white)
#set text(size: 16pt, font: "New Computer Modern")
#set par(justify: true, leading: 0.65em)
#set block(spacing: 1.2em)
${typstCode}
${metadataHeader}${typstCode}
`;
const result = await this.compile(styledCode, { cleanup: false });