Add full event notification

This commit is contained in:
Ean Milligan (Bastion) 2023-04-08 05:09:35 -04:00
parent 9c6f5ef7ec
commit c8befee5f4
2 changed files with 30 additions and 8 deletions

View File

@ -8,7 +8,7 @@ import { joinMemberToEvent } from './utils.ts';
export const customId = 'joinEvent'; export const customId = 'joinEvent';
export const execute = async (bot: Bot, interaction: Interaction) => { export 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.guildId && interaction.message && interaction.message.embeds[0]) {
// 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) =>
utils.commonLoggers.dbError('joinEvent.ts', 'call sproc INC_CNT on', e) utils.commonLoggers.dbError('joinEvent.ts', 'call sproc INC_CNT on', e)
@ -18,7 +18,7 @@ export const execute = async (bot: Bot, interaction: Interaction) => {
joinMemberToEvent(bot, interaction, interaction.message.embeds[0], interaction.message.id, interaction.channelId, { joinMemberToEvent(bot, interaction, interaction.message.embeds[0], interaction.message.id, interaction.channelId, {
id: interaction.member.id, id: interaction.member.id,
name: interaction.member.user.username, name: interaction.member.user.username,
}); }, interaction.guildId);
} else { } else {
somethingWentWrong(bot, interaction, 'noDataFromJoinEventButton'); somethingWentWrong(bot, interaction, 'noDataFromJoinEventButton');
} }

View File

@ -64,6 +64,10 @@ const noEdit = async (bot: Bot, interaction: Interaction) =>
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));
// Get Guild Name
const getGuildName = async (bot: Bot, guildId: bigint): Promise<string> =>
(await bot.helpers.getGuild(guildId).catch((e: Error) => utils.commonLoggers.messageGetError('utils.ts', 'get guild', e)) || { name: 'failed to get guild name' }).name;
// Remove member from the event // Remove member from the event
export const removeMemberFromEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, userId: bigint, evtGuildId: bigint) => { export const removeMemberFromEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, userId: bigint, evtGuildId: bigint) => {
if (evtMessageEmbed.fields) { if (evtMessageEmbed.fields) {
@ -90,16 +94,15 @@ export const removeMemberFromEvent = async (bot: Bot, interaction: Interaction,
messageId: evtMessageId, messageId: evtMessageId,
}; };
const guildDetails = await bot.helpers.getGuild(evtGuildId).catch((e: Error) => utils.commonLoggers.messageGetError('utils.ts', 'get guild', e));
// Notify member of promotion // Notify member of promotion
await sendDirectMessage(bot, memberToPromote.id, { await sendDirectMessage(bot, memberToPromote.id, {
embeds: [{ embeds: [{
color: successColor, color: successColor,
title: 'Good news, you\'ve been promoted!', title: 'Good news, you\'ve been promoted!',
description: `A member left [the full event](${utils.idsToMessageUrl(urlIds)}) in ${ description: `A member left [the full event](${utils.idsToMessageUrl(urlIds)}) in \`${await getGuildName(
guildDetails?.name || '`failed to get guild name`' bot,
} you tried to join, leaving space for me to promote you from the alternate list to the joined list.\n\nPlease verify the event details below. If you are no longer available for this event, please click on the '${leaveEventBtnStr}' button below`, evtGuildId,
)}\` you tried to join, leaving space for me to promote you from the alternate list to the joined list.\n\nPlease verify the event details below. If you are no longer available for this event, please click on the '${leaveEventBtnStr}' button below`,
fields: [ fields: [
evtMessageEmbed.fields[LfgEmbedIndexes.Activity], evtMessageEmbed.fields[LfgEmbedIndexes.Activity],
evtMessageEmbed.fields[LfgEmbedIndexes.StartTime], evtMessageEmbed.fields[LfgEmbedIndexes.StartTime],
@ -160,7 +163,7 @@ export const alternateMemberToEvent = async (bot: Bot, interaction: Interaction,
}; };
// Join member to the event // Join member to the event
export const joinMemberToEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, member: LFGMember) => { export const joinMemberToEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, member: LFGMember, evtGuildId: bigint) => {
if (evtMessageEmbed.fields) { if (evtMessageEmbed.fields) {
// Get current member list and count // Get current member list and count
const [oldMemberCount, maxMemberCount] = getEventMemberCount(evtMessageEmbed.fields[LfgEmbedIndexes.JoinedMembers].name); const [oldMemberCount, maxMemberCount] = getEventMemberCount(evtMessageEmbed.fields[LfgEmbedIndexes.JoinedMembers].name);
@ -181,6 +184,25 @@ export const joinMemberToEvent = async (bot: Bot, interaction: Interaction, evtM
// Update the event // Update the event
await editEvent(bot, interaction, evtMessageEmbed, evtMessageId, evtChannelId, memberList, maxMemberCount, alternateList); await editEvent(bot, interaction, evtMessageEmbed, evtMessageId, evtChannelId, memberList, maxMemberCount, alternateList);
// Check if we need to notify the owner that their event has filled
if (memberList.length === maxMemberCount) {
const urlIds: UrlIds = {
guildId: evtGuildId,
channelId: evtChannelId,
messageId: evtMessageId,
};
const guildName = await getGuildName(bot, evtGuildId);
// Notify member of promotion
await sendDirectMessage(bot, BigInt(evtMessageEmbed.footer?.iconUrl?.split('#')[1] || '0'), {
embeds: [{
color: successColor,
title: `Good news, your event in ${guildName} has filled!`,
description: `[Click here to view the event in ${guildName}.](${utils.idsToMessageUrl(urlIds)})`,
fields: evtMessageEmbed.fields,
}],
}).catch((e: Error) => utils.commonLoggers.messageSendError('utils.ts', 'event filled', e));
}
} }
} else { } else {
// No fields, can't join // No fields, can't join