Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzDerock committed Feb 9, 2024
1 parent c7a73d3 commit fcf7e18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/generator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default async function Messages({ messages, channel, callbacks, ...option
{/* body */}
<Suspense>
{messages.map((message) => (
<DiscordMessage message={message} context={{ messages, channel, callbacks, ...options }} />
<DiscordMessage message={message} context={{ messages, channel, callbacks, ...options }} key={message.id} />
))}
</Suspense>

Expand Down
26 changes: 11 additions & 15 deletions src/utils/embeds.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import type { APIEmbedField } from 'discord.js';

export const calculateAmountOfTrue = (array: boolean[]) => {
// get the amount of true values before endIndex, stopping at the first false value
for (let i = array.length - 1; i >= 0; i--) {
if (!array[i]) {
return array.length - i;
}
}

return array.length - 1;
};

export function calculateInlineIndex(fields: APIEmbedField[], currentFieldIndex: number) {
// get the amount of inline fields before the current field without gaps
const inlineFieldsBefore = fields.slice(0, currentFieldIndex).map((e) => e.inline ?? false);
const startIndex = currentFieldIndex - 1;

const amount = calculateAmountOfTrue(inlineFieldsBefore) + 1;
for (let i = startIndex; i >= 0; i--) {
const field = fields[i];
if (!field) continue;

if (field.inline === false) {
const amount = startIndex - i;
return (amount % 3) + 1;
}
}

return (amount % 3) + 1;
return (currentFieldIndex % 3) + 1;
}

0 comments on commit fcf7e18

Please sign in to comment.