Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

fix: Replaced manualEmbed with EmbedBuilders, removed debug stuff from apps #26

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions src/core/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import {
ActionRowBuilder,
InteractionResponse,
Message,
APIEmbedField,
Colors,
EmbedBuilder,
ColorResolvable,
EmbedFooterOptions,
} from 'discord.js';
import {replyToInteraction} from './slash_commands.js';

Expand All @@ -31,25 +26,6 @@ export enum ConfirmEmbedResponse {
Denied = 'denied',
}

/**
* Interface used when generating a manual embed, holds everything needed to create it
* @param color Optional embed color
* @param thumbnail Optional embed thumbnail URL
* @param title Optional embed title
* @param description Required embed description
* @param footer Optional embed footer
* @param fields Optional field array
*/
interface embedGenerator {
color?: ColorResolvable;
title?: string;
thumbnail?: string;
// Required by the API
description: string;
footer?: EmbedFooterOptions;
fields?: APIEmbedField[];
}

/**
* Helper utilities used to speed up embed work
*/
Expand All @@ -74,41 +50,6 @@ export const embed = {
return otherOptions;
},

/**
* Method to create a factoid with manually defined parameters
* Takes a {@link embedGenerator} object as an argument.
* @returns The finished embed object
*/
manualEmbed({
color = Colors.Blue,
thumbnail,
title,
description,
footer,
fields,
}: embedGenerator): APIEmbed {
const embed: EmbedBuilder = new EmbedBuilder();

embed.setColor(color);
// Required field
embed.setDescription(description);

if (thumbnail !== undefined) {
embed.setThumbnail(thumbnail);
}
if (title !== undefined) {
embed.setTitle(title);
}
if (footer !== undefined) {
embed.setFooter(footer);
}
if (fields !== undefined) {
embed.setFields(fields);
}

return embed.toJSON();
},

/**
* A preformatted embed that should be used to indicate command failure
*/
Expand Down
36 changes: 18 additions & 18 deletions src/modules/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Role,
GuildMember,
APIEmbedField,
EmbedBuilder,
} from 'discord.js';

import * as util from '../core/util.js';
Expand Down Expand Up @@ -186,13 +187,14 @@ const apply = new util.RootModule(
});
}

const embed = util.embed.manualEmbed({
color: Colors.Blurple,
title: 'Application manager',
description: `New application! User: \`${submittedModal.user.tag}\` Application ID: \`${userApplication._id}\``,
footer: {text: 'Status: Pending'},
fields: embedFields,
});
const embed: EmbedBuilder = new EmbedBuilder()
.setColor(Colors.Blurple)
.setTitle('Application manager')
.setDescription(
`New application! User: \`${submittedModal.user.tag}\` Application ID: \`${userApplication._id}\``
)
.setFooter({text: 'Status: Pending'})
.setFields(embedFields);

await applicationChannel.send({embeds: [embed]});

Expand Down Expand Up @@ -248,7 +250,7 @@ application.registerSubModule(
}

// Creates all payloads for pagination
const embeds: BaseMessageOptions[] = [];
const payloads: BaseMessageOptions[] = [];

for (const entry of locatedApplications) {
// Creates the embed fields dynamically from the responses
Expand All @@ -262,20 +264,18 @@ application.registerSubModule(
});
}

const embed = util.embed.manualEmbed({
color: Colors.Blurple,
title: `Applications for \`${user.tag}\``,
description: `Application ID: \`${entry._id}\``,
footer: {text: `Status: ${entry.status}`},
fields: embedFields,
});
const embed: EmbedBuilder = new EmbedBuilder()
.setColor(Colors.Blurple)
.setTitle(`Applications for \`${user.tag}\``)
.setDescription(`Application ID: \`${entry._id}\``)
.setFooter({text: `Status: ${entry.status}`})
.setFields(embedFields);

embeds.push({embeds: [embed]});
payloads.push({embeds: [embed.toJSON()]});
}

// Finally, send the payloads off to be paginated
//await util.paginatePayloads(interaction, embeds, 60, false);
new util.PaginatedMessage(interaction, embeds, 5);
new util.PaginatedMessage(interaction, payloads, 30);
}
)
);
Expand Down
15 changes: 7 additions & 8 deletions src/modules/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* - {@link youtube}
*/

import {APIEmbed, BaseMessageOptions, Colors} from 'discord.js';
import {BaseMessageOptions, Colors, EmbedBuilder} from 'discord.js';
import * as util from '../core/util.js';
import {google} from 'googleapis';

Expand Down Expand Up @@ -74,14 +74,13 @@ googleModule.registerSubModule(
for (const resultIndex in results.data.items) {
const result = results.data.items[parseInt(resultIndex)];

const embed: APIEmbed = util.embed.manualEmbed({
color: Colors.Blurple,
thumbnail: GOOGLE_ICON_URL,
title: `Results for ${query}`,
description: `${result.link!}\n${result.snippet!}`,
});
const embed: EmbedBuilder = new EmbedBuilder()
.setColor(Colors.Blurple)
.setThumbnail(GOOGLE_ICON_URL)
.setTitle(`Results for ${query}`)
.setDescription(`${result.link!}\n${result.snippet!}`);

payloads.push({embeds: [embed]});
payloads.push({embeds: [embed.toJSON()]});
}

new util.PaginatedMessage(interaction, payloads);
Expand Down