Spaces:
Runtime error

Codex commited on
Commit
a3d1dbb
·
1 Parent(s): 3587549

Reduce Circa embed page size

Browse files
Files changed (1) hide show
  1. src/embeds.js +37 -39
src/embeds.js CHANGED
@@ -515,55 +515,53 @@ function chunkLines(lines, maxLength = 1000) {
515
  return chunks;
516
  }
517
 
518
- export function buildCircaMarketEmbeds(snapshot, marketLabel, entries, options = {}) {
519
- const lines = entries.map((entry) => {
520
- const team = entry.team ? ` (${entry.team})` : '';
521
- const side = `${String(entry.side ?? '').toUpperCase()}${entry.lineValue !== null && entry.lineValue !== undefined ? ` ${entry.lineValue}` : ''}`;
522
- return `${entry.playerName}${team} | ${side} | ${entry.oddsInput}`;
523
- });
524
-
525
- const footerBase = options.footerText ?? 'Latest parsed Circa market snapshot';
526
- const allChunks = lines.length > 0 ? chunkLines(lines) : ['No parsed props were available for this market.'];
527
- const embeds = [];
528
- let currentChunks = [];
529
  let currentLength = 0;
530
 
531
- for (const chunk of allChunks) {
532
- const fieldName = currentChunks.length === 0 ? 'Props' : `Props ${currentChunks.length + 1}`;
533
- const fieldLength = fieldName.length + chunk.length;
534
- const hasRoomForAnotherField = currentChunks.length < 5 && currentLength + fieldLength <= 4800;
535
-
536
- if (!hasRoomForAnotherField && currentChunks.length > 0) {
537
- embeds.push(currentChunks);
538
- currentChunks = [chunk];
539
- currentLength = 'Props'.length + chunk.length;
540
  } else {
541
- currentChunks.push(chunk);
542
- currentLength += fieldLength;
543
  }
544
  }
545
 
546
- if (currentChunks.length > 0) {
547
- embeds.push(currentChunks);
548
  }
549
 
550
- return embeds.map((chunks, pageIndex) => {
551
- const embed = new EmbedBuilder()
552
- .setColor(PALETTE.gold)
553
- .setTitle(`Circa ${marketLabel}${embeds.length > 1 ? ` (${pageIndex + 1}/${embeds.length})` : ''}`)
554
- .setDescription(`Source file: **${snapshot.fileName ?? 'Unknown'}**`)
555
- .setFooter({ text: `${footerBase}${embeds.length > 1 ? ` | Page ${pageIndex + 1}/${embeds.length}` : ''}` });
556
-
557
- embed.addFields(
558
- chunks.map((value, index) => ({
559
- name: pageIndex === 0 && index === 0 ? 'Props' : `Props ${pageIndex * 5 + index + 1}`,
560
- value,
561
- inline: false,
562
- }))
563
- );
564
 
565
- return embed;
 
 
 
 
566
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  }
568
 
569
  export function buildCircaMovementEmbed(movement, snapshot) {
 
515
  return chunks;
516
  }
517
 
518
+ function chunkTextPages(lines, maxLength = 3400) {
519
+ const pages = [];
520
+ let current = [];
 
 
 
 
 
 
 
 
521
  let currentLength = 0;
522
 
523
+ for (const line of lines) {
524
+ const nextLength = currentLength + line.length + (current.length > 0 ? 1 : 0);
525
+ if (current.length > 0 && nextLength > maxLength) {
526
+ pages.push(current.join('\n'));
527
+ current = [line];
528
+ currentLength = line.length;
 
 
 
529
  } else {
530
+ current.push(line);
531
+ currentLength = nextLength;
532
  }
533
  }
534
 
535
+ if (current.length > 0) {
536
+ pages.push(current.join('\n'));
537
  }
538
 
539
+ return pages;
540
+ }
 
 
 
 
 
 
 
 
 
 
 
 
541
 
542
+ export function buildCircaMarketEmbeds(snapshot, marketLabel, entries, options = {}) {
543
+ const lines = entries.map((entry) => {
544
+ const team = entry.team ? ` (${entry.team})` : '';
545
+ const side = `${String(entry.side ?? '').toUpperCase()}${entry.lineValue !== null && entry.lineValue !== undefined ? ` ${entry.lineValue}` : ''}`;
546
+ return `${entry.playerName}${team} | ${side} | ${entry.oddsInput}`;
547
  });
548
+
549
+ const footerBase = options.footerText ?? 'Latest parsed Circa market snapshot';
550
+ const pages = lines.length > 0
551
+ ? chunkTextPages(lines, 3400)
552
+ : ['No parsed props were available for this market.'];
553
+
554
+ return pages.map((pageText, pageIndex) =>
555
+ new EmbedBuilder()
556
+ .setColor(PALETTE.gold)
557
+ .setTitle(`Circa ${marketLabel}${pages.length > 1 ? ` (${pageIndex + 1}/${pages.length})` : ''}`)
558
+ .setDescription([
559
+ `Source file: **${snapshot.fileName ?? 'Unknown'}**`,
560
+ '',
561
+ pageText,
562
+ ].join('\n'))
563
+ .setFooter({ text: `${footerBase}${pages.length > 1 ? ` | Page ${pageIndex + 1}/${pages.length}` : ''}` })
564
+ );
565
  }
566
 
567
  export function buildCircaMovementEmbed(movement, snapshot) {