From a7337fbf64c5c0ed85cf22aa241754e607ccf694 Mon Sep 17 00:00:00 2001 From: Alex | Kronox <39801116+Kr0nox@users.noreply.github.com> Date: Fri, 19 May 2023 23:29:54 +0200 Subject: [PATCH] Added emojis (#111) * Added emojis * removed whitespace --- modules/mensa/mensaParser.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/mensa/mensaParser.ts b/modules/mensa/mensaParser.ts index 4bb3a41..0bd0616 100644 --- a/modules/mensa/mensaParser.ts +++ b/modules/mensa/mensaParser.ts @@ -28,10 +28,12 @@ export function buildMensaEmbed(foodPlan: CanteenLine[]): EmbedBuilder { for (const line of foodPlan) { if (line.meals.length > 0) { const content = line.meals.map(e => { + let emoji = getClassificationEmoji(e.classifiers); + emoji += emoji != '' ? ' ' : ''; if (e.price !== "") { - return `${e.name} (${e.price})`; + return `${emoji}${e.name} (${e.price})`; } else { - return `_${e.name}_`; + return `${emoji} _${e.name}_`; } }).join("\n"); embed.addFields({name: line.name, value: content, inline: true}); @@ -45,3 +47,28 @@ export function buildMensaEmbed(foodPlan: CanteenLine[]): EmbedBuilder { return embed; } + +/** + * Generates the emoji representation of the given classifiers of a meal + * + * @param classification Classifiers of meal + * @returns Emoji of the classifiers + */ +function getClassificationEmoji(classification: string[]): string { + if (classification.length == 0) { + return ''; + } + if (classification.includes('VG')) { + return ':ear_of_rice:'; + } + if (classification.includes('VEG')) { + return ':carrot:'; + } + if (classification.includes('S') || classification[0].startsWith('S')) { + return ':pig:'; + } + if (classification.includes('R') || classification[0].startsWith('R')) { + return ':cow:'; + } + return ''; +} \ No newline at end of file