deno fmt
This commit is contained in:
parent
ee501e4333
commit
ee09ad8c9c
|
@ -1,4 +1,4 @@
|
|||
export const config = {// !! NOTICE !! All fields below are required unless they are explicitly noted as OPTIONAL. If a field is OPTIONAL, do not remove it from this file, just leave it at the default value
|
||||
export const config = { // !! NOTICE !! All fields below are required unless they are explicitly noted as OPTIONAL. If a field is OPTIONAL, do not remove it from this file, just leave it at the default value
|
||||
'name': 'Group Up', // Name of the bot
|
||||
'version': '1.1.0', // Version of the bot
|
||||
'token': 'the_bot_token', // Discord API Token for this bot
|
||||
|
|
|
@ -12,133 +12,133 @@ export const confirmedCustomId = 'confirmedCustomId';
|
|||
export const confirmStr = 'yes';
|
||||
|
||||
const execute = async (bot: Bot, interaction: Interaction) => {
|
||||
if (interaction.data?.customId && interaction.data?.components?.length && interaction.channelId && interaction.guildId && interaction?.member?.user) {
|
||||
// Light Telemetry
|
||||
dbClient.execute(queries.callIncCnt('btn-confirmDelEvent')).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@incCnt', 'call sproc INC_CNT on', e));
|
||||
if (interaction.data?.customId && interaction.data?.components?.length && interaction.channelId && interaction.guildId && interaction?.member?.user) {
|
||||
// Light Telemetry
|
||||
dbClient.execute(queries.callIncCnt('btn-confirmDelEvent')).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@incCnt', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Parse out our data
|
||||
const tempDataMap: Map<string, string> = new Map();
|
||||
for (const row of interaction.data.components) {
|
||||
if (row.components?.[0]) {
|
||||
const textField = row.components[0];
|
||||
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || 'missingValue');
|
||||
}
|
||||
}
|
||||
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 lfgChannelSetting = lfgChannelSettings.get(generateGuildSettingKey(interaction.guildId, interaction.channelId)) || {
|
||||
managed: false,
|
||||
managerRoleId: 0n,
|
||||
logChannelId: 0n,
|
||||
};
|
||||
// Parse out our data
|
||||
const tempDataMap: Map<string, string> = new Map();
|
||||
for (const row of interaction.data.components) {
|
||||
if (row.components?.[0]) {
|
||||
const textField = row.components[0];
|
||||
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || 'missingValue');
|
||||
}
|
||||
}
|
||||
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 lfgChannelSetting = lfgChannelSettings.get(generateGuildSettingKey(interaction.guildId, interaction.channelId)) || {
|
||||
managed: false,
|
||||
managerRoleId: 0n,
|
||||
logChannelId: 0n,
|
||||
};
|
||||
|
||||
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 userId = interaction.member.id;
|
||||
const userName = interaction.member.user.username;
|
||||
// Delete event
|
||||
bot.helpers
|
||||
.deleteMessage(evtChannelId, evtMessageId, 'User deleted event')
|
||||
.then(() => {
|
||||
dbClient.execute(queries.deleteEvent, [evtChannelId, evtMessageId]).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@deleteEvent', 'delete event from', e));
|
||||
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 userId = interaction.member.id;
|
||||
const userName = interaction.member.user.username;
|
||||
// Delete event
|
||||
bot.helpers
|
||||
.deleteMessage(evtChannelId, evtMessageId, 'User deleted event')
|
||||
.then(() => {
|
||||
dbClient.execute(queries.deleteEvent, [evtChannelId, evtMessageId]).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@deleteEvent', 'delete event from', e));
|
||||
|
||||
// Acknowledge user so discord doesn't get annoyed
|
||||
bot.helpers
|
||||
.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: ApplicationCommandFlags.Ephemeral,
|
||||
embeds: [
|
||||
{
|
||||
color: successColor,
|
||||
title: 'Event successfully deleted.',
|
||||
description: safelyDismissMsg,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
||||
// Acknowledge user so discord doesn't get annoyed
|
||||
bot.helpers
|
||||
.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: ApplicationCommandFlags.Ephemeral,
|
||||
embeds: [
|
||||
{
|
||||
color: successColor,
|
||||
title: 'Event successfully deleted.',
|
||||
description: safelyDismissMsg,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
||||
|
||||
if (actionByManager) {
|
||||
const ownerId = BigInt(eventMessage?.embeds[0].footer?.iconUrl?.split('#')[1] || '0');
|
||||
const eventEmbed = eventMessage?.embeds[0] || { title: 'Event not found', color: failColor };
|
||||
bot.helpers
|
||||
.sendMessage(lfgChannelSetting.logChannelId, {
|
||||
embeds: [
|
||||
{
|
||||
color: infoColor2,
|
||||
title: `Event deleted by a ${config.name} Manager`,
|
||||
description: `The following event was deleted by ${userName} - <@${userId}>.`,
|
||||
timestamp: new Date().getTime(),
|
||||
},
|
||||
eventEmbed,
|
||||
],
|
||||
})
|
||||
.catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send log message', e));
|
||||
if (actionByManager) {
|
||||
const ownerId = BigInt(eventMessage?.embeds[0].footer?.iconUrl?.split('#')[1] || '0');
|
||||
const eventEmbed = eventMessage?.embeds[0] || { title: 'Event not found', color: failColor };
|
||||
bot.helpers
|
||||
.sendMessage(lfgChannelSetting.logChannelId, {
|
||||
embeds: [
|
||||
{
|
||||
color: infoColor2,
|
||||
title: `Event deleted by a ${config.name} Manager`,
|
||||
description: `The following event was deleted by ${userName} - <@${userId}>.`,
|
||||
timestamp: new Date().getTime(),
|
||||
},
|
||||
eventEmbed,
|
||||
],
|
||||
})
|
||||
.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) => {
|
||||
utils.commonLoggers.messageDeleteError('deleteConfirmed.ts', 'deleteEventFailedDB', e);
|
||||
somethingWentWrong(bot, interaction, 'deleteEventMessageInDeleteConfirmedButton');
|
||||
});
|
||||
} else if (tempDataMap.get(confirmedCustomId)) {
|
||||
// User either did not type yes confirm field was missing, lets see which it was
|
||||
// User did not type yes.
|
||||
bot.helpers
|
||||
.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: ApplicationCommandFlags.Ephemeral,
|
||||
embeds: [
|
||||
{
|
||||
color: infoColor1,
|
||||
title: 'Event not deleted.',
|
||||
description: `If you are trying to delete the event, please make sure you type \`${confirmStr}\` into the field provided.
|
||||
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) => {
|
||||
utils.commonLoggers.messageDeleteError('deleteConfirmed.ts', 'deleteEventFailedDB', e);
|
||||
somethingWentWrong(bot, interaction, 'deleteEventMessageInDeleteConfirmedButton');
|
||||
});
|
||||
} else if (tempDataMap.get(confirmedCustomId)) {
|
||||
// User either did not type yes confirm field was missing, lets see which it was
|
||||
// User did not type yes.
|
||||
bot.helpers
|
||||
.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: ApplicationCommandFlags.Ephemeral,
|
||||
embeds: [
|
||||
{
|
||||
color: infoColor1,
|
||||
title: 'Event not deleted.',
|
||||
description: `If you are trying to delete the event, please make sure you type \`${confirmStr}\` into the field provided.
|
||||
|
||||
${safelyDismissMsg}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
||||
} else {
|
||||
// Field was missing
|
||||
somethingWentWrong(bot, interaction, 'noIdsFromDeleteConfirmedButton');
|
||||
}
|
||||
} else {
|
||||
somethingWentWrong(bot, interaction, 'noDataFromDeleteConfirmedButton');
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
||||
} else {
|
||||
// Field was missing
|
||||
somethingWentWrong(bot, interaction, 'noIdsFromDeleteConfirmedButton');
|
||||
}
|
||||
} else {
|
||||
somethingWentWrong(bot, interaction, 'noDataFromDeleteConfirmedButton');
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteConfirmedButton = {
|
||||
customId,
|
||||
execute,
|
||||
customId,
|
||||
execute,
|
||||
};
|
||||
|
|
|
@ -194,7 +194,7 @@ export const removeMemberFromEvent = async (
|
|||
await sendDirectMessage(bot, memberToPromote.id, {
|
||||
embeds: [{
|
||||
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 \`${await getGuildName(
|
||||
bot,
|
||||
evtGuildId,
|
||||
|
|
|
@ -3,9 +3,9 @@ import { Client } from '../../deps.ts';
|
|||
import { LOCALMODE } from '../../flags.ts';
|
||||
|
||||
export const dbClient = await new Client().connect({
|
||||
hostname: LOCALMODE ? config.db.localhost : config.db.host,
|
||||
port: config.db.port,
|
||||
db: config.db.name,
|
||||
username: config.db.username,
|
||||
password: config.db.password,
|
||||
hostname: LOCALMODE ? config.db.localhost : config.db.host,
|
||||
port: config.db.port,
|
||||
db: config.db.name,
|
||||
username: config.db.username,
|
||||
password: config.db.password,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue