sonar cleanup

This commit is contained in:
Ean Milligan 2024-05-18 18:32:35 -04:00
parent 5a8cd8e8bb
commit d8b5f010c2
17 changed files with 149 additions and 135 deletions

View File

@ -111,7 +111,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
}).catch((e: Error) => utils.commonLoggers.interactionSendError('step1-gameSelection.ts:ping', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('step1-gameSelection.ts:ping', interaction, e));
// Update the original game selector // Update the original game selector
await bot.helpers.editOriginalInteractionResponse(tokenMap.get(generateMapId(interaction.guildId, interaction.channelId, interaction.member.id))?.token || '', { await bot.helpers.editOriginalInteractionResponse(tokenMap.get(generateMapId(interaction.guildId, interaction.channelId, interaction.member.id))?.token ?? '', {
components: selectMenus, components: selectMenus,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('step1-gameSelection.ts:edit', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('step1-gameSelection.ts:edit', interaction, e));
} else { } else {

View File

@ -12,7 +12,7 @@ import { queries } from '../../db/common.ts';
export const customId = 'finalize'; export const customId = 'finalize';
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.components?.length && interaction.guildId && interaction.channelId && interaction.member && interaction.member.user) { if (interaction.data?.components?.length && interaction.guildId && interaction.channelId && interaction?.member?.user) {
// User selected activity and has filled out fields, delete the selectMenus // User selected activity and has filled out fields, delete the selectMenus
await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id); await deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);

View File

@ -11,7 +11,7 @@ export const customId = 'createEvent';
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if ( if (
interaction.data?.customId && interaction.member && interaction.guildId && interaction.channelId && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields interaction.data?.customId && interaction.member && interaction.guildId && interaction.channelId && interaction?.message?.embeds?.[0]?.fields
) { ) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt(interaction.data.customId.includes(idSeparator) ? 'btn-createWLEvt' : 'btn-createEvt')).catch((e) => dbClient.execute(queries.callIncCnt(interaction.data.customId.includes(idSeparator) ? 'btn-createWLEvt' : 'btn-createEvt')).catch((e) =>

View File

@ -27,7 +27,7 @@ import { customId as editEventCustomId } from '../live-event/editEvent.ts';
export const getNestedActivity = (idxPath: Array<number>, activities: Array<Activity>): Array<Activity> => { export const getNestedActivity = (idxPath: Array<number>, activities: Array<Activity>): Array<Activity> => {
const nextIdx = idxPath[0]; const nextIdx = idxPath[0];
if (idxPath.length && activities[nextIdx] && activities[nextIdx].options) { if (idxPath.length && activities[nextIdx]?.options) {
idxPath.shift(); idxPath.shift();
return getNestedActivity(idxPath, activities[nextIdx].options || []); return getNestedActivity(idxPath, activities[nextIdx].options || []);
} else { } else {
@ -160,7 +160,7 @@ export const createLFGPost = (
name: 'Description:', name: 'Description:',
value: eventDescription, value: eventDescription,
}, { }, {
name: generateMemberTitle(memberList, activity.maxMembers || 0), name: generateMemberTitle(memberList, activity.maxMembers ?? 0),
value: generateMemberList(memberList), value: generateMemberList(memberList),
inline: true, inline: true,
}, { }, {

View File

@ -8,7 +8,7 @@ import { alternateMemberToEvent } from './utils.ts';
export const customId = 'alternateEvent'; export const customId = 'alternateEvent';
const execute = (bot: Bot, interaction: Interaction) => { const execute = (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.member.user && interaction.channelId && interaction.message && interaction.message.embeds[0]) { if (interaction.data?.customId && interaction?.member?.user && interaction.channelId && interaction?.message?.embeds?.[0]) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt('btn-altEvent')).catch((e) => utils.commonLoggers.dbError('alternateEvent.ts', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt('btn-altEvent')).catch((e) => utils.commonLoggers.dbError('alternateEvent.ts', 'call sproc INC_CNT on', e));

View File

@ -8,7 +8,7 @@ import { alternateMemberToEvent } from './utils.ts';
export const customId = 'alternateRequest'; export const customId = 'alternateRequest';
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.user && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].description) { if (interaction.data?.customId && interaction.user && interaction?.message?.embeds?.[0]?.description) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt('btn-joinReqAlt')).catch((e) => utils.commonLoggers.dbError('alternateRequest.ts', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt('btn-joinReqAlt')).catch((e) => utils.commonLoggers.dbError('alternateRequest.ts', 'call sproc INC_CNT on', e));

View File

@ -12,7 +12,7 @@ export const confirmedCustomId = 'confirmedCustomId';
export const confirmStr = 'yes'; export const confirmStr = 'yes';
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.data?.components?.length && interaction.channelId && interaction.guildId && interaction.member && interaction.member.user) { if (interaction.data?.customId && interaction.data?.components?.length && interaction.channelId && interaction.guildId && interaction?.member?.user) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt('btn-confirmDelEvent')).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@incCnt', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt('btn-confirmDelEvent')).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@incCnt', 'call sproc INC_CNT on', e));
@ -38,46 +38,60 @@ const execute = async (bot: Bot, interaction: Interaction) => {
const userId = interaction.member.id; const userId = interaction.member.id;
const userName = interaction.member.user.username; const userName = interaction.member.user.username;
// Delete event // Delete event
bot.helpers.deleteMessage(evtChannelId, evtMessageId, 'User deleted event').then(() => { bot.helpers
.deleteMessage(evtChannelId, evtMessageId, 'User deleted event')
.then(() => {
dbClient.execute(queries.deleteEvent, [evtChannelId, evtMessageId]).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@deleteEvent', 'delete event from', e)); dbClient.execute(queries.deleteEvent, [evtChannelId, evtMessageId]).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@deleteEvent', 'delete event from', e));
// Acknowledge user so discord doesn't get annoyed // Acknowledge user so discord doesn't get annoyed
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { bot.helpers
.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource, type: InteractionResponseTypes.ChannelMessageWithSource,
data: { data: {
flags: ApplicationCommandFlags.Ephemeral, flags: ApplicationCommandFlags.Ephemeral,
embeds: [{ embeds: [
{
color: successColor, color: successColor,
title: 'Event successfully deleted.', title: 'Event successfully deleted.',
description: safelyDismissMsg, description: safelyDismissMsg,
}],
}, },
}).catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e)); ],
},
})
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
if (actionByManager) { if (actionByManager) {
const ownerId = BigInt(eventMessage?.embeds[0].footer?.iconUrl?.split('#')[1] || '0'); const ownerId = BigInt(eventMessage?.embeds[0].footer?.iconUrl?.split('#')[1] || '0');
const eventEmbed = eventMessage?.embeds[0] || { title: 'Event not found', color: failColor }; const eventEmbed = eventMessage?.embeds[0] || { title: 'Event not found', color: failColor };
bot.helpers.sendMessage(lfgChannelSetting.logChannelId, { bot.helpers
embeds: [{ .sendMessage(lfgChannelSetting.logChannelId, {
embeds: [
{
color: infoColor2, color: infoColor2,
title: `Event deleted by a ${config.name} Manager`, title: `Event deleted by a ${config.name} Manager`,
description: `The following event was deleted by ${userName} - <@${userId}>.`, description: `The following event was deleted by ${userName} - <@${userId}>.`,
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
}, eventEmbed], },
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send log message', e)); eventEmbed,
],
})
.catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send log message', e));
sendDirectMessage(bot, ownerId, { sendDirectMessage(bot, ownerId, {
embeds: [{ embeds: [
{
color: infoColor2, color: infoColor2,
title: `Notice: A ${config.name} Manager has deleted one of your events in ${guildName}`, title: `Notice: A ${config.name} Manager has deleted one of your events in ${guildName}`,
description: 'The deleted event is listed below.', description: 'The deleted event is listed below.',
fields: [ fields: [
{ {
name: `${config.name} Manager:`, name: `${config.name} Manager:`,
value: generateMemberList([{ value: generateMemberList([
{
id: userId, id: userId,
name: userName, name: userName,
}]), },
]),
inline: true, inline: true,
}, },
{ {
@ -85,35 +99,40 @@ const execute = async (bot: Bot, interaction: Interaction) => {
value: `Please reach out to the ${config.name} Manager that performed this action, or the moderators/administrators of ${guildName}.`, value: `Please reach out to the ${config.name} Manager that performed this action, or the moderators/administrators of ${guildName}.`,
}, },
], ],
}, eventEmbed], },
eventEmbed,
],
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send DM fail', e)); }).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send DM fail', e));
} }
}).catch((e) => { })
.catch((e) => {
utils.commonLoggers.messageDeleteError('deleteConfirmed.ts', 'deleteEventFailedDB', e); utils.commonLoggers.messageDeleteError('deleteConfirmed.ts', 'deleteEventFailedDB', e);
somethingWentWrong(bot, interaction, 'deleteEventMessageInDeleteConfirmedButton'); somethingWentWrong(bot, interaction, 'deleteEventMessageInDeleteConfirmedButton');
}); });
} else { } else if (tempDataMap.get(confirmedCustomId)) {
// User either did not type yes confirm field was missing, lets see which it was // User either did not type yes confirm field was missing, lets see which it was
if (tempDataMap.get(confirmedCustomId)) {
// User did not type yes. // User did not type yes.
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { bot.helpers
.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource, type: InteractionResponseTypes.ChannelMessageWithSource,
data: { data: {
flags: ApplicationCommandFlags.Ephemeral, flags: ApplicationCommandFlags.Ephemeral,
embeds: [{ embeds: [
{
color: infoColor1, color: infoColor1,
title: 'Event not deleted.', title: 'Event not deleted.',
description: `If you are trying to delete the event, please make sure you type \`${confirmStr}\` into the field provided. description: `If you are trying to delete the event, please make sure you type \`${confirmStr}\` into the field provided.
${safelyDismissMsg}`, ${safelyDismissMsg}`,
}],
}, },
}).catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e)); ],
},
})
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
} else { } else {
// Field was missing // Field was missing
somethingWentWrong(bot, interaction, 'noIdsFromDeleteConfirmedButton'); somethingWentWrong(bot, interaction, 'noIdsFromDeleteConfirmedButton');
} }
}
} else { } else {
somethingWentWrong(bot, interaction, 'noDataFromDeleteConfirmedButton'); somethingWentWrong(bot, interaction, 'noDataFromDeleteConfirmedButton');
} }

View File

@ -9,7 +9,7 @@ import utils from '../../utils.ts';
export const customId = 'deleteEvent'; export const customId = 'deleteEvent';
const execute = (bot: Bot, interaction: Interaction) => { const execute = (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.member.user && interaction.channelId && interaction.guildId && interaction.message && interaction.message.embeds[0]) { if (interaction.data?.customId && interaction?.member?.user && interaction.channelId && interaction.guildId && interaction?.message?.embeds?.[0]) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt('btn-delEvent')).catch((e) => utils.commonLoggers.dbError('deleteEvent.ts', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt('btn-delEvent')).catch((e) => utils.commonLoggers.dbError('deleteEvent.ts', 'call sproc INC_CNT on', e));

View File

@ -109,7 +109,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
!selectedActivity.maxMembers || !selectedCategory || !selectedActivity.name || (isNaN(selectedActivity.maxMembers) || (selectedActivity.maxMembers < 1 || selectedActivity.maxMembers > 99)) !selectedActivity.maxMembers || !selectedCategory || !selectedActivity.name || (isNaN(selectedActivity.maxMembers) || (selectedActivity.maxMembers < 1 || selectedActivity.maxMembers > 99))
) { ) {
// Verify fields exist // Verify fields exist
somethingWentWrong(bot, interaction, `parseFailInEditCustomActivity@${selectedCategory}|${selectedActivity.name}|${selectedActivity.maxMembers || 'undefined'}$`); somethingWentWrong(bot, interaction, `parseFailInEditCustomActivity@${selectedCategory}|${selectedActivity.name}|${selectedActivity.maxMembers ?? 'undefined'}$`);
return; return;
} }
@ -181,7 +181,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
}).catch((e: Error) => utils.commonLoggers.interactionSendError('editActivity.ts@ping', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('editActivity.ts@ping', interaction, e));
// Update the original game selector // Update the original game selector
await bot.helpers.editOriginalInteractionResponse(tokenMap.get(generateMapId(interaction.guildId, interaction.channelId, interaction.member.id))?.token || '', { await bot.helpers.editOriginalInteractionResponse(tokenMap.get(generateMapId(interaction.guildId, interaction.channelId, interaction.member.id))?.token ?? '', {
components: selectMenus, components: selectMenus,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('editActivity.ts@edit', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('editActivity.ts@edit', interaction, e));
} else { } else {

View File

@ -14,8 +14,7 @@ export const customId = 'editEvent';
const execute = (bot: Bot, interaction: Interaction) => { const execute = (bot: Bot, interaction: Interaction) => {
if ( if (
interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId && interaction.message && interaction.message.components && interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId && interaction?.message?.components?.[0].components
interaction.message.components[0].components
) { ) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt('btn-editEvent')).catch((e) => utils.commonLoggers.dbError('editEvent.ts', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt('btn-editEvent')).catch((e) => utils.commonLoggers.dbError('editEvent.ts', 'call sproc INC_CNT on', e));

View File

@ -11,8 +11,7 @@ export const customId = 'joinEvent';
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if ( if (
interaction.data?.customId && interaction.member && interaction.member.user && interaction.channelId && interaction.guildId && interaction.message && interaction.message.embeds[0] && interaction.data?.customId && interaction?.member?.user && interaction.channelId && interaction.guildId && interaction?.message?.embeds?.[0]?.fields
interaction.message.embeds[0].fields
) { ) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt(interaction.data.customId.includes(idSeparator) ? 'btn-joinWLEvent' : 'btn-joinEvent')).catch((e) => dbClient.execute(queries.callIncCnt(interaction.data.customId.includes(idSeparator) ? 'btn-joinWLEvent' : 'btn-joinEvent')).catch((e) =>
@ -62,7 +61,7 @@ ${safelyDismissMsg}`,
If this request is urgent, please speak with${urgentManagerStr}the owner of [this event](${messageUrl}), <@${ownerId}>, to resolve the issue. If this request is urgent, please speak with${urgentManagerStr}the owner of [this event](${messageUrl}), <@${ownerId}>, to resolve the issue.
The status of your recent Join Request for [this event](${messageUrl}) is: \`${joinRequestMap.get(joinRequestKey)?.status || 'Failed to retrieve status'}\` The status of your recent Join Request for [this event](${messageUrl}) is: \`${joinRequestMap.get(joinRequestKey)?.status ?? 'Failed to retrieve status'}\`
${safelyDismissMsg}`, ${safelyDismissMsg}`,
}], }],

View File

@ -13,8 +13,7 @@ export const denyStr = 'denied';
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if ( if (
interaction.data?.customId && interaction.user && interaction.channelId && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields && interaction.data?.customId && interaction.user && interaction.channelId && interaction?.message?.embeds?.[0]?.fields && interaction?.message?.embeds?.[0]?.description
interaction.message.embeds[0].description
) { ) {
const memberRequesting = getLfgMembers(interaction.message.embeds[0].fields[0].value || '')[0]; const memberRequesting = getLfgMembers(interaction.message.embeds[0].fields[0].value || '')[0];
const approved = interaction.data.customId.includes(approveStr); const approved = interaction.data.customId.includes(approveStr);

View File

@ -8,7 +8,7 @@ import { removeMemberFromEvent } from './utils.ts';
export const customId = 'leaveEvent'; export const customId = 'leaveEvent';
const execute = (bot: Bot, interaction: Interaction) => { const execute = (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId && interaction.message && interaction.message.embeds[0]) { if (interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId && interaction?.message?.embeds?.[0]) {
// Light Telemetry // Light Telemetry
dbClient.execute(queries.callIncCnt('btn-leaveEvent')).catch((e) => utils.commonLoggers.dbError('leaveEvent.ts', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt('btn-leaveEvent')).catch((e) => utils.commonLoggers.dbError('leaveEvent.ts', 'call sproc INC_CNT on', e));

View File

@ -129,9 +129,9 @@ ${safelyDismissMsg}`,
}; };
// Generic no response response // Generic no response response
const noEdit = (bot: Bot, interaction: Interaction, loudAcknowledge: boolean) => { const noEdit = async (bot: Bot, interaction: Interaction, loudAcknowledge: boolean) => {
if (loudAcknowledge) { if (loudAcknowledge) {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource, type: InteractionResponseTypes.ChannelMessageWithSource,
data: { data: {
flags: ApplicationCommandFlags.Ephemeral, flags: ApplicationCommandFlags.Ephemeral,
@ -145,7 +145,7 @@ ${safelyDismissMsg}`,
}, },
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
} else { } else {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.DeferredUpdateMessage, type: InteractionResponseTypes.DeferredUpdateMessage,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
} }

View File

@ -45,7 +45,7 @@ const details: CommandDetails = {
}; };
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.options?.[0].options && interaction.channelId && interaction.guildId && interaction.member && interaction.member.user) { if (interaction.data?.options?.[0].options && interaction.channelId && interaction.guildId && interaction?.member?.user) {
// Get action and log to db // Get action and log to db
const actionName = interaction.data.options[0].name; const actionName = interaction.data.options[0].name;
dbClient.execute(queries.callIncCnt(`cmd-${actionName}`)).catch((e) => utils.commonLoggers.dbError('managerJLA.ts', 'call sproc INC_CNT on', e)); dbClient.execute(queries.callIncCnt(`cmd-${actionName}`)).catch((e) => utils.commonLoggers.dbError('managerJLA.ts', 'call sproc INC_CNT on', e));

View File

@ -241,7 +241,7 @@ The Discord Slash Command system will ensure you provide all the required detail
const msgsToDel: Array<bigint> = []; const msgsToDel: Array<bigint> = [];
const oldLfgMsgs: Array<bigint> = []; const oldLfgMsgs: Array<bigint> = [];
messages.forEach((msg) => { messages.forEach((msg) => {
if (msg.authorId === botId && msg.embeds.length && msg.embeds[0].footer && msg.embeds[0].footer.text.includes('Created by:')) { if (msg.authorId === botId && msg.embeds.length && msg.embeds[0].footer?.text.includes('Created by:')) {
oldLfgMsgs.push(msg.id); oldLfgMsgs.push(msg.id);
} else { } else {
msgsToDel.push(msg.id); msgsToDel.push(msg.id);
@ -266,7 +266,7 @@ The Discord Slash Command system will ensure you provide all the required detail
oldEvent.embeds[0].fields[LfgEmbedIndexes.StartTime].value = generateTimeFieldStr(eventDateTimeStr, eventDateTime); oldEvent.embeds[0].fields[LfgEmbedIndexes.StartTime].value = generateTimeFieldStr(eventDateTimeStr, eventDateTime);
oldEvent.embeds[0].footer.text = oldEvent.embeds[0].footer.text.split(' | ')[0]; oldEvent.embeds[0].footer.text = oldEvent.embeds[0].footer.text.split(' | ')[0];
const ownerName = oldEvent.embeds[0].footer.text.split(': ')[1]; const ownerName = oldEvent.embeds[0].footer.text.split(': ')[1];
const ownerId = eventMembers.find((member) => ownerName === member.name)?.id || 0n; const ownerId = eventMembers.find((member) => ownerName === member.name)?.id ?? 0n;
oldEvent.embeds[0].footer.iconUrl = `${config.links.creatorIcon}#${ownerId}`; oldEvent.embeds[0].footer.iconUrl = `${config.links.creatorIcon}#${ownerId}`;
bot.helpers.editMessage(oldEvent.channelId, oldEvent.id, { bot.helpers.editMessage(oldEvent.channelId, oldEvent.id, {
content: '', content: '',

View File

@ -11,7 +11,7 @@ const tzOverrides: Array<Array<string>> = [
['PST', '-08:00'], ['PST', '-08:00'],
['IST', '+05:30'], ['IST', '+05:30'],
]; ];
const abbrOverrides: Array<string> = tzOverrides.map(tzSet => tzSet[0]); const abbrOverrides: Array<string> = tzOverrides.map((tzSet) => tzSet[0]);
// Prefill the map // Prefill the map
for (const override of tzOverrides) { for (const override of tzOverrides) {
@ -22,22 +22,20 @@ for (const override of tzOverrides) {
const attemptAdd = (tzAbbr: string, tzOffset: string) => { const attemptAdd = (tzAbbr: string, tzOffset: string) => {
if (!abbrOverrides.includes(tzAbbr)) { if (!abbrOverrides.includes(tzAbbr)) {
if (tzMap.has(tzAbbr) && tzMap.get(tzAbbr) !== tzOffset) { if (tzMap.has(tzAbbr) && tzMap.get(tzAbbr) !== tzOffset) {
console.error(`DOUBLED TZ ABBR WITH DIFF OFFSETS: ${tzAbbr} | ${tzOffset} | ${tzMap.get(tzAbbr)}`) console.error(`DOUBLED TZ ABBR WITH DIFF OFFSETS: ${tzAbbr} | ${tzOffset} | ${tzMap.get(tzAbbr)}`);
} else { } else if (!tzAbbr.includes('+') && !tzAbbr.includes('-')) {
if (!tzAbbr.includes('+') && !tzAbbr.includes('-')) {
tzMap.set(tzAbbr, tzOffset); tzMap.set(tzAbbr, tzOffset);
} }
} }
}
}; };
// Get each TZ from the csv // Get each TZ from the csv
for (const row of csvRows) { for (const row of csvRows) {
const [rawSTDOffset, rawDSTOffset, rawSTDAbbr, rawDSTAbbr] = row.replaceAll('?', '-').toUpperCase().split(','); const [rawSTDOffset, rawDSTOffset, rawSTDAbbr, rawDSTAbbr] = row.replaceAll('?', '-').toUpperCase().split(',');
const STDOffset = (rawSTDOffset || ''); const STDOffset = rawSTDOffset || '';
const DSTOffset = (rawDSTOffset || ''); const DSTOffset = rawDSTOffset || '';
const STDAbbr = (rawSTDAbbr || ''); const STDAbbr = rawSTDAbbr || '';
const DSTAbbr = (rawDSTAbbr || ''); const DSTAbbr = rawDSTAbbr || '';
attemptAdd(STDAbbr, STDOffset); attemptAdd(STDAbbr, STDOffset);
if (STDAbbr !== DSTAbbr) { if (STDAbbr !== DSTAbbr) {
@ -47,7 +45,7 @@ for (const row of csvRows) {
// Log it out to copy to source // Log it out to copy to source
const tzIt = tzMap.entries(); const tzIt = tzMap.entries();
let tzVal = tzIt.next() let tzVal = tzIt.next();
while (!tzVal.done) { while (!tzVal.done) {
if (tzVal.value[0]) { if (tzVal.value[0]) {
console.log(`['${tzVal.value[0]}','${tzVal.value[1]}'],`); console.log(`['${tzVal.value[0]}','${tzVal.value[1]}'],`);