Add edit menu

This commit is contained in:
Ean Milligan (Bastion) 2023-04-25 03:21:02 -04:00
parent ce0a3cca1d
commit 7352554ddf
4 changed files with 93 additions and 2 deletions

View File

@ -25,6 +25,10 @@ const actions = [
'btn-joinReqAlt', 'btn-joinReqAlt',
'btn-delEvent', 'btn-delEvent',
'btn-confirmDelEvent', 'btn-confirmDelEvent',
'btn-editEvent',
'btn-eeChangeAct',
'btn-eeChangeTime',
'btn-eeChangeDesc',
]; ];
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) => {

View File

@ -11,6 +11,7 @@ import { joinRequestButton } from './live-event/joinRequest.ts';
import { alternateRequestButton } from './live-event/alternateRequest.ts'; import { alternateRequestButton } from './live-event/alternateRequest.ts';
import { deleteEventButton } from './live-event/deleteEvent.ts'; import { deleteEventButton } from './live-event/deleteEvent.ts';
import { deleteConfirmedButton } from './live-event/deleteConfirmed.ts'; import { deleteConfirmedButton } from './live-event/deleteConfirmed.ts';
import { editEventButton } from './live-event/editEvent.ts';
export const buttons: Array<Button> = [ export const buttons: Array<Button> = [
gameSelectionButton, gameSelectionButton,
@ -25,4 +26,5 @@ export const buttons: Array<Button> = [
alternateRequestButton, alternateRequestButton,
deleteEventButton, deleteEventButton,
deleteConfirmedButton, deleteConfirmedButton,
editEventButton,
]; ];

View File

@ -23,7 +23,7 @@ import { customId as joinEventCustomId } from '../live-event/joinEvent.ts';
import { customId as leaveEventCustomId } from '../live-event/leaveEvent.ts'; import { customId as leaveEventCustomId } from '../live-event/leaveEvent.ts';
import { customId as alternateEventCustomId } from '../live-event/alternateEvent.ts'; import { customId as alternateEventCustomId } from '../live-event/alternateEvent.ts';
import { customId as deleteEventCustomId } from '../live-event/deleteEvent.ts'; import { customId as deleteEventCustomId } from '../live-event/deleteEvent.ts';
import { customId as editEventCustomId } from '../live-event/editEvent.ts';
export const getNestedActivity = (idxPath: Array<number>, activities: Array<Activity>): Array<Activity> => { export const getNestedActivity = (idxPath: Array<number>, activities: Array<Activity>): Array<Activity> => {
const nextIdx = idxPath[0]; const nextIdx = idxPath[0];
@ -92,7 +92,7 @@ export const generateLFGButtons = (whitelist: boolean): [ButtonComponent, Button
type: MessageComponentTypes.Button, type: MessageComponentTypes.Button,
label: '', label: '',
style: ButtonStyles.Secondary, style: ButtonStyles.Secondary,
customId: 'editEvent', // TODO: replace with proper id customId: editEventCustomId,
emoji: { emoji: {
name: '✏️', name: '✏️',
}, },

View File

@ -0,0 +1,85 @@
import { ApplicationCommandFlags, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../../db.ts';
import { infoColor1, somethingWentWrong, stopThat } from '../../commandUtils.ts';
import { idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts';
import { addTokenToMap, selfDestructMessage } from '../tokenCleanup.ts';
import utils from '../../utils.ts';
export const customId = 'editEvent';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.channelId && interaction.guildId && interaction.message) {
// Light Telemetry
dbClient.execute(queries.callIncCnt('btn-editEvent')).catch((e) => utils.commonLoggers.dbError('editEvent.ts', 'call sproc INC_CNT on', e));
const ownerId = BigInt(interaction.message.embeds[0].footer?.iconUrl?.split('#')[1] || '0');
const lfgChannelSetting = lfgChannelSettings.get(generateGuildSettingKey(interaction.guildId, interaction.channelId)) || {
managed: false,
managerRoleId: 0n,
logChannelId: 0n,
};
// Make sure this is being done by the owner or a Group Up Manager
if (interaction.member.id === ownerId || (lfgChannelSetting.managed && interaction.member.roles.includes(lfgChannelSetting.managerRoleId))) {
const actionByManager = interaction.member.id !== ownerId;
const editIdxPath = `${idSeparator}${interaction.channelId}${pathIdxSeparator}${interaction.message.id}${actionByManager ? pathIdxEnder : ''}`;
// Store token for later use
addTokenToMap(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
// Open Edit Options
bot.helpers.sendInteractionResponse(
interaction.id,
interaction.token,
{
type: InteractionResponseTypes.ChannelMessageWithSource,
data: {
flags: ApplicationCommandFlags.Ephemeral,
embeds: [{
color: infoColor1,
title: 'Edit Menu',
description: `Now editing [this event](${
utils.idsToMessageUrl({
guildId: interaction.guildId,
channelId: interaction.channelId,
messageId: interaction.message.id,
})
}). Please select an option below.
${selfDestructMessage(new Date().getTime())}`,
}],
components: [{
type: MessageComponentTypes.ActionRow,
components: [{
type: MessageComponentTypes.Button,
label: 'Change Activity',
style: ButtonStyles.Primary,
customId: `a${editIdxPath}`, // TODO: add customId
}, {
type: MessageComponentTypes.Button,
label: 'Change Date/Time',
style: ButtonStyles.Primary,
customId: `b${editIdxPath}`, // TODO: add customId
}, {
type: MessageComponentTypes.Button,
label: 'Edit Description',
style: ButtonStyles.Primary,
customId: `c${editIdxPath}`, // TODO: add customId
}],
}],
},
},
).catch((e: Error) => utils.commonLoggers.interactionSendError('editEvent.ts', interaction, e));
} else {
// Not owner or manager, tell user they can't
stopThat(bot, interaction, 'edit');
}
} else {
somethingWentWrong(bot, interaction, 'noDataFromEditEventButton');
}
};
export const editEventButton = {
customId,
execute,
};