From d78c462a91f5120887038fcf67176d203148e809 Mon Sep 17 00:00:00 2001 From: Irvin Favors <93955643+IrvinFavors@users.noreply.github.com> Date: Mon, 28 Apr 2025 13:34:42 -0400 Subject: [PATCH 1/3] removing download option --- src/commands/general/tainfo.ts | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/commands/general/tainfo.ts b/src/commands/general/tainfo.ts index 6f1afab4..e3910f1b 100644 --- a/src/commands/general/tainfo.ts +++ b/src/commands/general/tainfo.ts @@ -7,8 +7,7 @@ import { ButtonStyle, ComponentType, EmbedBuilder, - DMChannel, - AttachmentBuilder + DMChannel } from 'discord.js'; import { Command } from '@lib/types/Command'; import 'dotenv/config'; @@ -103,15 +102,15 @@ export default class extends Command { const name = rawName.replace(/^Name:\s*/, '').trim(); const email = rawEmail.replace(/^Email:\s*/, '').trim(); return { - markdown: `**Name:** ${name} **Email:** ${email}`, - plain: `Name: ${name} Email: ${email}` + markdown: `**Name:** ${name} **Email:** ${email}` + // plain: `Name: ${name} Email: ${email}` }; }); // Set for embed const taSetMdEntries = taData.map((x) => x.markdown); // Set for downloadable text file - const taSetPlainEntries = taData.map((x) => x.plain); + // const taSetPlainEntries = taData.map((x) => x.plain); const pages = chunk(taSetMdEntries, NUM_ENTRIES_PER_PAGE); let pageIndex = 0; @@ -138,10 +137,6 @@ export default class extends Command { .setLabel('Next ➡') .setStyle(ButtonStyle.Secondary) .setDisabled(pageIndex === pages.length - 1), - new ButtonBuilder() - .setCustomId('download') - .setLabel('Download .txt') - .setStyle(ButtonStyle.Primary), new ButtonBuilder() .setCustomId('close') .setLabel('Close ✖️') @@ -184,18 +179,8 @@ export default class extends Command { embeds: [makeEmbed(pageIndex)], components: [makeRow()] }); - } else if (btn.customId === 'download') { - const content = taSetPlainEntries.join('\n'); - const file = new AttachmentBuilder( - Buffer.from(content, 'utf-8'), - { - name: `${className}_TAs.txt` - } - ); - return btn.reply({ files: [file], ephemeral: true }); } else if (btn.customId === 'close') { await btn.update({ - content: 'Paginator closed.', components: [] }); return dmCollector.stop(); @@ -217,11 +202,6 @@ export default class extends Command { .setLabel('Next ➡') .setStyle(ButtonStyle.Primary) .setDisabled(true), - new ButtonBuilder() - .setCustomId('download') - .setLabel('Download .txt') - .setStyle(ButtonStyle.Secondary) - .setDisabled(true), new ButtonBuilder() .setCustomId('close') .setLabel('Close ✖️') From 38023ea87770510856502c9af882e8b72d020637 Mon Sep 17 00:00:00 2001 From: Irvin Favors <93955643+IrvinFavors@users.noreply.github.com> Date: Wed, 30 Apr 2025 13:34:48 -0400 Subject: [PATCH 2/3] putting email on separate line from name --- src/commands/general/tainfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/general/tainfo.ts b/src/commands/general/tainfo.ts index e3910f1b..be3a84af 100644 --- a/src/commands/general/tainfo.ts +++ b/src/commands/general/tainfo.ts @@ -102,7 +102,7 @@ export default class extends Command { const name = rawName.replace(/^Name:\s*/, '').trim(); const email = rawEmail.replace(/^Email:\s*/, '').trim(); return { - markdown: `**Name:** ${name} **Email:** ${email}` + markdown: `**Name:** ${name}\n**Email:** ${email}` // plain: `Name: ${name} Email: ${email}` }; }); From 29e5d0cf63766fbf534dd30072b19edf54273805 Mon Sep 17 00:00:00 2001 From: Irvin Favors <93955643+IrvinFavors@users.noreply.github.com> Date: Sun, 4 May 2025 15:41:58 -0400 Subject: [PATCH 3/3] linter fixes and ui improvements --- src/commands/general/tainfo.ts | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/commands/general/tainfo.ts b/src/commands/general/tainfo.ts index be3a84af..c6800069 100644 --- a/src/commands/general/tainfo.ts +++ b/src/commands/general/tainfo.ts @@ -20,7 +20,6 @@ const CALENDAR_ID const EXPIRATION_TIME = 5 * 60 * 1000; // 5 minutes const NUM_ENTRIES_PER_PAGE = 5; - // Function to chunk an array into smaller ones; used for pagination function chunk(arr: T[], size: number): T[][] { const pages: T[][] = []; @@ -78,7 +77,9 @@ export default class extends Command { !ev.summary ?.toLowerCase() .includes(className.toLowerCase()) - ) { continue; } + ) { + continue; + } const name = ev.summary.split('-')[1]?.trim(); if (!name) continue; const email @@ -94,37 +95,40 @@ export default class extends Command { }); } - // Build dual arrays: markdown for embeds, plain for downloadable text file const taData = Array.from(taSet).map((line) => { const [rawName, rawEmail] = line .replace(/\*\*/g, '') // remove all asterisks for plain text .split(' '); - const name = rawName.replace(/^Name:\s*/, '').trim(); - const email = rawEmail.replace(/^Email:\s*/, '').trim(); return { - markdown: `**Name:** ${name}\n**Email:** ${email}` - // plain: `Name: ${name} Email: ${email}` + name: rawName.replace(/^Name:\s*/, '').trim(), + email: rawEmail.replace(/^Email:\s*/, '').trim() }; }); - // Set for embed - const taSetMdEntries = taData.map((x) => x.markdown); - // Set for downloadable text file - // const taSetPlainEntries = taData.map((x) => x.plain); - - const pages = chunk(taSetMdEntries, NUM_ENTRIES_PER_PAGE); + const pages = chunk(taData, NUM_ENTRIES_PER_PAGE); let pageIndex = 0; - const makeEmbed = (page: number) => - new EmbedBuilder() + const makeEmbed = (page: number) => { + const embed = new EmbedBuilder() .setTitle( `TAs for **${className}** (page ${page + 1}/${ pages.length })` ) - .setDescription(pages[page].join('\n\n')) .setColor('#0099ff'); + pages[page].forEach((ta) => + embed.addFields( + { name: 'Name', value: ta.name, inline: true }, + { name: 'Email', value: ta.email, inline: true }, + // Spacer for new line + { name: '\u200b', value: '\u200b', inline: true } + ) + ); + + return embed; + }; + const makeRow = () => new ActionRowBuilder().addComponents( new ButtonBuilder()