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:
parent
126689171d
commit
e52e384fb9
|
@ -13,6 +13,7 @@
|
||||||
"https://deno.land": true
|
"https://deno.land": true
|
||||||
},
|
},
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"sproc",
|
||||||
"USTZ"
|
"USTZ"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -16,6 +16,9 @@ const actions = [
|
||||||
'btn-joinWLEvent',
|
'btn-joinWLEvent',
|
||||||
'btn-leaveEvent',
|
'btn-leaveEvent',
|
||||||
'btn-altEvent',
|
'btn-altEvent',
|
||||||
|
'btn-joinReqApprove',
|
||||||
|
'btn-joinReqDeny',
|
||||||
|
'btn-joinReqAlt',
|
||||||
];
|
];
|
||||||
for (const action of actions) {
|
for (const action of actions) {
|
||||||
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => {
|
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { joinEventButton } from './live-event/joinEvent.ts';
|
||||||
import { leaveEventButton } from './live-event/leaveEvent.ts';
|
import { leaveEventButton } from './live-event/leaveEvent.ts';
|
||||||
import { alternateEventButton } from './live-event/alternateEvent.ts';
|
import { alternateEventButton } from './live-event/alternateEvent.ts';
|
||||||
import { joinRequestButton } from './live-event/joinRequest.ts';
|
import { joinRequestButton } from './live-event/joinRequest.ts';
|
||||||
|
import { alternateRequestButton } from './live-event/alternateRequest.ts';
|
||||||
|
|
||||||
export const buttons: Array<Button> = [
|
export const buttons: Array<Button> = [
|
||||||
gameSelectionButton,
|
gameSelectionButton,
|
||||||
|
@ -19,4 +20,5 @@ export const buttons: Array<Button> = [
|
||||||
leaveEventButton,
|
leaveEventButton,
|
||||||
alternateEventButton,
|
alternateEventButton,
|
||||||
joinRequestButton,
|
joinRequestButton,
|
||||||
|
alternateRequestButton,
|
||||||
];
|
];
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { alternateMemberToEvent } from './utils.ts';
|
||||||
|
|
||||||
export const customId = 'alternateEvent';
|
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]) {
|
if (interaction.data?.customId && interaction.member && interaction.member.user && interaction.channelId && interaction.message && 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));
|
||||||
|
|
|
@ -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,
|
||||||
|
};
|
|
@ -8,7 +8,7 @@ import { generateMapId, getGuildName, getLfgMembers, joinMemberToEvent, joinRequ
|
||||||
|
|
||||||
export const customId = 'joinEvent';
|
export const customId = 'joinEvent';
|
||||||
|
|
||||||
export 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 && interaction.member.user && interaction.channelId && interaction.guildId && interaction.message && interaction.message.embeds[0] &&
|
||||||
interaction.message.embeds[0].fields
|
interaction.message.embeds[0].fields
|
||||||
|
|
|
@ -2,13 +2,15 @@ import { Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageCompon
|
||||||
import { sendDirectMessage, somethingWentWrong, successColor, warnColor } from '../../commandUtils.ts';
|
import { sendDirectMessage, somethingWentWrong, successColor, warnColor } from '../../commandUtils.ts';
|
||||||
import { generateMapId, getLfgMembers, joinMemberToEvent, joinRequestMap, joinRequestResponseButtons, JoinRequestStatus } from './utils.ts';
|
import { generateMapId, getLfgMembers, joinMemberToEvent, joinRequestMap, joinRequestResponseButtons, JoinRequestStatus } from './utils.ts';
|
||||||
import { alternateEventBtnStr, idSeparator } from '../eventUtils.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';
|
import utils from '../../utils.ts';
|
||||||
|
|
||||||
export const customId = 'joinRequest';
|
export const customId = 'joinRequest';
|
||||||
export const approveStr = 'approved';
|
export const approveStr = 'approved';
|
||||||
export const denyStr = 'denied';
|
export const denyStr = 'denied';
|
||||||
|
|
||||||
export 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 && interaction.message.embeds[0] && interaction.message.embeds[0].fields &&
|
||||||
interaction.message.embeds[0].description
|
interaction.message.embeds[0].description
|
||||||
|
@ -21,6 +23,9 @@ export const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
const eventUrl = utils.idsToMessageUrl(eventIds);
|
const eventUrl = utils.idsToMessageUrl(eventIds);
|
||||||
const joinRequestMapId = generateMapId(eventIds.messageId, eventIds.channelId, memberRequesting.id);
|
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 (approved) {
|
||||||
// If member was approved, get the event and add them to it
|
// 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));
|
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,
|
type: MessageComponentTypes.Button,
|
||||||
label: alternateEventBtnStr,
|
label: alternateEventBtnStr,
|
||||||
style: ButtonStyles.Primary,
|
style: ButtonStyles.Primary,
|
||||||
customId: `tempId`, // TODO: fix
|
customId: alternateRequestCustomId,
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
}).catch((e: Error) => utils.commonLoggers.messageSendError('joinRequest.ts', 'send DM fail', e));
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('joinRequest.ts', 'send DM fail', e));
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { removeMemberFromEvent } from './utils.ts';
|
||||||
|
|
||||||
export const customId = 'leaveEvent';
|
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]) {
|
if (interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId && interaction.message && 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));
|
||||||
|
|
|
@ -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 { 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 { generateAlternateList, generateMemberList, generateMemberTitle, idSeparator, leaveEventBtnStr, LfgEmbedIndexes, noMembersStr } from '../eventUtils.ts';
|
||||||
import { approveStr, customId as joinRequestCustomId, denyStr } from './joinRequest.ts';
|
import { approveStr, customId as joinRequestCustomId, denyStr } from './joinRequest.ts';
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
|
@ -81,6 +81,7 @@ const editEvent = async (
|
||||||
memberList: Array<LFGMember>,
|
memberList: Array<LFGMember>,
|
||||||
maxMemberCount: number,
|
maxMemberCount: number,
|
||||||
alternateList: Array<LFGMember>,
|
alternateList: Array<LFGMember>,
|
||||||
|
loudAcknowledge = false,
|
||||||
) => {
|
) => {
|
||||||
if (evtMessageEmbed.fields) {
|
if (evtMessageEmbed.fields) {
|
||||||
// Update the fields
|
// Update the fields
|
||||||
|
@ -93,9 +94,25 @@ const editEvent = async (
|
||||||
embeds: [evtMessageEmbed],
|
embeds: [evtMessageEmbed],
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// Let discord know we didn't ignore the user
|
// Let discord know we didn't ignore the user
|
||||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
if (loudAcknowledge) {
|
||||||
type: InteractionResponseTypes.DeferredUpdateMessage,
|
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
|
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) => {
|
}).catch((e: Error) => {
|
||||||
// Edit failed, try to notify user
|
// Edit failed, try to notify user
|
||||||
utils.commonLoggers.messageEditError('utils.ts', 'event edit fail', e);
|
utils.commonLoggers.messageEditError('utils.ts', 'event edit fail', e);
|
||||||
|
@ -105,10 +122,27 @@ const editEvent = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generic no response response
|
// Generic no response response
|
||||||
const noEdit = async (bot: Bot, interaction: Interaction) =>
|
const noEdit = async (bot: Bot, interaction: Interaction, loudAcknowledge = false) => {
|
||||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
if (loudAcknowledge) {
|
||||||
type: InteractionResponseTypes.DeferredUpdateMessage,
|
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
|
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
|
// Get Guild Name
|
||||||
export const getGuildName = async (bot: Bot, guildId: bigint): Promise<string> =>
|
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
|
// 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) {
|
if (evtMessageEmbed.fields) {
|
||||||
member.joined = userJoinOnFull;
|
member.joined = userJoinOnFull;
|
||||||
// Get current alternates
|
// Get current alternates
|
||||||
|
@ -197,10 +231,10 @@ export const alternateMemberToEvent = async (bot: Bot, interaction: Interaction,
|
||||||
|
|
||||||
// Update the event
|
// Update the event
|
||||||
evtMessageEmbed.fields[LfgEmbedIndexes.AlternateMembers].value = generateAlternateList(alternateList);
|
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 {
|
} else {
|
||||||
// Send noEdit response because user was already an alternate and joined status did not change
|
// 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 {
|
} else {
|
||||||
// No fields, can't alternate
|
// No fields, can't alternate
|
||||||
|
|
Loading…
Reference in New Issue