Add DM notification system to delete and edit when a Group Up Manager edits/deletes on behalf of the owner
This commit is contained in:
parent
e1b8ac48da
commit
ed827a42fd
|
@ -1,9 +1,10 @@
|
||||||
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
|
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
|
||||||
import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../../db.ts';
|
import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../../db.ts';
|
||||||
import { failColor, infoColor1, infoColor2, safelyDismissMsg, somethingWentWrong, successColor } from '../../commandUtils.ts';
|
import { failColor, infoColor1, infoColor2, safelyDismissMsg, somethingWentWrong, successColor, sendDirectMessage } from '../../commandUtils.ts';
|
||||||
import { idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
|
import { generateMemberList, idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
import config from '../../../config.ts';
|
import config from '../../../config.ts';
|
||||||
|
import { getGuildName } from './utils.ts';
|
||||||
|
|
||||||
export const customId = 'deleteConfirmed';
|
export const customId = 'deleteConfirmed';
|
||||||
export const confirmedCustomId = 'confirmedCustomId';
|
export const confirmedCustomId = 'confirmedCustomId';
|
||||||
|
@ -31,6 +32,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tempDataMap.get(confirmedCustomId)?.toLowerCase() === confirmStr) {
|
if (tempDataMap.get(confirmedCustomId)?.toLowerCase() === confirmStr) {
|
||||||
|
const guildName = await getGuildName(bot, interaction.guildId);
|
||||||
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('deleteConfirmed.ts', 'get eventMessage', e));
|
const eventMessage = await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('deleteConfirmed.ts', 'get eventMessage', e));
|
||||||
const userId = interaction.member.id;
|
const userId = interaction.member.id;
|
||||||
const userName = interaction.member.user.username;
|
const userName = interaction.member.user.username;
|
||||||
|
@ -52,6 +54,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
||||||
|
|
||||||
if (actionByManager) {
|
if (actionByManager) {
|
||||||
|
const ownerId = BigInt(eventMessage?.embeds[0].footer?.iconUrl?.split('#')[1] || '0');
|
||||||
const eventEmbed = eventMessage?.embeds[0] || { title: 'Event not found', color: failColor };
|
const eventEmbed = eventMessage?.embeds[0] || { title: 'Event not found', color: failColor };
|
||||||
bot.helpers.sendMessage(lfgChannelSetting.logChannelId, {
|
bot.helpers.sendMessage(lfgChannelSetting.logChannelId, {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
|
@ -61,6 +64,27 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
timestamp: new Date().getTime(),
|
timestamp: new Date().getTime(),
|
||||||
}, eventEmbed],
|
}, eventEmbed],
|
||||||
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send log message', e));
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send log message', e));
|
||||||
|
|
||||||
|
sendDirectMessage(bot, ownerId, {
|
||||||
|
embeds: [{
|
||||||
|
color: infoColor2,
|
||||||
|
title: `Notice: A ${config.name} Manager has deleted one of your events in ${guildName}`,
|
||||||
|
description: 'The deleted event is listed below.',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: `${config.name} Manager:`,
|
||||||
|
value: generateMemberList([{
|
||||||
|
id: userId,
|
||||||
|
name: userName,
|
||||||
|
}]),
|
||||||
|
inline: true,
|
||||||
|
}, {
|
||||||
|
name: 'Are you unhappy with this action?',
|
||||||
|
value: `Please reach out to the ${config.name} Manager that performed this action, or the moderators/administrators of ${guildName}.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}, eventEmbed],
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send DM fail', e));
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
utils.commonLoggers.messageDeleteError('deleteConfirmed.ts', 'deleteEventFailedDB', e);
|
utils.commonLoggers.messageDeleteError('deleteConfirmed.ts', 'deleteEventFailedDB', e);
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
|
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts';
|
||||||
import { failColor, infoColor1, infoColor2, safelyDismissMsg, somethingWentWrong, successColor } from '../../commandUtils.ts';
|
import { failColor, infoColor1, infoColor2, safelyDismissMsg, somethingWentWrong, successColor, sendDirectMessage } from '../../commandUtils.ts';
|
||||||
import { idSeparator, LfgEmbedIndexes, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
|
import { generateMemberList, idSeparator, LfgEmbedIndexes, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
|
||||||
import { deleteTokenEarly } from '../tokenCleanup.ts';
|
import { deleteTokenEarly } from '../tokenCleanup.ts';
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
import config from '../../../config.ts';
|
import config from '../../../config.ts';
|
||||||
import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../../db.ts';
|
import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../../db.ts';
|
||||||
|
import { getGuildName } from './utils.ts';
|
||||||
|
|
||||||
export const customId = 'updateEvent';
|
export const customId = 'updateEvent';
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
const actionByManager = interaction.data.customId.endsWith(pathIdxEnder);
|
const actionByManager = interaction.data.customId.endsWith(pathIdxEnder);
|
||||||
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
|
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
|
||||||
const eventTime: Date = new Date(parseInt(interaction.message.embeds[0].fields[LfgEmbedIndexes.ICSLink].value.split('?t=')[1].split('&n=')[0] || '0'));
|
const eventTime: Date = new Date(parseInt(interaction.message.embeds[0].fields[LfgEmbedIndexes.ICSLink].value.split('?t=')[1].split('&n=')[0] || '0'));
|
||||||
|
const guildName = await getGuildName(bot, interaction.guildId);
|
||||||
const oldEventEmbed = (await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('updateEvent.ts', 'get eventMessage', e)))?.embeds[0];
|
const oldEventEmbed = (await bot.helpers.getMessage(evtChannelId, evtMessageId).catch((e: Error) => utils.commonLoggers.messageGetError('updateEvent.ts', 'get eventMessage', e)))?.embeds[0];
|
||||||
const newEventEmbed = interaction.message.embeds[0];
|
const newEventEmbed = interaction.message.embeds[0];
|
||||||
const userId = interaction.member.id;
|
const userId = interaction.member.id;
|
||||||
|
@ -41,6 +43,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('updateEvent.ts', interaction, e));
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('updateEvent.ts', interaction, e));
|
||||||
|
|
||||||
if (actionByManager) {
|
if (actionByManager) {
|
||||||
|
const ownerId = BigInt(oldEventEmbed?.footer?.iconUrl?.split('#')[1] || '0');
|
||||||
const missingOldEmbed = { title: 'Failed to get old event', color: failColor };
|
const missingOldEmbed = { title: 'Failed to get old event', color: failColor };
|
||||||
if (oldEventEmbed) {
|
if (oldEventEmbed) {
|
||||||
oldEventEmbed.color = infoColor1;
|
oldEventEmbed.color = infoColor1;
|
||||||
|
@ -57,6 +60,29 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
newEventEmbed,
|
newEventEmbed,
|
||||||
],
|
],
|
||||||
}).catch((e: Error) => utils.commonLoggers.messageSendError('updateEvent.ts', 'send log message', e));
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('updateEvent.ts', 'send log message', e));
|
||||||
|
|
||||||
|
sendDirectMessage(bot, ownerId, {
|
||||||
|
embeds: [{
|
||||||
|
color: infoColor2,
|
||||||
|
title: `Notice: A ${config.name} Manager has edited one of your events in ${guildName}`,
|
||||||
|
description: 'The edited event is listed below. The old event is listed first and marked with a blue bar.',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: `${config.name} Manager:`,
|
||||||
|
value: generateMemberList([{
|
||||||
|
id: userId,
|
||||||
|
name: userName,
|
||||||
|
}]),
|
||||||
|
inline: true,
|
||||||
|
}, {
|
||||||
|
name: 'Are you unhappy with this action?',
|
||||||
|
value: `Please reach out to the ${config.name} Manager that performed this action, or the moderators/administrators of ${guildName}.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
oldEventEmbed || missingOldEmbed,
|
||||||
|
newEventEmbed,],
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.messageSendError('managerJLA.ts', 'send DM fail', e));
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
utils.commonLoggers.dbError('updateEvent.ts', 'update event in', e);
|
utils.commonLoggers.dbError('updateEvent.ts', 'update event in', e);
|
||||||
|
|
Loading…
Reference in New Issue