Update early token deletion to be less aggressive + deno fmt

This commit is contained in:
Ean Milligan (Bastion) 2023-04-29 20:23:24 -04:00
parent efc3aa3b7c
commit ad3d854469
11 changed files with 15 additions and 19 deletions

View File

@ -45,9 +45,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
const strippedIdxPath = interaction.data.customId?.includes(idSeparator) ? customIdIdxPath : valuesIdxPath;
const finalizedIdxPath = strippedIdxPath.substring(0, strippedIdxPath.lastIndexOf(pathIdxEnder));
if ((interaction.data.customId?.includes(idSeparator) && interaction.data.customId.endsWith(pathIdxEnder)) || interaction.data?.values?.[0].endsWith(pathIdxEnder)) {
// User selected activity, give them the details modal and delete the selectMenus
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
let prefillTime = '';
let prefillTimeZone = '';
let prefillDate = '';

View File

@ -1,5 +1,4 @@
import { Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
import { deleteTokenEarly } from '../tokenCleanup.ts';
import { generateCustomActivityFields, idSeparator, pathIdxSeparator } from '../eventUtils.ts';
import { customId as verifyCustomActivityId } from './step1b-verifyCustomActivity.ts';
import utils from '../../utils.ts';
@ -14,7 +13,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
const [actTitle, actSubtitle, activityMaxPlayers] = (interaction.data.customId.split(idSeparator)[1] || '').split(pathIdxSeparator);
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.Modal,
data: {

View File

@ -2,7 +2,7 @@ import config from '../../../config.ts';
import { ApplicationCommandFlags, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { failColor, infoColor1, safelyDismissMsg, somethingWentWrong } from '../../commandUtils.ts';
import { activityMaxPlayersId, activitySubtitleId, activityTitleId, idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
import { addTokenToMap, selfDestructMessage } from '../tokenCleanup.ts';
import { addTokenToMap, deleteTokenEarly, selfDestructMessage } from '../tokenCleanup.ts';
import { customId as gameSelectionId } from './step1-gameSelection.ts';
import { customId as openCustomModalId } from './step1a-openCustomModal.ts';
import utils from '../../utils.ts';
@ -11,6 +11,7 @@ export const customId = 'verifyCustomActivity';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.components?.length && interaction.guildId && interaction.channelId && interaction.member) {
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
// Parse out our data
const tempDataMap: Map<string, string> = new Map();
for (const row of interaction.data.components) {

View File

@ -2,7 +2,7 @@ import { Bot, Interaction } from '../../../deps.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { createLFGPost, getFinalActivity } from './utils.ts';
import { eventDateId, eventDescriptionId, eventTimeId, eventTimeZoneId, idSeparator, noDescProvided, pathIdxSeparator } from '../eventUtils.ts';
import { addTokenToMap } from '../tokenCleanup.ts';
import { addTokenToMap, deleteTokenEarly } from '../tokenCleanup.ts';
import { Activities, Activity } from './activities.ts';
import { getDateFromRawInput } from './dateTimeUtils.ts';
import utils from '../../utils.ts';
@ -12,6 +12,9 @@ export const customId = 'finalize';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.components?.length && interaction.guildId && interaction.channelId && interaction.member && interaction.member.user) {
// User selected activity and has filled out fields, delete the selectMenus
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
const tempDataMap: Map<string, string> = new Map();
for (const row of interaction.data.components) {
if (row.components?.[0]) {

View File

@ -1,7 +1,7 @@
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
import { somethingWentWrong, warnColor } from '../../commandUtils.ts';
import { eventDateId, eventTimeId, eventTimeZoneId, idSeparator, LfgEmbedIndexes, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
import { addTokenToMap } from '../tokenCleanup.ts';
import { addTokenToMap, deleteTokenEarly } from '../tokenCleanup.ts';
import utils from '../../utils.ts';
import { applyEditButtons, applyEditMessage } from './utils.ts';
import { getDateFromRawInput } from '../event-creation/dateTimeUtils.ts';
@ -11,6 +11,7 @@ export const customId = 'applyDateTime';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.data?.components?.length && interaction.member && interaction.channelId && interaction.guildId) {
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('applyDateTime.ts', 'get eventMessage', e));

View File

@ -1,7 +1,7 @@
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { eventDescriptionId, idSeparator, LfgEmbedIndexes, noDescProvided, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
import { addTokenToMap } from '../tokenCleanup.ts';
import { addTokenToMap, deleteTokenEarly } from '../tokenCleanup.ts';
import utils from '../../utils.ts';
import { applyEditButtons, applyEditMessage } from './utils.ts';
@ -9,6 +9,7 @@ export const customId = 'applyDescription';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.data?.components?.length && interaction.member && interaction.channelId && interaction.guildId) {
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('applyDescription.ts', 'get eventMessage', e));

View File

@ -1,5 +1,4 @@
import { Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
import { deleteTokenEarly } from '../tokenCleanup.ts';
import { generateCustomActivityFields, idSeparator } from '../eventUtils.ts';
import { customId as editActivityCustomId } from './editActivity.ts';
import utils from '../../utils.ts';
@ -12,8 +11,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
// Light Telemetry
dbClient.execute(queries.callIncCnt('btn-eeCustomAct')).catch((e) => utils.commonLoggers.dbError('step1a-openCustomModal.ts', 'call sproc INC_CNT on', e));
deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.Modal,
data: {

View File

@ -115,6 +115,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
// Get event to apply edit
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('editActivity.ts', 'get eventMessage', e));
if (eventMessage && eventMessage.embeds[0].fields) {
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
// Update member lists
const [currentMemberCount, _oldMaxMemberCount] = getEventMemberCount(eventMessage.embeds[0].fields[LfgEmbedIndexes.JoinedMembers].name);
const currentMembers = getLfgMembers(eventMessage.embeds[0].fields[LfgEmbedIndexes.JoinedMembers].value);

View File

@ -2,7 +2,6 @@ import { Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
import { dbClient, queries } from '../../db.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { dateTimeFields, idSeparator, LfgEmbedIndexes, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
import { deleteTokenEarly } from '../tokenCleanup.ts';
import { monthsShort } from '../event-creation/dateTimeUtils.ts';
import utils from '../../utils.ts';
import { customId as applyDateTimeCustomId } from './applyDateTime.ts';
@ -13,7 +12,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId) {
// Light Telemetry
dbClient.execute(queries.callIncCnt('btn-eeChangeTime')).catch((e) => utils.commonLoggers.dbError('editDateTime.ts', 'call sproc INC_CNT on', e));
deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('editDateTime.ts', 'get eventMessage', e));

View File

@ -2,7 +2,6 @@ import { Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
import { dbClient, queries } from '../../db.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { descriptionTextField, idSeparator, LfgEmbedIndexes, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
import { deleteTokenEarly } from '../tokenCleanup.ts';
import utils from '../../utils.ts';
import { customId as applyDescriptionCustomId } from './applyDescription.ts';
@ -12,7 +11,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId) {
// Light Telemetry
dbClient.execute(queries.callIncCnt('btn-eeChangeDesc')).catch((e) => utils.commonLoggers.dbError('editDescription.ts', 'call sproc INC_CNT on', e));
deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('editDescription.ts', 'get eventMessage', e));

View File

@ -159,7 +159,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
The Discord Slash Command system will ensure you provide all the required details.`,
});
// Set permissions for self, skip if we already failed to set roles
!logChannelErrorOut && await bot.helpers.editChannelPermissionOverrides(logChannelId, {
id: botId,
@ -273,7 +272,7 @@ The Discord Slash Command system will ensure you provide all the required detail
oldLfgMsgs.forEach((oldEventId) => {
const oldEvent = messages.get(oldEventId);
if (oldEvent && oldEvent.embeds[0].fields && oldEvent.embeds[0].footer) {
const eventMembers = [...getLfgMembers(oldEvent.embeds[0].fields[LfgEmbedIndexes.JoinedMembers].value), ...getLfgMembers(oldEvent.embeds[0].fields[LfgEmbedIndexes.AlternateMembers].value)]
const eventMembers = [...getLfgMembers(oldEvent.embeds[0].fields[LfgEmbedIndexes.JoinedMembers].value), ...getLfgMembers(oldEvent.embeds[0].fields[LfgEmbedIndexes.AlternateMembers].value)];
const eventDateTime = new Date(parseInt((oldEvent.embeds[0].fields[LfgEmbedIndexes.StartTime].value.split('tz#')[1] || ' ').slice(0, -1)));
if (!isNaN(eventDateTime.getTime())) {
const eventDateTimeStr = (oldEvent.embeds[0].fields[LfgEmbedIndexes.StartTime].value.split('](')[0] || ' ').slice(1);
@ -290,7 +289,9 @@ The Discord Slash Command system will ensure you provide all the required detail
components: generateLFGButtons(false),
}],
}).catch((e: Error) => utils.commonLoggers.messageEditError('setup.ts', 'retrofit event', e));
dbClient.execute(queries.insertEvent, [oldEvent.id, oldEvent.channelId, interaction.guildId, ownerId, eventDateTime]).catch((e) => utils.commonLoggers.dbError('setup.ts@retrofit', 'INSERT event to DB', e));
dbClient.execute(queries.insertEvent, [oldEvent.id, oldEvent.channelId, interaction.guildId, ownerId, eventDateTime]).catch((e) =>
utils.commonLoggers.dbError('setup.ts@retrofit', 'INSERT event to DB', e)
);
}
}
});