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
8 changes: 4 additions & 4 deletions apps/bot/src/commands/staff/bot-profile/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class extends Component.Interaction {
case 'name': {
return interaction.showModal(
new ModalBuilder()
.setCustomId(customId('bot_profile_menu', 'name'))
.setCustomId(customId('bot_profile_menu_name'))
.setTitle(guildTranslations.name.input.title())
.setLabelComponents(
new LabelBuilder()
Expand All @@ -40,7 +40,7 @@ export default class extends Component.Interaction {
case 'bio': {
return interaction.showModal(
new ModalBuilder()
.setCustomId(customId('bot_profile_menu', 'bio'))
.setCustomId(customId('bot_profile_menu_bio'))
.setTitle(guildTranslations.bio.input.title())
.setLabelComponents(
new LabelBuilder()
Expand All @@ -60,7 +60,7 @@ export default class extends Component.Interaction {
case 'avatar': {
return interaction.showModal(
new ModalBuilder()
.setCustomId(customId('bot_profile_menu', 'avatar'))
.setCustomId(customId('bot_profile_menu_avatar'))
.setTitle(guildTranslations.avatar.input.title())
.setLabelComponents(
new LabelBuilder()
Expand All @@ -79,7 +79,7 @@ export default class extends Component.Interaction {
case 'banner': {
return interaction.showModal(
new ModalBuilder()
.setCustomId(customId('bot_profile_menu', 'banner'))
.setCustomId(customId('bot_profile_menu_banner'))
.setTitle(guildTranslations.banner.input.title())
.setLabelComponents(
new LabelBuilder()
Expand Down
66 changes: 18 additions & 48 deletions apps/bot/src/commands/staff/bot-profile/modal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
container,
DeferReply,
dynamicCustomId,
extractCustomId,
Modal,
userEmbedError,
} from '@ticketer/djs-framework';
import { container, customId, DeferReply, Modal, userEmbedError } from '@ticketer/djs-framework';
import {
ContainerBuilder,
codeBlock,
Expand All @@ -22,44 +15,9 @@ import { prettifyError, z } from 'zod';
import { translate } from '@/i18n';

export default class extends Modal.Interaction {
public readonly customIds = [dynamicCustomId('bot_profile_menu')];

public async execute(context: Modal.Context) {
const { dynamicValue } = extractCustomId(context.interaction.customId, true);
public readonly customIds = [customId('bot_profile_menu_name')];

switch (dynamicValue) {
case 'name': {
return this.name(context);
}
case 'bio': {
return this.bio(context);
}
case 'avatar': {
return this.avatar(context);
}
case 'banner': {
return this.banner(context);
}
default: {
const translations = translate(context.interaction.locale).commands['bot-profile'].command.modals.errors
.customId;

return context.interaction.reply({
embeds: [
userEmbedError({
client: context.interaction.client,
description: translations.description(),
member: context.interaction.member,
title: translations.title(),
}),
],
flags: [MessageFlags.Ephemeral],
});
}
}
}

private async name({ interaction }: Modal.Context) {
public async execute({ interaction }: Modal.Context) {
const translations = translate(interaction.locale).commands['bot-profile'].command.modals.name.response.errors;
const {
data: nick,
Expand Down Expand Up @@ -126,8 +84,12 @@ export default class extends Modal.Interaction {
flags: [MessageFlags.IsComponentsV2],
});
}
}

export class Bio extends Modal.Interaction {
public readonly customIds = [customId('bot_profile_menu_bio')];

private async bio({ interaction }: Modal.Context) {
public async execute({ interaction }: Modal.Context) {
const translations = translate(interaction.locale).commands['bot-profile'].command.modals.bio.response.errors;
const {
data: bio,
Expand Down Expand Up @@ -175,9 +137,13 @@ export default class extends Modal.Interaction {
flags: [MessageFlags.IsComponentsV2],
});
}
}

export class Avatar extends Modal.Interaction {
public readonly customIds = [customId('bot_profile_menu_avatar')];

@DeferReply()
private async avatar({ interaction }: Modal.Context) {
public async execute({ interaction }: Modal.Context) {
const avatar = interaction.fields.getUploadedFiles('avatar', false)?.at(0)?.url ?? '';
let me = await interaction.guild.members.fetchMe();
const oldAvatar = me.displayAvatarURL();
Expand Down Expand Up @@ -226,9 +192,13 @@ export default class extends Modal.Interaction {
flags: [MessageFlags.IsComponentsV2],
});
}
}

export class Banner extends Modal.Interaction {
public readonly customIds = [customId('bot_profile_menu_banner')];

@DeferReply()
private async banner({ interaction }: Modal.Context) {
public async execute({ interaction }: Modal.Context) {
const banner = interaction.fields.getUploadedFiles('banner', false)?.at(0)?.url ?? '';
// Force fetch due to caching issues.
let me = await interaction.guild.members.fetchMe({ force: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ export default class extends Command.Interaction {
subcommand.setName('overview').setDescription('View the current configurations for automatic threads.'),
)
.addSubcommand((subcommand) =>
subcommand
.setName('create')
.setDescription('Create a new configuration for automatic threads.')
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('The text channel where the bot creates a thread for the user.')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true),
),
subcommand.setName('create').setDescription('Create a new configuration for automatic threads.'),
)
.addSubcommand((subcommand) =>
subcommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class extends Component.Interaction {
private async openingMessage(context: Component.Context<'string'>) {
const { dynamicValue } = extractCustomId(context.interaction.customId, true);
const {
data: id,
data: channelId,
error,
success,
} = automaticThreadsConfigurationsSelectSchema.shape.channelId.safeParse(dynamicValue);
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class extends Component.Interaction {
.from(automaticThreadsConfigurations)
.where(
and(
eq(automaticThreadsConfigurations.channelId, id),
eq(automaticThreadsConfigurations.channelId, channelId),
eq(automaticThreadsConfigurations.guildId, context.interaction.guildId),
),
);
Expand All @@ -105,9 +105,7 @@ export default class extends Component.Interaction {
.catch(() => false);
}

const { description, title } = row;

void openingMessageModal(context, { description, id, title });
void openingMessageModal(context, { channelId, ...row });
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { automaticThreadsConfigurations, database, desc, eq } from '@ticketer/database';
import { type Command, type Component, container, customId, userEmbedError } from '@ticketer/djs-framework';
import { type Component, container, customId, type Subcommand, userEmbedError } from '@ticketer/djs-framework';
import {
bold,
ChannelSelectMenuBuilder,
ChannelType,
channelMention,
HeadingLevel,
Expand All @@ -21,7 +22,7 @@ import { automaticThreadsContainer, messageWithPagination, withPagination } from
export function IsTextChannel(_: object, __: string, descriptor: PropertyDescriptor) {
const original = descriptor.value as () => void;

descriptor.value = function (this: Command.Interaction, { interaction }: Command.Context<'chat'>) {
descriptor.value = function (this: Subcommand.Interaction, { interaction }: Subcommand.Context) {
const { type } = interaction.options.getChannel('channel', true);

if (type !== ChannelType.GuildText) {
Expand All @@ -43,10 +44,7 @@ export function IsTextChannel(_: object, __: string, descriptor: PropertyDescrip
return descriptor;
}

export async function getConfigurations(
{ interaction }: Command.Context<'chat'> | Component.Context<'button'>,
page = 0,
) {
export async function getConfigurations({ interaction }: Subcommand.Context | Component.Context<'button'>, page = 0) {
const PAGE_SIZE = 3;
const configurations = await withPagination({
page,
Expand Down Expand Up @@ -96,14 +94,26 @@ export async function getConfigurations(
}

export async function openingMessageModal(
{ interaction }: Command.Context<'chat'> | Component.Context<'string'>,
options: { id: string; title?: string; description?: string },
{ interaction }: Subcommand.Context | Component.Context<'string'>,
{ channelId, description, title }: { channelId?: string; title?: string; description?: string },
) {
const channelInput = new LabelBuilder()
.setLabel('Channel')
.setDescription("The text channel where the bot creates a thread from the user's message.")
.setChannelSelectMenuComponent(
// TODO: make this disabled in presence of a preset channel when Discord allows so.
(channelId ? new ChannelSelectMenuBuilder().setDefaultChannels(channelId) : new ChannelSelectMenuBuilder())
.setCustomId(customId('channel'))
.setRequired(true)
.setMinValues(1)
.setMaxValues(1)
.setChannelTypes(ChannelType.GuildText),
);
const titleInput = new LabelBuilder()
.setLabel('Message Title')
.setDescription('Write "{member}" to mention the user.')
.setTextInputComponent(
(options.title ? new TextInputBuilder().setValue(options.title) : new TextInputBuilder())
(title ? new TextInputBuilder().setValue(title) : new TextInputBuilder())
.setCustomId(customId('title'))
.setRequired(true)
.setMinLength(1)
Expand All @@ -115,7 +125,7 @@ export async function openingMessageModal(
.setLabel('Message Description')
.setDescription('Write "{member}" to mention the user.')
.setTextInputComponent(
(options.description ? new TextInputBuilder().setValue(options.description) : new TextInputBuilder())
(description ? new TextInputBuilder().setValue(description) : new TextInputBuilder())
.setCustomId(customId('description'))
.setRequired(true)
.setMinLength(1)
Expand All @@ -124,9 +134,9 @@ export async function openingMessageModal(
);

const modal = new ModalBuilder()
.setCustomId(customId('ticket_automatic_threads_configuration_opening_message', options.id))
.setCustomId(customId('ticket_automatic_threads_configuration_opening_message'))
.setTitle('Opening Message Title & Description')
.setLabelComponents(titleInput, descriptionInput);
.setLabelComponents([channelInput, titleInput, descriptionInput].filter((input) => !!input));

return interaction.showModal(modal).catch(() => false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import {
automaticThreadsConfigurationsInsertSchema,
database,
} from '@ticketer/database';
import {
container,
DeferReply,
dynamicCustomId,
extractCustomId,
Modal,
userEmbedError,
} from '@ticketer/djs-framework';
import { container, customId, DeferReply, Modal, userEmbedError } from '@ticketer/djs-framework';
import { ChannelType, HeadingLevel, heading, MessageFlags, TextDisplayBuilder } from 'discord.js';
import { prettifyError } from 'zod';
import { automaticThreadsContainer, fetchChannel } from '@/utils';
import { automaticThreadsContainer } from '@/utils';

export class ModalInteraction extends Modal.Interaction {
public readonly customIds = [dynamicCustomId('ticket_automatic_threads_configuration_opening_message')];
public readonly customIds = [customId('ticket_automatic_threads_configuration_opening_message')];

@DeferReply()
public async execute({ interaction }: Modal.Context) {
const { dynamicValue } = extractCustomId(interaction.customId, true);
const channel = await fetchChannel(interaction.guild, dynamicValue);
const channel = interaction.fields.getSelectedChannels('channel', true).at(0);

if (channel?.type !== ChannelType.GuildText) {
return interaction.editReply({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export class Create extends Subcommand.Interaction {
subcommandNames: ['create'],
});

@IsTextChannel
public execute(context: Subcommand.Context) {
void openingMessageModal(context, { id: context.interaction.options.getChannel('channel', true).id });
void openingMessageModal(context, {});
}
}

Expand Down
11 changes: 1 addition & 10 deletions apps/bot/src/commands/staff/configuration-user-forums/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ export default class extends Command.Interaction {
subcommand.setName('overview').setDescription('View the current configurations for user forum threads.'),
)
.addSubcommand((subcommand) =>
subcommand
.setName('create')
.setDescription('Create a new configuration for user forums assisted by the bot.')
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('The forum channel where the bot assists with support for the user.')
.addChannelTypes(ChannelType.GuildForum)
.setRequired(true),
),
subcommand.setName('create').setDescription('Create a new configuration for user forums assisted by the bot.'),
)
.addSubcommand((subcommand) =>
subcommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export default class extends Component.Interaction {

private async openingMessage(context: Component.Context<'string'>) {
const { dynamicValue } = extractCustomId(context.interaction.customId, true);
const { data: id, error, success } = userForumsConfigurationsSelectSchema.shape.channelId.safeParse(dynamicValue);
const {
data: channelId,
error,
success,
} = userForumsConfigurationsSelectSchema.shape.channelId.safeParse(dynamicValue);

if (!success) {
return context.interaction
Expand All @@ -76,7 +80,7 @@ export default class extends Component.Interaction {
.from(userForumsConfigurations)
.where(
and(
eq(userForumsConfigurations.channelId, id),
eq(userForumsConfigurations.channelId, channelId),
eq(userForumsConfigurations.guildId, context.interaction.guildId),
),
);
Expand All @@ -96,9 +100,7 @@ export default class extends Component.Interaction {
.catch(() => false);
}

const { description, title } = row;

void openingMessageModal(context, { description, id, title });
void openingMessageModal(context, { channelId, ...row });
}
}

Expand Down
Loading