Add option to alternate to denied join request

Additionally:
Added light telemetry to joinRequest buttons
Added loudAcknowledge to editEvent so that the alternate event in DM has a proper response
Stopped exporting the execute functions from all live-event buttons, I have no clue why I did that in the first place
This commit is contained in:
Ean Milligan (Bastion) 2023-04-14 17:20:57 -04:00
parent 126689171d
commit e52e384fb9
9 changed files with 106 additions and 17 deletions

View File

@ -13,6 +13,7 @@
"https://deno.land": true
},
"cSpell.words": [
"sproc",
"USTZ"
]
}

View File

@ -16,6 +16,9 @@ const actions = [
'btn-joinWLEvent',
'btn-leaveEvent',
'btn-altEvent',
'btn-joinReqApprove',
'btn-joinReqDeny',
'btn-joinReqAlt',
];
for (const action of actions) {
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => {

View File

@ -8,6 +8,7 @@ import { joinEventButton } from './live-event/joinEvent.ts';
import { leaveEventButton } from './live-event/leaveEvent.ts';
import { alternateEventButton } from './live-event/alternateEvent.ts';
import { joinRequestButton } from './live-event/joinRequest.ts';
import { alternateRequestButton } from './live-event/alternateRequest.ts';
export const buttons: Array<Button> = [
gameSelectionButton,
@ -19,4 +20,5 @@ export const buttons: Array<Button> = [
leaveEventButton,
alternateEventButton,
joinRequestButton,
alternateRequestButton,
];

View File

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

View File

@ -0,0 +1,44 @@
import { Bot, Interaction } from '../../../deps.ts';
import { dbClient, queries } from '../../db.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import utils from '../../utils.ts';
import { alternateMemberToEvent } from './utils.ts';
export const customId = 'alternateRequest';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.user && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].description) {
// Light Telemetry
dbClient.execute(queries.callIncCnt('btn-joinReqAlt')).catch((e) => utils.commonLoggers.dbError('alternateRequest.ts', 'call sproc INC_CNT on', e));
// Get details from message
const eventIds = utils.messageUrlToIds(interaction.message.embeds[0].description.split(')')[0] || '');
const eventMessage = await bot.helpers.getMessage(eventIds.channelId, eventIds.messageId).catch((e: Error) => utils.commonLoggers.messageGetError('alternateRequest.ts', 'get eventMessage', e));
// Try to alternate the member to the event
if (eventMessage) {
alternateMemberToEvent(
bot,
interaction,
eventMessage.embeds[0],
eventIds.messageId,
eventIds.channelId,
{
id: interaction.user.id,
name: interaction.user.username,
},
false,
true,
);
} else {
somethingWentWrong(bot, interaction, 'eventMissingFromAlternateRequestButton');
}
} else {
somethingWentWrong(bot, interaction, 'noDataFromAlternateRequestButton');
}
};
export const alternateRequestButton = {
customId,
execute,
};

View File

@ -8,7 +8,7 @@ import { generateMapId, getGuildName, getLfgMembers, joinMemberToEvent, joinRequ
export const customId = 'joinEvent';
export const execute = async (bot: Bot, interaction: Interaction) => {
const execute = async (bot: Bot, interaction: Interaction) => {
if (
interaction.data?.customId && interaction.member && interaction.member.user && interaction.channelId && interaction.guildId && interaction.message && interaction.message.embeds[0] &&
interaction.message.embeds[0].fields

View File

@ -2,13 +2,15 @@ import { Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageCompon
import { sendDirectMessage, somethingWentWrong, successColor, warnColor } from '../../commandUtils.ts';
import { generateMapId, getLfgMembers, joinMemberToEvent, joinRequestMap, joinRequestResponseButtons, JoinRequestStatus } from './utils.ts';
import { alternateEventBtnStr, idSeparator } from '../eventUtils.ts';
import { dbClient, queries } from '../../db.ts';
import { customId as alternateRequestCustomId } from './alternateRequest.ts';
import utils from '../../utils.ts';
export const customId = 'joinRequest';
export const approveStr = 'approved';
export const denyStr = 'denied';
export const execute = async (bot: Bot, interaction: Interaction) => {
const execute = async (bot: Bot, interaction: Interaction) => {
if (
interaction.data?.customId && interaction.user && interaction.channelId && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields &&
interaction.message.embeds[0].description
@ -21,6 +23,9 @@ export const execute = async (bot: Bot, interaction: Interaction) => {
const eventUrl = utils.idsToMessageUrl(eventIds);
const joinRequestMapId = generateMapId(eventIds.messageId, eventIds.channelId, memberRequesting.id);
// Light Telemetry
dbClient.execute(queries.callIncCnt(approved ? 'btn-joinReqApprove' : 'btn-joinReqDeny')).catch((e) => utils.commonLoggers.dbError('joinRequest.ts', 'call sproc INC_CNT on', e));
if (approved) {
// If member was approved, get the event and add them to it
const eventMessage = await bot.helpers.getMessage(eventIds.channelId, eventIds.messageId).catch((e: Error) => utils.commonLoggers.messageGetError('joinRequest.ts', 'get eventMessage', e));
@ -58,7 +63,7 @@ export const execute = async (bot: Bot, interaction: Interaction) => {
type: MessageComponentTypes.Button,
label: alternateEventBtnStr,
style: ButtonStyles.Primary,
customId: `tempId`, // TODO: fix
customId: alternateRequestCustomId,
}],
}],
}).catch((e: Error) => utils.commonLoggers.messageSendError('joinRequest.ts', 'send DM fail', e));

View File

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

View File

@ -1,6 +1,6 @@
import { ActionRow, Bot, ButtonStyles, Embed, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { ActionRow, ApplicationCommandFlags, Bot, ButtonStyles, Embed, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { LFGMember, UrlIds } from '../../types/commandTypes.ts';
import { sendDirectMessage, somethingWentWrong, successColor } from '../../commandUtils.ts';
import { infoColor1, safelyDismissMsg, sendDirectMessage, somethingWentWrong, successColor } from '../../commandUtils.ts';
import { generateAlternateList, generateMemberList, generateMemberTitle, idSeparator, leaveEventBtnStr, LfgEmbedIndexes, noMembersStr } from '../eventUtils.ts';
import { approveStr, customId as joinRequestCustomId, denyStr } from './joinRequest.ts';
import utils from '../../utils.ts';
@ -81,6 +81,7 @@ const editEvent = async (
memberList: Array<LFGMember>,
maxMemberCount: number,
alternateList: Array<LFGMember>,
loudAcknowledge = false,
) => {
if (evtMessageEmbed.fields) {
// Update the fields
@ -93,9 +94,25 @@ const editEvent = async (
embeds: [evtMessageEmbed],
}).then(() => {
// Let discord know we didn't ignore the user
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.DeferredUpdateMessage,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
if (loudAcknowledge) {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource,
data: {
flags: ApplicationCommandFlags.Ephemeral,
embeds: [{
color: successColor,
title: 'Event Updated',
description: `The action requested was completed successfully.
${safelyDismissMsg}`
}],
},
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
} else {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.DeferredUpdateMessage,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
}
}).catch((e: Error) => {
// Edit failed, try to notify user
utils.commonLoggers.messageEditError('utils.ts', 'event edit fail', e);
@ -105,10 +122,27 @@ const editEvent = async (
};
// Generic no response response
const noEdit = async (bot: Bot, interaction: Interaction) =>
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.DeferredUpdateMessage,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
const noEdit = async (bot: Bot, interaction: Interaction, loudAcknowledge = false) => {
if (loudAcknowledge) {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource,
data: {
flags: ApplicationCommandFlags.Ephemeral,
embeds: [{
color: infoColor1,
title: 'No Changes Made',
description: `The action requested was not performed as it was not necessary.
${safelyDismissMsg}`
}],
},
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
} else {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.DeferredUpdateMessage,
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
}
};
// Get Guild Name
export const getGuildName = async (bot: Bot, guildId: bigint): Promise<string> =>
@ -179,7 +213,7 @@ export const removeMemberFromEvent = async (bot: Bot, interaction: Interaction,
};
// Alternate member to the event
export const alternateMemberToEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, member: LFGMember, userJoinOnFull = false) => {
export const alternateMemberToEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, member: LFGMember, userJoinOnFull = false, loudAcknowledge = false) => {
if (evtMessageEmbed.fields) {
member.joined = userJoinOnFull;
// Get current alternates
@ -197,10 +231,10 @@ export const alternateMemberToEvent = async (bot: Bot, interaction: Interaction,
// Update the event
evtMessageEmbed.fields[LfgEmbedIndexes.AlternateMembers].value = generateAlternateList(alternateList);
await editEvent(bot, interaction, evtMessageEmbed, evtMessageId, evtChannelId, memberList, maxMemberCount, alternateList);
await editEvent(bot, interaction, evtMessageEmbed, evtMessageId, evtChannelId, memberList, maxMemberCount, alternateList, loudAcknowledge);
} else {
// Send noEdit response because user was already an alternate and joined status did not change
await noEdit(bot, interaction);
await noEdit(bot, interaction, loudAcknowledge);
}
} else {
// No fields, can't alternate