Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): embed colors #27

Merged
merged 1 commit into from
Sep 15, 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
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ model connectedList {
compact Boolean
invite String?
profFilter Boolean
embedColor String?
webhookURL String
date DateTime @default(now())
hub hubs? @relation(fields: [hubId], references: [id])
Expand Down
11 changes: 10 additions & 1 deletion src/Events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import checks from '../Scripts/message/checks';
import messageContentModifiers from '../Scripts/message/messageContentModifiers';
import cleanup from '../Scripts/message/cleanup';
import { APIMessage, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, Message, User, WebhookClient, WebhookMessageCreateOptions } from 'discord.js';
import { APIMessage, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, HexColorString, Message, User, WebhookClient, WebhookMessageCreateOptions } from 'discord.js';
import { getDb, colors } from '../Utils/functions/utils';
import { censor } from '../Utils/functions/wordFilter';
import { messageData } from '@prisma/client';
Expand Down Expand Up @@ -135,6 +135,15 @@ export default {
threadId: connection.parentId ? connection.channelId : undefined,
allowedMentions: { parse: [] },
};

if (connection.embedColor && webhookMessage.embeds
&& /^#[0-9A-F]{6}$/i.test(connection.embedColor)
) {
webhookMessage.embeds.push(EmbedBuilder.from(webhookMessage.embeds[0])
.setColor(connection.embedColor as HexColorString),
);
webhookMessage.embeds.splice(0, 1);
}
}

const webhook = new WebhookClient({ url: connection.webhookURL });
Expand Down
60 changes: 60 additions & 0 deletions src/Scripts/network/displaySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export = {
.setEmoji(emoji.icons.store)
.setDescription('Set a different channel for the network.')
.setValue('change_channel'),
new StringSelectMenuOptionBuilder()
.setLabel('Embed Color')
.setEmoji('🎨')
.setDescription('Set the color of the embeds sent in the network.')
.setValue('embed_color'),
),
]);

Expand Down Expand Up @@ -164,6 +169,61 @@ export = {
}

switch (settingsMenu.values[0]) {
/* Embed color selection */
case 'embed_color': {
const modal = new ModalBuilder()
.setTitle('Set Embed Color')
.setCustomId(settingsMenu.id)
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('embed_color')
.setStyle(TextInputStyle.Short)
.setLabel('Embed Color')
.setPlaceholder('Provide a hex color code.')
.setValue(updConnection.embedColor || '#000000'),
),
);

await settingsMenu.showModal(modal);

const modalSubmit = await settingsMenu.awaitModalSubmit({
time: 60_000,
filter: (i) => i.customId === modal.data.custom_id,
}).catch((e) => {
if (!e.message.includes('reason: time')) {
logger.error(e);
captureException(e);
}
return null;
});

if (!modalSubmit) return;


const embedColor = modalSubmit.fields.getTextInputValue('embed_color');

const hex_regex = /^#[0-9A-F]{6}$/i;
if (!hex_regex.test(embedColor)) {
modalSubmit.reply({
content: `${emoji.normal.no} Invalid hex color code. Please try again.`,
ephemeral: true,
});
return;
}

await db.connectedList.update({
where: { channelId: updConnection.channelId },
data: { embedColor },
});

modalSubmit.reply({
content: `${emoji.normal.yes} Embed color successfully set to \`${embedColor}\`!`,
ephemeral: true,
});
break;
}

/* Compact / Normal mode toggle */
case 'compact': {
await db.connectedList.update({
Expand Down