Skip to content

Commit

Permalink
cleaner embed path code
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jun 1, 2024
1 parent 7c53d5b commit 50e09ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
27 changes: 14 additions & 13 deletions functions/submission/makeEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ module.exports = async function makeEmbed(
// send to #submission-spam for permanent urls
const [thumbnailUrl, comparedUrl] = await getImages(message.client, rawImage, comparisonImage);

embed.setImage(comparedUrl);
embed.setThumbnail(thumbnailUrl);
embed.setFooter({ text: hasReference ? "Reference | New | Current" : "Reference | New" });
embed
.setImage(comparedUrl)
.setThumbnail(thumbnailUrl)
.setFooter({ text: hasReference ? "Reference | New | Current" : "Reference | New" });

// if it's a blank mcmeta there's no point adding a whole field for it
if (Object.keys(mcmeta?.animation ?? {}).length)
Expand Down Expand Up @@ -126,23 +127,23 @@ module.exports = async function makeEmbed(
*/
function addPathsToEmbed(texture) {
/** @type {Record<import("@helpers/jsdoc").MinecraftEdition, string[]>} */
const tmp = {};

texture.uses.forEach((use) => {
texture.paths
const groupedPaths = texture.uses.reduce((acc, use) => {
const paths = texture.paths
.filter((el) => el.use === use.id)
.forEach((p) => {
.map((p) => {
const versions = p.versions.sort(minecraftSorter);
const versionRange = `\`[${
versions.length > 1 ? `${versions[0]}${versions[versions.length - 1]}` : versions[0]
}]\``;
const formatted = `${versionRange} ${p.name}`;
if (tmp[use.edition]) tmp[use.edition].push(formatted);
else tmp[use.edition] = [formatted];
return `${versionRange} ${p.name}`;
});
});
if (!acc[use.edition]) acc[use.edition] = [];
acc[use.edition].push(...paths);
return acc;
}, {});

return Object.entries(tmp).map(([edition, paths]) => ({
// convert from use object to embed-compatible data
return Object.entries(groupedPaths).map(([edition, paths]) => ({
name: edition[0].toUpperCase() + edition.slice(1),
value: paths.join("\n"),
}));
Expand Down
6 changes: 3 additions & 3 deletions helpers/getMessages.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @callback MessageFilter
* @param {import("discord.js").Message}
* @returns {boolean}
* @param {import("discord.js").Message} message Message to be filtered
* @returns {boolean} Whether the message should stay or be discarded
*/

/**
Expand All @@ -10,7 +10,7 @@
* @param {import("discord.js").Client} client
* @param {string} channelID channel where messages are fetched from
* @param {MessageFilter} [filter] filter incoming messages
* @returns {Promise<import("discord.js").Message[]>} fetched messages
* @returns {Promise<import("discord.js").Message[]>} fetched messages from oldest to newest
*/
module.exports = async function getMessages(client, channelID, filter = () => true) {
/** @type {import("discord.js").TextChannel} */
Expand Down

0 comments on commit 50e09ed

Please sign in to comment.