V1.0.1 - Fix setup permission issue, sonar fixes
This commit is contained in:
parent
3db443effc
commit
33d9770b5f
|
@ -1,6 +1,6 @@
|
|||
export const config = {
|
||||
'name': 'Group Up', // Name of the bot
|
||||
'version': '1.0.0', // Version of the bot
|
||||
'version': '1.0.1', // Version of the bot
|
||||
'token': 'the_bot_token', // Discord API Token for this bot
|
||||
'localToken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
|
||||
'prefix': '/', // Prefix for all commands
|
||||
|
|
|
@ -49,7 +49,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
let prefillTimeZone = '';
|
||||
let prefillDate = '';
|
||||
let prefillDescription = '';
|
||||
if (interaction.message && interaction.message.embeds[0].fields && interaction.message.embeds[0].fields[LfgEmbedIndexes.StartTime].name === lfgStartTimeName) {
|
||||
if (interaction.message?.embeds[0].fields && interaction.message.embeds[0].fields[LfgEmbedIndexes.StartTime].name === lfgStartTimeName) {
|
||||
if (interaction.message.embeds[0].fields[LfgEmbedIndexes.StartTime].value !== invalidDateTimeStr) {
|
||||
let rawEventDateTime = interaction.message.embeds[0].fields[LfgEmbedIndexes.StartTime].value.split('\n')[0].split(' ');
|
||||
const monthIdx = rawEventDateTime.findIndex((item) => monthsShort.includes(item.toUpperCase()));
|
||||
|
@ -103,7 +103,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
});
|
||||
selectMenus.push(generateCustomEventRow(prefillArray.length ? prefillArray[0] : '', prefillArray.length > 1 ? prefillArray[prefillArray.length - 1] : ''));
|
||||
|
||||
if (interaction.data.customId && interaction.data.customId.includes(fillerChar)) {
|
||||
if (interaction.data.customId?.includes(fillerChar)) {
|
||||
// Let discord know we didn't ignore the user
|
||||
await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.DeferredUpdateMessage,
|
||||
|
|
|
@ -22,9 +22,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
}
|
||||
|
||||
// Remove any pipe characters to avoid issues down the process
|
||||
const activityTitle = (tempDataMap.get(activityTitleId) || '').replace(/\|/g, '');
|
||||
const activitySubtitle = (tempDataMap.get(activitySubtitleId) || '').replace(/\|/g, '');
|
||||
const activityMaxPlayers = parseInt(tempDataMap.get(activityMaxPlayersId) || '0');
|
||||
const activityTitle = (tempDataMap.get(activityTitleId) ?? '').replace(/\|/g, '');
|
||||
const activitySubtitle = (tempDataMap.get(activitySubtitleId) ?? '').replace(/\|/g, '');
|
||||
const activityMaxPlayers = parseInt(tempDataMap.get(activityMaxPlayersId) ?? '0');
|
||||
if (isNaN(activityMaxPlayers) || activityMaxPlayers < 1 || activityMaxPlayers > 99) {
|
||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
|
|
|
@ -55,10 +55,10 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
);
|
||||
}
|
||||
|
||||
const rawEventTime = tempDataMap.get(eventTimeId) || '';
|
||||
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || '';
|
||||
const rawEventDate = tempDataMap.get(eventDateId) || '';
|
||||
const eventDescription = tempDataMap.get(eventDescriptionId) || noDescProvided;
|
||||
const rawEventTime = tempDataMap.get(eventTimeId) ?? '';
|
||||
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) ?? '';
|
||||
const rawEventDate = tempDataMap.get(eventDateId) ?? '';
|
||||
const eventDescription = tempDataMap.get(eventDescriptionId) ?? noDescProvided;
|
||||
if (!rawEventTime || !rawEventTimeZone || !rawEventDate) {
|
||||
// Error out if user somehow failed to provide one of the fields (eventDescription is allowed to be null/empty)
|
||||
somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`);
|
||||
|
|
|
@ -55,7 +55,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (eventMessage && eventMessage.embeds[0].fields) {
|
||||
if (eventMessage?.embeds[0].fields) {
|
||||
eventMessage.embeds[0].fields[LfgEmbedIndexes.StartTime].value = generateTimeFieldStr(eventDateTimeStr, eventDateTime);
|
||||
const tIdx = eventMessage.embeds[0].fields[LfgEmbedIndexes.ICSLink].value.indexOf('?t=') + 3;
|
||||
const nIdx = eventMessage.embeds[0].fields[LfgEmbedIndexes.ICSLink].value.indexOf('&n=');
|
||||
|
|
|
@ -17,13 +17,13 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
for (const row of interaction.data.components) {
|
||||
if (row.components?.[0]) {
|
||||
const textField = row.components[0];
|
||||
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || '');
|
||||
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || noDescProvided);
|
||||
}
|
||||
}
|
||||
const newDescription = tempDataMap.get(eventDescriptionId);
|
||||
|
||||
if (eventMessage && eventMessage.embeds[0].fields) {
|
||||
eventMessage.embeds[0].fields[LfgEmbedIndexes.Description].value = newDescription || noDescProvided;
|
||||
if (eventMessage?.embeds[0].fields) {
|
||||
eventMessage.embeds[0].fields[LfgEmbedIndexes.Description].value = newDescription ?? noDescProvided;
|
||||
|
||||
// Send edit confirmation
|
||||
addTokenToMap(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
|
||||
|
|
|
@ -65,9 +65,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
}
|
||||
|
||||
// Remove any pipe characters to avoid issues down the process
|
||||
const activityTitle = (tempDataMap.get(activityTitleId) || '').replace(/\|/g, '');
|
||||
const activitySubtitle = (tempDataMap.get(activitySubtitleId) || '').replace(/\|/g, '');
|
||||
const activityMaxPlayers = parseInt(tempDataMap.get(activityMaxPlayersId) || '0');
|
||||
const activityTitle = (tempDataMap.get(activityTitleId) ?? '').replace(/\|/g, '');
|
||||
const activitySubtitle = (tempDataMap.get(activitySubtitleId) ?? '').replace(/\|/g, '');
|
||||
const activityMaxPlayers = parseInt(tempDataMap.get(activityMaxPlayersId) ?? '0');
|
||||
if (isNaN(activityMaxPlayers) || activityMaxPlayers < 1 || activityMaxPlayers > 99) {
|
||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
|
@ -114,7 +114,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) {
|
||||
if (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);
|
||||
|
@ -173,7 +173,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
|
||||
selectMenus.push(makeCustomEventRow(interaction.data.customId.replaceAll(fillerChar, '').split(idSeparator)[1] || ''));
|
||||
|
||||
if (interaction.data.customId && interaction.data.customId.includes(fillerChar)) {
|
||||
if (interaction.data.customId.includes(fillerChar)) {
|
||||
// Let discord know we didn't ignore the user
|
||||
await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.DeferredUpdateMessage,
|
||||
|
|
|
@ -15,7 +15,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
const [evtGuildId, 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('editActivity.ts', 'get eventMessage', e));
|
||||
|
||||
if (eventMessage && eventMessage.embeds[0]) {
|
||||
if (eventMessage?.embeds[0]) {
|
||||
// Remove user from event
|
||||
removeMemberFromEvent(bot, interaction, eventMessage.embeds[0], evtMessageId, evtChannelId, interaction.user.id, evtGuildId, true);
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,7 @@ export const addTokenToMap = (bot: Bot, interaction: Interaction, guildId: bigin
|
|||
token: interaction.token,
|
||||
timeoutId: setTimeout(
|
||||
(guildId, channelId, userId) => {
|
||||
deleteTokenEarly(bot, interaction, guildId, channelId, userId);
|
||||
deleteTokenEarly(bot, interaction, guildId, channelId, userId).catch((e) => utils.commonLoggers.interactionSendError('tokenCleanup.ts:addTokenToMap', interaction, e));
|
||||
},
|
||||
tokenTimeoutMS,
|
||||
guildId,
|
||||
|
@ -30,8 +30,8 @@ export const addTokenToMap = (bot: Bot, interaction: Interaction, guildId: bigin
|
|||
|
||||
export const deleteTokenEarly = async (bot: Bot, interaction: Interaction, guildId: bigint, channelId: bigint, userId: bigint) => {
|
||||
const tokenMapEntry = tokenMap.get(generateMapId(guildId, channelId, userId));
|
||||
if (tokenMapEntry && tokenMapEntry.token) {
|
||||
await bot.helpers.deleteOriginalInteractionResponse(tokenMap.get(generateMapId(guildId, channelId, userId))?.token || '').catch((e: Error) =>
|
||||
if (tokenMapEntry?.token) {
|
||||
await bot.helpers.deleteOriginalInteractionResponse(tokenMap.get(generateMapId(guildId, channelId, userId))?.token ?? '').catch((e: Error) =>
|
||||
utils.commonLoggers.interactionSendError('tokenCleanup.ts:deleteTokenEarly', interaction, e)
|
||||
);
|
||||
clearTimeout(tokenMapEntry.timeoutId);
|
||||
|
|
|
@ -61,8 +61,8 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
for (const option of interaction.data.options[0].options) {
|
||||
tempDataMap.set(option.name || 'missingCustomId', option.value as string || '');
|
||||
}
|
||||
const eventLink = tempDataMap.get(eventLinkName) || '';
|
||||
const userToAdd = BigInt(tempDataMap.get(userName) || '0');
|
||||
const eventLink = tempDataMap.get(eventLinkName) ?? '';
|
||||
const userToAdd = BigInt(tempDataMap.get(userName) ?? '0');
|
||||
const eventIds = utils.messageUrlToIds(eventLink);
|
||||
|
||||
// Verify fields exist
|
||||
|
|
|
@ -10,7 +10,6 @@ import {
|
|||
DiscordEmbedField,
|
||||
Interaction,
|
||||
InteractionResponseTypes,
|
||||
LT, log,
|
||||
MessageComponentTypes,
|
||||
OverwriteTypes,
|
||||
} from '../../deps.ts';
|
||||
|
@ -110,7 +109,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
name: 'Editing/Deleting your event:',
|
||||
value: 'To edit or delete your event, simply click on the ✏️ or 🗑️ buttons respectively.',
|
||||
}];
|
||||
const sendMessagePermSting = '`SEND_MESSAGES`\n`VIEW_CHANNEL`\n`EMBED_LINKS`'
|
||||
const sendMessagePermSting = '`SEND_MESSAGES`\n`VIEW_CHANNEL`\n`EMBED_LINKS`';
|
||||
const permissionFields: Array<DiscordEmbedField> = [
|
||||
{
|
||||
name: `Please make sure ${config.name} has the following permissions for the current channel:`,
|
||||
|
@ -258,7 +257,7 @@ The Discord Slash Command system will ensure you provide all the required detail
|
|||
// Retrofit all old LFG posts that we found
|
||||
oldLfgMsgs.forEach((oldEventId) => {
|
||||
const oldEvent = messages.get(oldEventId);
|
||||
if (oldEvent && oldEvent.embeds[0].fields && oldEvent.embeds[0].footer) {
|
||||
if (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 eventDateTime = new Date(parseInt((oldEvent.embeds[0].fields[LfgEmbedIndexes.StartTime].value.split('tz#')[1] || ' ').slice(0, -1)));
|
||||
if (!isNaN(eventDateTime.getTime())) {
|
||||
|
@ -339,10 +338,12 @@ The Discord Slash Command system will ensure you provide all the required detail
|
|||
} else {
|
||||
// Clean up DB and map
|
||||
lfgChannelSettings.delete(lfgChannelSettingKey);
|
||||
await dbClient.execute('DELETE FROM guild_settings WHERE guildId = ? AND lfgChannelId = ?', [interaction.guildId, interaction.channelId]).catch((e) => utils.commonLoggers.dbError('setup.ts', 'delete guild/lfgChannel', e));
|
||||
await dbClient.execute('DELETE FROM guild_settings WHERE guildId = ? AND lfgChannelId = ?', [interaction.guildId, interaction.channelId]).catch((e) =>
|
||||
utils.commonLoggers.dbError('setup.ts', 'delete guild/lfgChannel', e)
|
||||
);
|
||||
|
||||
if (introMsg) {
|
||||
bot.helpers.deleteMessage(interaction.channelId, introMsg.id, 'embed missing').catch((e) => utils.commonLoggers.messageDeleteError('setup.ts', 'embed missing cleanup', e))
|
||||
bot.helpers.deleteMessage(interaction.channelId, introMsg.id, 'embed missing').catch((e) => utils.commonLoggers.messageDeleteError('setup.ts', 'embed missing cleanup', e));
|
||||
}
|
||||
|
||||
// Could not send initial message
|
||||
|
|
|
@ -128,7 +128,7 @@ export const notifyEventMembers = async (bot: Bot, event: ActiveEvent, secondTry
|
|||
dbClient.execute(queries.updateEventFlags(1, 0), [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@notifySuccess', 'update event in', e));
|
||||
return true;
|
||||
} else {
|
||||
if (!secondTry) loudLogFailure(bot, event, notifyStepName);
|
||||
if (!secondTry) loudLogFailure(bot, event, notifyStepName).catch((e) => utils.commonLoggers.messageSendError('notificationSystem.ts@notify', 'loudLog Failed', e));
|
||||
// Update DB to indicate notifications have not been sent out
|
||||
dbClient.execute(queries.updateEventFlags(-1, 0), [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@notifyFail', 'update event in', e));
|
||||
return false;
|
||||
|
@ -182,7 +182,7 @@ export const lockEvent = async (bot: Bot, event: ActiveEvent, secondTry = false)
|
|||
dbClient.execute(queries.updateEventFlags(1, 1), [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@lockSuccess', 'update event in', e));
|
||||
return true;
|
||||
} else {
|
||||
if (!secondTry) loudLogFailure(bot, event, lockStepName);
|
||||
if (!secondTry) loudLogFailure(bot, event, lockStepName).catch((e) => utils.commonLoggers.messageSendError('notificationSystem.ts@lock', 'loudLog Failed', e));
|
||||
// Update DB to indicate event has not been locked
|
||||
dbClient.execute(queries.updateEventFlags(1, -1), [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@lockFail', 'update event in', e));
|
||||
return false;
|
||||
|
@ -202,7 +202,7 @@ export const deleteEvent = async (bot: Bot, event: ActiveEvent, secondTry = fals
|
|||
dbClient.execute(queries.deleteEvent, [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@deleteSuccess', 'delete event from', e));
|
||||
return true;
|
||||
} else {
|
||||
if (!secondTry) loudLogFailure(bot, event, deleteStepName);
|
||||
if (!secondTry) loudLogFailure(bot, event, deleteStepName).catch((e) => utils.commonLoggers.messageSendError('notificationSystem.ts@delete', 'loudLog Failed', e));
|
||||
// Update DB to indicate delete failed
|
||||
dbClient.execute(queries.updateEventFlags(-1, -1), [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@deleteFail', 'update event in', e));
|
||||
return false;
|
||||
|
@ -232,7 +232,7 @@ export const handleFailures = async (bot: Bot, event: ActiveEvent) => {
|
|||
|
||||
if (!rerunSuccess) {
|
||||
// Failed at completing a step! Event may have been deleted?
|
||||
loudLogFailure(bot, event, stepName, true);
|
||||
loudLogFailure(bot, event, stepName, true).catch((e) => utils.commonLoggers.messageSendError('notificationSystem.ts@rerun', 'loudLog Failed', e));
|
||||
dbClient.execute(queries.deleteEvent, [event.channelId, event.messageId]).catch((e) => utils.commonLoggers.dbError('notificationSystem.ts@handleFailures', 'delete event from', e));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue