Add notification of promotion when user leaves full event
This commit is contained in:
parent
bfcb993b03
commit
c00e8e7c83
|
@ -7,12 +7,12 @@ import { removeMemberFromEvent } from './utils.ts';
|
||||||
export const customId = 'leaveEvent';
|
export const customId = 'leaveEvent';
|
||||||
|
|
||||||
export const execute = async (bot: Bot, interaction: Interaction) => {
|
export const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
if (interaction.data?.customId && interaction.member && interaction.channelId && 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));
|
||||||
|
|
||||||
// Remove user from event
|
// Remove user from event
|
||||||
removeMemberFromEvent(bot, interaction, interaction.message.embeds[0], interaction.message.id, interaction.channelId, interaction.member.id);
|
removeMemberFromEvent(bot, interaction, interaction.message.embeds[0], interaction.message.id, interaction.channelId, interaction.member.id, interaction.guildId);
|
||||||
} else {
|
} else {
|
||||||
somethingWentWrong(bot, interaction, 'noDataFromLeaveEventButton');
|
somethingWentWrong(bot, interaction, 'noDataFromLeaveEventButton');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Bot, Embed, Interaction, InteractionResponseTypes } from '../../../deps.ts';
|
import { Bot, ButtonStyles, Embed, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
|
||||||
import { LFGMember } from '../../types/commandTypes.ts';
|
import { LFGMember, UrlIds } from '../../types/commandTypes.ts';
|
||||||
import { somethingWentWrong } from '../../commandUtils.ts';
|
import { sendDirectMessage, somethingWentWrong } from '../../commandUtils.ts';
|
||||||
import { generateAlternateList, generateMemberList, generateMemberTitle, LfgEmbedIndexes, noMembersStr } from '../eventUtils.ts';
|
import { generateAlternateList, generateMemberList, generateMemberTitle, leaveEventBtnStr, LfgEmbedIndexes, noMembersStr } from '../eventUtils.ts';
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
|
|
||||||
// Get Member Counts from the title
|
// Get Member Counts from the title
|
||||||
|
@ -65,7 +65,7 @@ const noEdit = async (bot: Bot, interaction: Interaction) =>
|
||||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('utils.ts', interaction, e));
|
||||||
|
|
||||||
// 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) => {
|
export const removeMemberFromEvent = async (bot: Bot, interaction: Interaction, evtMessageEmbed: Embed, evtMessageId: bigint, evtChannelId: bigint, userId: bigint, evtGuildId: bigint) => {
|
||||||
if (evtMessageEmbed.fields) {
|
if (evtMessageEmbed.fields) {
|
||||||
// Get old counts
|
// Get old counts
|
||||||
const [oldMemberCount, maxMemberCount] = getEventMemberCount(evtMessageEmbed.fields[LfgEmbedIndexes.JoinedMembers].name);
|
const [oldMemberCount, maxMemberCount] = getEventMemberCount(evtMessageEmbed.fields[LfgEmbedIndexes.JoinedMembers].name);
|
||||||
|
@ -84,8 +84,37 @@ export const removeMemberFromEvent = async (bot: Bot, interaction: Interaction,
|
||||||
alternateList = removeLfgMember(alternateList, memberToPromote.id);
|
alternateList = removeLfgMember(alternateList, memberToPromote.id);
|
||||||
memberList.push(memberToPromote);
|
memberList.push(memberToPromote);
|
||||||
|
|
||||||
|
const urlIds: UrlIds = {
|
||||||
|
guildId: evtGuildId,
|
||||||
|
channelId: evtChannelId,
|
||||||
|
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
|
||||||
// TODO: send notification
|
await sendDirectMessage(bot, memberToPromote.id, {
|
||||||
|
embeds: [{
|
||||||
|
title: 'Good news, you\'ve been promoted!',
|
||||||
|
description: `A member left [the full event](${utils.idsToMessageUrl(urlIds)}) in ${
|
||||||
|
guildDetails?.name || '`failed to get guild name`'
|
||||||
|
} 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: [
|
||||||
|
evtMessageEmbed.fields[LfgEmbedIndexes.Activity],
|
||||||
|
evtMessageEmbed.fields[LfgEmbedIndexes.StartTime],
|
||||||
|
evtMessageEmbed.fields[LfgEmbedIndexes.ICSLink],
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
components: [{
|
||||||
|
type: MessageComponentTypes.ActionRow,
|
||||||
|
components: [{
|
||||||
|
type: MessageComponentTypes.Button,
|
||||||
|
label: leaveEventBtnStr,
|
||||||
|
style: ButtonStyles.Danger,
|
||||||
|
customId: 'leaveEventCustomId', // TODO: fix
|
||||||
|
}],
|
||||||
|
}],
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('utils.ts', 'user promotion', e));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the event
|
// Update the event
|
||||||
|
|
|
@ -46,7 +46,4 @@ export const sendDirectMessage = async (bot: Bot, userId: bigint, message: Creat
|
||||||
bot.helpers.getDmChannel(userId).then((userDmChannel) => {
|
bot.helpers.getDmChannel(userId).then((userDmChannel) => {
|
||||||
// Actually send the DM
|
// Actually send the DM
|
||||||
bot.helpers.sendMessage(userDmChannel.id, message).catch((e: Error) => utils.commonLoggers.messageSendError('commandUtils.ts', message, e));
|
bot.helpers.sendMessage(userDmChannel.id, message).catch((e: Error) => utils.commonLoggers.messageSendError('commandUtils.ts', message, e));
|
||||||
}).catch((e: Error) => {
|
}).catch((e: Error) => utils.commonLoggers.messageGetError('commandUtils.ts', 'get userDmChannel', e));
|
||||||
// Edit failed, try to notify user
|
|
||||||
utils.commonLoggers.messageGetError('commandUtils.ts', 'get userDmChannel', e);
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue