From 0d5dab8f0472f5e516e8064780ac8ab04779f60e Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Sat, 29 Apr 2023 00:43:21 -0400 Subject: [PATCH] deno fmt + prevent managers from JLA to locked events --- src/commands/managerJLA.ts | 23 +++++++++++++++++++++-- src/notificationSystem.ts | 4 +++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/commands/managerJLA.ts b/src/commands/managerJLA.ts index b69fb2a..861a357 100644 --- a/src/commands/managerJLA.ts +++ b/src/commands/managerJLA.ts @@ -1,8 +1,8 @@ -import { ApplicationCommandOptionTypes, ApplicationCommandTypes, Bot, Interaction } from '../../deps.ts'; +import { ApplicationCommandFlags, ApplicationCommandOptionTypes, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes } from '../../deps.ts'; import { alternateMemberToEvent, getGuildName, joinMemberToEvent, removeMemberFromEvent } from '../buttons/live-event/utils.ts'; import { generateMemberList } from '../buttons/eventUtils.ts'; import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../db.ts'; -import { infoColor2, sendDirectMessage, somethingWentWrong, stopThat } from '../commandUtils.ts'; +import { infoColor2, safelyDismissMsg, sendDirectMessage, somethingWentWrong, stopThat, warnColor } from '../commandUtils.ts'; import { CommandDetails, LFGMember } from '../types/commandTypes.ts'; import config from '../../config.ts'; import utils from '../utils.ts'; @@ -73,6 +73,25 @@ const execute = async (bot: Bot, interaction: Interaction) => { // Get event from link const eventMessage = await bot.helpers.getMessage(eventIds.channelId, eventIds.messageId).catch((e: Error) => utils.commonLoggers.messageGetError('managerJLA.ts', 'get eventMessage', e)); + + // Prevent managers from adding people to locked events + if (eventMessage && !eventMessage.components?.length) { + bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { + type: InteractionResponseTypes.ChannelMessageWithSource, + data: { + flags: ApplicationCommandFlags.Ephemeral, + embeds: [{ + color: warnColor, + title: 'Hey! Stop that!', + description: `You are not allowed to ${actionName} users to an event that has already started. + +${safelyDismissMsg}`, + }], + }, + }).catch((e: Error) => utils.commonLoggers.interactionSendError('commandUtils.ts@stopThat', interaction, e)); + return; + } + const userDetails = await bot.helpers.getUser(userToAdd).catch((e: Error) => utils.commonLoggers.messageGetError('managerJLA.ts', 'get userDetails', e)); if (eventMessage && userDetails) { // Perform the action diff --git a/src/notificationSystem.ts b/src/notificationSystem.ts index e8205e3..2e00f3c 100644 --- a/src/notificationSystem.ts +++ b/src/notificationSystem.ts @@ -154,7 +154,9 @@ export const lockEvent = async (bot: Bot, event: ActiveEvent, secondTry = false) embeds: [{ color: infoColor1, title: `Hello ${member.name}! An activity in ${guildName} may need your help.`, - description: `The ${activityName} in ${guildName} that you marked yourself as an alternate for may be \`${peopleShort}\` ${peopleShort === 1 ? 'person' : 'people'} short. If you are available, please join up with them.`, + description: `The ${activityName} in ${guildName} that you marked yourself as an alternate for may be \`${peopleShort}\` ${ + peopleShort === 1 ? 'person' : 'people' + } short. If you are available, please join up with them.`, }, eventMessage.embeds[0]], }).catch((e: Error) => utils.commonLoggers.messageSendError('notificationSystem.ts@lock', 'send DM fail', e)); });