Difficulty and Topic Display Update
This commit is contained in:
@@ -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." });
|
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) {
|
if (!imagePath) {
|
||||||
// Log error to logs channel
|
// Log error to logs channel
|
||||||
|
|||||||
@@ -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." });
|
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) {
|
if (!imagePath) {
|
||||||
// Log error to logs channel
|
// Log error to logs channel
|
||||||
|
|||||||
@@ -92,14 +92,30 @@ export default class Typst {
|
|||||||
return result;
|
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 = `
|
const styledCode = `
|
||||||
#set page(width: 210mm, height: auto, margin: (x: 20pt, y: 25pt), fill: white)
|
#set page(width: 210mm, height: auto, margin: (x: 20pt, y: 25pt), fill: white)
|
||||||
#set text(size: 16pt, font: "New Computer Modern")
|
#set text(size: 16pt, font: "New Computer Modern")
|
||||||
#set par(justify: true, leading: 0.65em)
|
#set par(justify: true, leading: 0.65em)
|
||||||
#set block(spacing: 1.2em)
|
#set block(spacing: 1.2em)
|
||||||
|
|
||||||
${typstCode}
|
${metadataHeader}${typstCode}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await this.compile(styledCode, { cleanup: false });
|
const result = await this.compile(styledCode, { cleanup: false });
|
||||||
|
|||||||
Reference in New Issue
Block a user