Skip to content

Commit

Permalink
Merge pull request #28 from immich-app/fix/helpdesk-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bo0tzz committed Jun 19, 2024
2 parents 74011af + 940037e commit 3c69a4b
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/events/helpTicket/helpticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
import { ArgsOf, ButtonComponent, Discord, On, Slash, SlashChoice, SlashOption } from 'discordx';
import { Constants } from '../../constants.js';
import {
getLogsUploadModel,
getHelpDeskWelcomeMessage,
getComposeUploadModal,
getEnvUploadModal,
getComposeButton,
getComposeUploadModal,
getEnvButton,
getEnvUploadModal,
getHelpDeskWelcomeMessage,
getLogsButton,
getLogsUploadModel,
} from './util.js';

const submitButton = new ButtonBuilder({
Expand All @@ -36,6 +36,20 @@ const mainButtonRow = new ActionRowBuilder<MessageActionRowComponentBuilder>().a
submitButton,
);

async function sendHelpdeskWelcomeMessage(user: string, thread: ThreadChannel) {
const welcomeMessage = getHelpDeskWelcomeMessage(user);
const message = await thread.send({
content: welcomeMessage,
components: [mainButtonRow],
flags: [MessageFlags.SuppressEmbeds],
});

const itemCount = welcomeMessage.match(new RegExp(Constants.Icons.Unchecked, 'g'))?.length ?? 0;
for (let i = 1; i <= itemCount; i++) {
await message.react(`${i}️⃣`);
}
}

@Discord()
export class HelpTicket {
@ButtonComponent({ id: 'submit' })
Expand Down Expand Up @@ -93,18 +107,13 @@ export class HelpTicket {
return;
}

const welcomeMessage = getHelpDeskWelcomeMessage(thread.ownerId ?? '');
const message = await thread.fetch().then((thread) =>
thread.send({
content: welcomeMessage,
components: [mainButtonRow],
flags: [MessageFlags.SuppressEmbeds],
}),
);

const itemCount = welcomeMessage.match(new RegExp(Constants.Icons.Unchecked, 'g'))?.length ?? 0;
for (let i = 1; i <= itemCount; i++) {
await message.react(`${i}️⃣`);
const user = thread.ownerId ?? '';
const t = await thread.fetch();
try {
await sendHelpdeskWelcomeMessage(user, t);
} catch (e) {
console.error('Retrying helpdesk welcome message:', e);
setTimeout(async () => await sendHelpdeskWelcomeMessage(user, t), 5000);
}
}

Expand All @@ -118,19 +127,12 @@ export class HelpTicket {
return;
}

const welcomeMessage = getHelpDeskWelcomeMessage(interaction.channel.ownerId ?? '');
const message = await interaction.channel.fetch().then((thread) =>
thread.send({
content: welcomeMessage,
components: [mainButtonRow],
flags: [MessageFlags.SuppressEmbeds],
}),
);

const itemCount = welcomeMessage.match(new RegExp(Constants.Icons.Unchecked, 'g'))?.length ?? 0;
for (let i = 1; i <= itemCount; i++) {
await message.react(`${i}️⃣`);
}
const user = interaction.channel.ownerId ?? '';
await sendHelpdeskWelcomeMessage(user, await interaction.channel.fetch());
await interaction.reply({
content: 'Helpdesk welcome message sent',
flags: [MessageFlags.Ephemeral],
});
}

@ButtonComponent({ id: 'openTicket' })
Expand Down

0 comments on commit 3c69a4b

Please sign in to comment.