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

TripSit simplifications #884

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
74 changes: 61 additions & 13 deletions src/discord/commands/global/d.tripsitmode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
} from 'discord.js';
import { stripIndents } from 'common-tags';
import { DateTime } from 'luxon';
import { ticket_status } from '@prisma/client';
import { ticket_status, user_tickets } from '@prisma/client';
import { SlashCommand } from '../../@types/commandDef';
import { embedTemplate } from '../../utils/embedTemplate';
// import {embedTemplate} from '../../utils/embedTemplate';
Expand All @@ -40,7 +40,7 @@

const F = f(__filename);

async function tripsitmodeOn(

Check warning on line 43 in src/discord/commands/global/d.tripsitmode.ts

View workflow job for this annotation

GitHub Actions / Lint

Refactor this function to reduce its Cognitive Complexity from 86 to the 50 allowed
interaction:ChatInputCommandInteraction,
target:GuildMember,
) {
Expand Down Expand Up @@ -251,10 +251,13 @@
if (minutes > 5) { // Switch to seconds > 10 for dev server
const helperString = `and/or ${roleHelper}`;
try {
// eslint-disable-next-line max-len
metaMessage = `Hey ${roleTripsitter} ${guildData.role_helper ? helperString : ''} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`;
} catch (err) {
// If for example helper role has been deleted but the ID is still stored, do this
// eslint-disable-next-line max-len
metaMessage = `Hey ${roleTripsitter} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`;
// eslint-disable-next-line max-len
log.error(F, `Stored Helper ID for guild ${guildData.id} is no longer valid. Role is unfetchable or deleted.`);
}
} else {
Expand Down Expand Up @@ -287,12 +290,14 @@
}
}

log.info(F, 'TripSit Mode was triggered in Condition 1 (Update)');
ticketData = await db.user_tickets.update({
where: {
id: ticketData.id,
},
data: {
status: 'OPEN' as ticket_status,
tripsit_mode: true,
reopened_at: new Date(),
archived_at: env.NODE_ENV === 'production'
? DateTime.local().plus({ days: 7 }).toJSDate()
Expand Down Expand Up @@ -330,7 +335,7 @@
new ActionRowBuilder<TextInputBuilder>().addComponents(new TextInputBuilder()
.setCustomId('introInput')
.setLabel('What\'s going on with them?')
.setPlaceholder('This will be posted in the channel for them to see!')
.setPlaceholder('This will only be visible to helpers and TripSitters.')
.setStyle(TextInputStyle.Paragraph)),
));

Expand All @@ -342,18 +347,61 @@
const triage = i.fields.getTextInputValue('triageInput');
const intro = i.fields.getTextInputValue('introInput');

const threadHelpUser = await tripSitMe(i, target, triage, intro) as ThreadChannel;
const result = (await tripSitMe(i, target, triage, intro)) as [ThreadChannel | null, user_tickets] | null;

const replyMessage = stripIndents`
Hey ${i.member}, you activated tripsit mode on ${target.displayName}!

Click here to be taken to their private room: ${threadHelpUser}

You can also click in your channel list to see your private room!`;
const embed = embedTemplate()
.setColor(Colors.DarkBlue)
.setDescription(replyMessage);
await i.editReply({ embeds: [embed] });
if (result !== null) {
const [threadHelpUser, newTicketData] = result;
const replyMessage = stripIndents`
Hey ${i.member}, you activated tripsit mode on ${target.displayName}!

Click here to be taken to their private room: ${threadHelpUser}

You can also click in your channel list to see their private room!`;
const embed = embedTemplate()
.setColor(Colors.DarkBlue)
.setDescription(replyMessage);
await i.editReply({ embeds: [embed] });

if (!ticketData) {
log.info(F, 'TripSit Mode was triggered in Condition 2 (Creation)');
ticketData = await db.user_tickets.create({
data: {
user_id: userData.id,
type: 'TRIPSIT',
status: 'OPEN' as ticket_status,
tripsit_mode: true,
description: '',
first_message_id: '',
thread_id: threadHelpUser !== null ? threadHelpUser.id : '',
archived_at: env.NODE_ENV === 'production'
? DateTime.local().plus({ days: 3 }).toJSDate()
: DateTime.local().plus({ minutes: 1 }).toJSDate(),
deleted_at: env.NODE_ENV === 'production'
? DateTime.local().plus({ days: 6 }).toJSDate()
: DateTime.local().plus({ minutes: 2 }).toJSDate(),
},
});
} else {
// Create or update thread to toggle tripsit_mode on
log.info(F, 'TripSit Mode was triggered in Condition 3 (Update)');
ticketData = await db.user_tickets.update({
where: {
id: newTicketData.id, // Assuming 'id' is unique; use a dummy value if `ticketData` is null
},
data: {
status: 'OPEN' as ticket_status,
tripsit_mode: true,
reopened_at: new Date(),
archived_at: env.NODE_ENV === 'production'
? DateTime.local().plus({ days: 3 }).toJSDate()
: DateTime.local().plus({ minutes: 1 }).toJSDate(),
deleted_at: env.NODE_ENV === 'production'
? DateTime.local().plus({ days: 6 }).toJSDate()
: DateTime.local().plus({ minutes: 2 }).toJSDate(),
},
});
}
}
});

return true;
Expand Down
6 changes: 6 additions & 0 deletions src/discord/events/buttonClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
tripsitmeBackup,
tripsitmeTeamClose,
tripsitmeUserClose,
tripsitmeUserDelete,
} from '../utils/tripsitme';
import { techHelpClick, techHelpClose, techHelpOwn } from '../utils/techHelp';
// import {
Expand Down Expand Up @@ -183,6 +184,11 @@ export async function buttonClick(interaction:ButtonInteraction, discordClient:C
return;
}

if (buttonID.startsWith('tripsitmeUserDelete')) {
tripsitmeUserDelete(interaction);
return;
}

if (buttonID.startsWith('tripsitmeMeta')) {
tripsitmeMeta(interaction);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/discord/utils/commandCooldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ async function commandCooldown(

// If the cooldown is still active, inform the user
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000; // Time left in seconds
return {
success: false,
message: `Please wait ${timeLeft.toFixed(1)} more seconds before using this command or button again.`,
// eslint-disable-next-line max-len
message: `Please wait before using this command or button again. You can press it again <t:${Math.floor(expirationTime / 1000)}:R>`,
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/discord/utils/messageCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ give people a chance to answer 😄 If no one answers in 5 minutes you can try a
}
const roleTripsitter = await message.guild.roles.fetch(env.ROLE_TRIPSITTER) as Role;
const roleHelper = await message.guild.roles.fetch(env.ROLE_HELPER) as Role;
await message.channel.send(`Hey ${displayName}, someone from the ${roleTripsitter} and/or ${roleHelper} team will be with you as soon as they're available!
await message.channel.send(stripIndents`Hey ${displayName}, someone from the ${roleTripsitter} and/or ${roleHelper} team will be with you as soon as they're available!

If you’re in the right mindset please start by telling us what you took, at what dose and route, how long ago, along with any concerns you may have.
If you’re in the right mindset please start by telling us what you took, at what dose and route, how long ago, along with any concerns you may have.

**If this is a medical emergency** please contact your local emergency services: we do not call EMS on behalf of anyone.
**If this is a medical emergency** please contact your local emergency services: we do not call EMS on behalf of anyone.

`);

Expand Down
Loading
Loading