Skip to content
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
2 changes: 1 addition & 1 deletion src/common/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { docsCommands } from '@/features/docs/index.js';
import { guidesCommand } from '@/features/guides/index.js';
import cacheMessages from '@/features/cache-messages/index.js';
import { repelCommand } from '@/features/moderation/repel.js';
import { repelCommand } from '@/features/repel/repel.js';
import { pingCommand } from '@/features/ping/index.js';
import { publicGuidesCommand } from '@/features/public-guides/index.js';
import { createShowcaseCommand } from '@/features/showcase/create-showcase.js';
Expand Down
45 changes: 28 additions & 17 deletions src/features/ban-buttons/ban-command-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ export const createBanCommandButtons = ({
id: string;
actions: BanCommandActions;
}): BanCommandButtons => {
const buildButtons = (
targetId: string,
disabled = false
): ActionRowBuilder<MessageActionRowComponentBuilder> => {
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
for (const [key, action] of Object.entries(actions)) {
row.addComponents(
new ButtonBuilder()
.setCustomId(customId(id, key, targetId))
.setLabel(action.label)
.setStyle(
action.command === 'softban'
? ButtonStyle.Secondary
: ButtonStyle.Danger
)
.setDisabled(disabled)
);
}
return row;
};

const handler: ButtonSubmitInteraction = {
commandName: id,
handler: async (interaction) => {
Expand All @@ -75,8 +96,13 @@ export const createBanCommandButtons = ({
return;
}

// Disable the buttons now that a moderator has acted on this repel.
await interaction.update({
components: [buildButtons(targetId, true)],
});

const command = buildBanCommand(targetId, action);
await interaction.reply({
await interaction.followUp({
content: `# Copy and run this ban command:\n${codeBlock(command)}`,
flags: MessageFlags.Ephemeral,
});
Expand All @@ -86,21 +112,6 @@ export const createBanCommandButtons = ({
registerButtonSubmitInteraction(handler);

return {
buildButtons: (targetId: string) => {
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
for (const [key, action] of Object.entries(actions)) {
row.addComponents(
new ButtonBuilder()
.setCustomId(customId(id, key, targetId))
.setLabel(action.label)
.setStyle(
action.command === 'softban'
? ButtonStyle.Secondary
: ButtonStyle.Danger
)
);
}
return row;
},
buildButtons,
};
};
90 changes: 90 additions & 0 deletions src/features/repel/embeds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {
channelMention,
Colors,
EmbedBuilder,
type GuildMember,
type User,
userMention,
} from 'discord.js';
import { timeToString } from '@/constants/time.js';
import {
buildDeletedMessagesDescription,
type DeletedMessageSnapshot,
} from './util.js';

export const buildCommandEmbed = ({
member,
channelInfo,
commandString,
}: {
member: GuildMember;
channelInfo: string;
commandString: string;
}): EmbedBuilder =>
new EmbedBuilder()
.setAuthor({
name: member.user.tag,
iconURL: member.user.displayAvatarURL(),
})
.setDescription(
`Used \`repel\` command in ${channelInfo}.\n${commandString}`
)
.setColor(Colors.Green);

export const buildFailedChannelsEmbed = (
failedChannels: string[]
): EmbedBuilder =>
new EmbedBuilder()
.setTitle('Failed to delete messages in the following channels:')
.setDescription(failedChannels.map((id) => channelMention(id)).join('\n'))
.setColor(Colors.Red)
.setTimestamp();

export const buildResultEmbed = (context: {
target: User | GuildMember;
member: GuildMember;
reason: string;
duration?: number;
shouldSendDm: boolean;
dmSent: boolean;
Comment thread
michal-skraburski marked this conversation as resolved.
Resolved
}): EmbedBuilder => {
const footerParts = [
context.duration
? `Timeout: ${timeToString(context.duration)}`
: 'No timeout',
];
if (context.shouldSendDm) {
footerParts.push(context.dmSent ? 'DM sent' : 'DM sent error');
}

return new EmbedBuilder()
.setTitle('Repel')
.addFields(
{
name: 'Repelled User',
value: userMention(context.target.id),
inline: true,
},
{
name: 'Repelled By',
value: userMention(context.member.id),
inline: true,
},
{
name: 'Reason',
value: context.reason,
inline: true,
}
)
.setColor(Colors.Orange)
.setFooter({ text: footerParts.join(' • ') });
};

export const buildDeletedMessagesEmbed = (
deletedMessages: DeletedMessageSnapshot[]
): EmbedBuilder =>
new EmbedBuilder()
.setTitle('Deleted Messages')
.setDescription(buildDeletedMessagesDescription(deletedMessages))
.setColor(Colors.Red)
.setTimestamp();
Loading
Loading