posts "question of the day" to a discord webhook

Added author and "by" field to embed, added URL button

+35 -4
+1 -1
main.ts
··· 37 37 } 38 38 39 39 // Post to Discord webhook 40 - await sendDiscordNotification(data[index].question); 40 + await sendDiscordNotification(data[index].question, data[index].by); 41 41 console.log(`Cron: posted question of index ${index} to Discord.`); 42 42 });
+34 -3
utils/discordUtils.ts
··· 2 2 3 3 await load({ export: true }); 4 4 5 - export async function sendDiscordNotification(quote: string) { 5 + export async function sendDiscordNotification(question: string, by?: string) { 6 6 const embed1 = { 7 7 color: 0xFEF250, // lemon yellow 8 8 image: { url: Deno.env.get("IMAGE_URL") }, 9 9 }; 10 10 11 11 const embed2 = { 12 + author: { 13 + name: ".•° ✿ °•. punchy .•° ✿ °•.", 14 + url: "https://tangled.sh/@timtinkers.online/discord-qotd-webhook", 15 + }, 12 16 title: `· · ─ ·𝒒𝒖𝒆𝒔𝒕𝒊𝒐𝒏 𝒐𝒇 𝒕𝒉𝒆 𝒅𝒂𝒚 · ─ · ·`, 13 17 color: 0xFEF250, // lemon yellow 14 - description: quote, 18 + description: question, 19 + fields: [] as Array<{ name: string; value: string; inline: boolean }>, 15 20 thumbnail: { url: Deno.env.get("THUMBNAIL_URL") }, 16 21 footer: { text: `𐔌՞. .՞𐦯` }, 17 22 }; 18 23 19 - const response = await fetch(Deno.env.get("DISCORD_WEBHOOK_URL")!, { 24 + if (by) { 25 + embed2.fields.push( 26 + { 27 + name: "question by:", 28 + value: by, 29 + inline: true, 30 + }, 31 + ); 32 + } 33 + 34 + const button = { 35 + "type": 1, // ComponentType.ACTION_ROW 36 + "components": [ 37 + { 38 + type: 2, // ComponentType.BUTTON, 39 + label: "Suggest question", 40 + style: 5, // link 41 + url: Deno.env.get("SUGGESTION_FORM_URL"), 42 + }, 43 + ], 44 + }; 45 + 46 + const webhookUrl = new URL(Deno.env.get("DISCORD_WEBHOOK_URL")!); 47 + webhookUrl.searchParams.set("with_components", "true"); 48 + 49 + const response = await fetch(webhookUrl, { 20 50 method: "POST", 21 51 headers: { 22 52 "Content-Type": "application/json", 23 53 }, 24 54 body: JSON.stringify({ 25 55 embeds: [embed1, embed2], 56 + components: [button], 26 57 }), 27 58 }); 28 59