Verify bot can dm users when they try to whitelist an event + deno fmt
This commit is contained in:
parent
ed18f556b1
commit
afeb6beda0
|
@ -47,7 +47,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
|
||||
// Log custom event to see if we should add it as a preset
|
||||
if (customAct) {
|
||||
dbClient.execute(queries.insertCustomActivity, [category, activity.name, activity.maxMembers]).catch((e) => utils.commonLoggers.dbError('step2-finalize.ts@custom', 'insert into', e))
|
||||
dbClient.execute(queries.insertCustomActivity, [category, activity.name, activity.maxMembers]).catch((e) => utils.commonLoggers.dbError('step2-finalize.ts@custom', 'insert into', e));
|
||||
}
|
||||
|
||||
const rawEventTime = tempDataMap.get(eventTimeId) || '';
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
|
||||
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
|
||||
import { generateLFGButtons } from './utils.ts';
|
||||
import { idSeparator, LfgEmbedIndexes } from '../eventUtils.ts';
|
||||
import { deleteTokenEarly } from '../tokenCleanup.ts';
|
||||
import { somethingWentWrong } from '../../commandUtils.ts';
|
||||
import { dmTestMessage, safelyDismissMsg, sendDirectMessage, somethingWentWrong, warnColor } from '../../commandUtils.ts';
|
||||
import { dbClient, queries } from '../../db.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
||||
|
@ -23,6 +23,25 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
const ownerId: bigint = BigInt(interaction.message.embeds[0].footer?.iconUrl?.split('#')[1] || '0');
|
||||
const eventTime: Date = new Date(parseInt(interaction.message.embeds[0].fields[LfgEmbedIndexes.ICSLink].value.split('?t=')[1].split('&n=')[0] || '0'));
|
||||
|
||||
// Check if we need to ensure DMs are open
|
||||
if (interaction.data.customId.includes(idSeparator)) {
|
||||
const dmSuccess = Boolean(await sendDirectMessage(bot, interaction.member.id, dmTestMessage).catch((e: Error) => utils.commonLoggers.messageSendError('toggleWLStatus.ts', 'send DM fail', e)));
|
||||
if (!dmSuccess) {
|
||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: ApplicationCommandFlags.Ephemeral,
|
||||
embeds: [{
|
||||
color: warnColor,
|
||||
title: 'Event not created.',
|
||||
description: `In order to create a whitelisted event, your DMs must be open to receive Join Requests. Please open your DMs and try again.\n\n${safelyDismissMsg}`,
|
||||
}],
|
||||
},
|
||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('toggleWLStatus.ts@dmFail', interaction, e));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Send Event Message
|
||||
const eventMessage = await bot.helpers.sendMessage(interaction.channelId, {
|
||||
embeds: [interaction.message.embeds[0]],
|
||||
|
|
|
@ -76,7 +76,8 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
embeds: [{
|
||||
color: failColor,
|
||||
title: 'Invalid Max Member count!',
|
||||
description: `${config.name} parsed the max members as \`${isNaN(activityMaxPlayers) ? 'Not a Number' : activityMaxPlayers
|
||||
description: `${config.name} parsed the max members as \`${
|
||||
isNaN(activityMaxPlayers) ? 'Not a Number' : activityMaxPlayers
|
||||
}\`, which is outside of the allowed range. Please re-edit this activity, but make sure the maximum player count is between 1 and 99.\n\n${safelyDismissMsg}`,
|
||||
}],
|
||||
},
|
||||
|
@ -93,7 +94,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
selectedActivity.maxMembers = activityMaxPlayers;
|
||||
|
||||
// Log custom event to see if we should add it as a preset
|
||||
dbClient.execute(queries.insertCustomActivity, [selectedCategory, selectedActivity.name, selectedActivity.maxMembers]).catch((e) => utils.commonLoggers.dbError('editActivity.ts@custom', 'insert into', e))
|
||||
dbClient.execute(queries.insertCustomActivity, [selectedCategory, selectedActivity.name, selectedActivity.maxMembers]).catch((e) =>
|
||||
utils.commonLoggers.dbError('editActivity.ts@custom', 'insert into', e)
|
||||
);
|
||||
} else {
|
||||
const rawIdxPath: Array<string> = finalizedIdxPath.split(pathIdxSeparator);
|
||||
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
||||
|
@ -195,7 +198,8 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
data: {
|
||||
embeds: [{
|
||||
title: 'Please select a Game and Activity, or create a Custom Event.',
|
||||
description: `Changing activity for [this event](${utils.idsToMessageUrl({
|
||||
description: `Changing activity for [this event](${
|
||||
utils.idsToMessageUrl({
|
||||
guildId: interaction.guildId,
|
||||
channelId: evtChannelId,
|
||||
messageId: evtMessageId,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
|
||||
import { safelyDismissMsg, somethingWentWrong, successColor } from '../../commandUtils.ts';
|
||||
import { dmTestMessage, safelyDismissMsg, sendDirectMessage, somethingWentWrong, successColor, warnColor } from '../../commandUtils.ts';
|
||||
import { idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
|
||||
import { deleteTokenEarly } from '../tokenCleanup.ts';
|
||||
import utils from '../../utils.ts';
|
||||
|
@ -15,7 +15,25 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
dbClient.execute(queries.callIncCnt(makeWhitelisted ? 'btn-eeMakeWL' : 'btn-eeMakePublic')).catch((e) => utils.commonLoggers.dbError('toggleWLStatus.ts', 'call sproc INC_CNT on', e));
|
||||
const [evtChannelId, evtMessageId] = (interaction.data.customId.replaceAll(pathIdxEnder, '').split(idSeparator)[1] || '').split(pathIdxSeparator).map((id) => BigInt(id || '0'));
|
||||
|
||||
// TODO: verify we can DM owner before applying update
|
||||
// Check if we need to ensure DMs are open
|
||||
if (makeWhitelisted) {
|
||||
const dmSuccess = Boolean(await sendDirectMessage(bot, interaction.member.id, dmTestMessage).catch((e: Error) => utils.commonLoggers.messageSendError('toggleWLStatus.ts', 'send DM fail', e)));
|
||||
if (!dmSuccess) {
|
||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: ApplicationCommandFlags.Ephemeral,
|
||||
embeds: [{
|
||||
color: warnColor,
|
||||
title: 'Event not modified.',
|
||||
description: `In order to turn the whitelist on, your DMs must be open to receive Join Requests. Please open your DMs and try again.\n\n${safelyDismissMsg}`,
|
||||
}],
|
||||
},
|
||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('toggleWLStatus.ts@dmFail', interaction, e));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bot.helpers.editMessage(evtChannelId, evtMessageId, {
|
||||
components: [{
|
||||
type: MessageComponentTypes.ActionRow,
|
||||
|
@ -32,7 +50,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
|||
description: `This event is now ${makeWhitelisted ? 'whitelisted, meaning you will have to approve join requests from all future members' : 'public'}.\n\n${safelyDismissMsg}`,
|
||||
}],
|
||||
},
|
||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('toggleWLStatus.ts', interaction, e))
|
||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('toggleWLStatus.ts@dmSuccess', interaction, e))
|
||||
).catch((e) => {
|
||||
utils.commonLoggers.messageEditError('toggleWLStatus.ts', 'toggleWLStatusFailed', e);
|
||||
somethingWentWrong(bot, interaction, 'editFailedInToggleWLStatusButton');
|
||||
|
|
|
@ -80,3 +80,11 @@ Ran into a bug? Report it to my developers using \`/${reportSlashName} [issue d
|
|||
text: `Current Version: ${config.version}`,
|
||||
},
|
||||
};
|
||||
|
||||
export const dmTestMessage: CreateMessage = {
|
||||
embeds: [{
|
||||
color: infoColor2,
|
||||
title: 'Heyo! Just making sure I can reach you.',
|
||||
description: 'This message is just to make sure I can DM you any Join Requests to your event. If you are reading this message, it means you have everything set up correctly.',
|
||||
}],
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue