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
|
'name': 'Group Up', // Name of the bot
|
||||||
'version': '1.1.0', // Version of the bot
|
'version': '1.1.0', // Version of the bot
|
||||||
'token': 'the_bot_token', // Discord API Token for this bot
|
'token': 'the_bot_token', // Discord API Token for this bot
|
||||||
|
|
|
@ -12,133 +12,133 @@ export const confirmedCustomId = 'confirmedCustomId';
|
||||||
export const confirmStr = 'yes';
|
export const confirmStr = 'yes';
|
||||||
|
|
||||||
const execute = async (bot: Bot, interaction: Interaction) => {
|
const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
if (interaction.data?.customId && interaction.data?.components?.length && interaction.channelId && interaction.guildId && interaction?.member?.user) {
|
if (interaction.data?.customId && interaction.data?.components?.length && interaction.channelId && interaction.guildId && interaction?.member?.user) {
|
||||||
// Light Telemetry
|
// Light Telemetry
|
||||||
dbClient.execute(queries.callIncCnt('btn-confirmDelEvent')).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@incCnt', 'call sproc INC_CNT on', e));
|
dbClient.execute(queries.callIncCnt('btn-confirmDelEvent')).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@incCnt', 'call sproc INC_CNT on', e));
|
||||||
|
|
||||||
// Parse out our data
|
// Parse out our data
|
||||||
const tempDataMap: Map<string, string> = new Map();
|
const tempDataMap: Map<string, string> = new Map();
|
||||||
for (const row of interaction.data.components) {
|
for (const row of interaction.data.components) {
|
||||||
if (row.components?.[0]) {
|
if (row.components?.[0]) {
|
||||||
const textField = row.components[0];
|
const textField = row.components[0];
|
||||||
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || 'missingValue');
|
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || 'missingValue');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 lfgChannelSetting = lfgChannelSettings.get(generateGuildSettingKey(interaction.guildId, interaction.channelId)) || {
|
const lfgChannelSetting = lfgChannelSettings.get(generateGuildSettingKey(interaction.guildId, interaction.channelId)) || {
|
||||||
managed: false,
|
managed: false,
|
||||||
managerRoleId: 0n,
|
managerRoleId: 0n,
|
||||||
logChannelId: 0n,
|
logChannelId: 0n,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tempDataMap.get(confirmedCustomId)?.toLowerCase() === confirmStr) {
|
if (tempDataMap.get(confirmedCustomId)?.toLowerCase() === confirmStr) {
|
||||||
const guildName = await getGuildName(bot, interaction.guildId);
|
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;
|
||||||
// Delete event
|
// Delete event
|
||||||
bot.helpers
|
bot.helpers
|
||||||
.deleteMessage(evtChannelId, evtMessageId, 'User deleted event')
|
.deleteMessage(evtChannelId, evtMessageId, 'User deleted event')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dbClient.execute(queries.deleteEvent, [evtChannelId, evtMessageId]).catch((e) => utils.commonLoggers.dbError('deleteConfirmed.ts@deleteEvent', 'delete event from', e));
|
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
|
// Acknowledge user so discord doesn't get annoyed
|
||||||
bot.helpers
|
bot.helpers
|
||||||
.sendInteractionResponse(interaction.id, interaction.token, {
|
.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
data: {
|
data: {
|
||||||
flags: ApplicationCommandFlags.Ephemeral,
|
flags: ApplicationCommandFlags.Ephemeral,
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: successColor,
|
color: successColor,
|
||||||
title: 'Event successfully deleted.',
|
title: 'Event successfully deleted.',
|
||||||
description: safelyDismissMsg,
|
description: safelyDismissMsg,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.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 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
|
bot.helpers
|
||||||
.sendMessage(lfgChannelSetting.logChannelId, {
|
.sendMessage(lfgChannelSetting.logChannelId, {
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: infoColor2,
|
color: infoColor2,
|
||||||
title: `Event deleted by a ${config.name} Manager`,
|
title: `Event deleted by a ${config.name} Manager`,
|
||||||
description: `The following event was deleted by ${userName} - <@${userId}>.`,
|
description: `The following event was deleted by ${userName} - <@${userId}>.`,
|
||||||
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, {
|
sendDirectMessage(bot, ownerId, {
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: infoColor2,
|
color: infoColor2,
|
||||||
title: `Notice: A ${config.name} Manager has deleted one of your events in ${guildName}`,
|
title: `Notice: A ${config.name} Manager has deleted one of your events in ${guildName}`,
|
||||||
description: 'The deleted event is listed below.',
|
description: 'The deleted event is listed below.',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: `${config.name} Manager:`,
|
name: `${config.name} Manager:`,
|
||||||
value: generateMemberList([
|
value: generateMemberList([
|
||||||
{
|
{
|
||||||
id: userId,
|
id: userId,
|
||||||
name: userName,
|
name: userName,
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Are you unhappy with this action?',
|
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}.`,
|
value: `Please reach out to the ${config.name} Manager that performed this action, or the moderators/administrators of ${guildName}.`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
eventEmbed,
|
eventEmbed,
|
||||||
],
|
],
|
||||||
}).catch((e: Error) => utils.commonLoggers.messageSendError('deleteConfirmed.ts', 'send DM fail', e));
|
}).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);
|
||||||
somethingWentWrong(bot, interaction, 'deleteEventMessageInDeleteConfirmedButton');
|
somethingWentWrong(bot, interaction, 'deleteEventMessageInDeleteConfirmedButton');
|
||||||
});
|
});
|
||||||
} else if (tempDataMap.get(confirmedCustomId)) {
|
} else if (tempDataMap.get(confirmedCustomId)) {
|
||||||
// User either did not type yes confirm field was missing, lets see which it was
|
// User either did not type yes confirm field was missing, lets see which it was
|
||||||
// User did not type yes.
|
// User did not type yes.
|
||||||
bot.helpers
|
bot.helpers
|
||||||
.sendInteractionResponse(interaction.id, interaction.token, {
|
.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
data: {
|
data: {
|
||||||
flags: ApplicationCommandFlags.Ephemeral,
|
flags: ApplicationCommandFlags.Ephemeral,
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: infoColor1,
|
color: infoColor1,
|
||||||
title: 'Event not deleted.',
|
title: 'Event not deleted.',
|
||||||
description: `If you are trying to delete the event, please make sure you type \`${confirmStr}\` into the field provided.
|
description: `If you are trying to delete the event, please make sure you type \`${confirmStr}\` into the field provided.
|
||||||
|
|
||||||
${safelyDismissMsg}`,
|
${safelyDismissMsg}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
.catch((e: Error) => utils.commonLoggers.interactionSendError('deleteConfirmed.ts', interaction, e));
|
||||||
} else {
|
} else {
|
||||||
// Field was missing
|
// Field was missing
|
||||||
somethingWentWrong(bot, interaction, 'noIdsFromDeleteConfirmedButton');
|
somethingWentWrong(bot, interaction, 'noIdsFromDeleteConfirmedButton');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
somethingWentWrong(bot, interaction, 'noDataFromDeleteConfirmedButton');
|
somethingWentWrong(bot, interaction, 'noDataFromDeleteConfirmedButton');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteConfirmedButton = {
|
export const deleteConfirmedButton = {
|
||||||
customId,
|
customId,
|
||||||
execute,
|
execute,
|
||||||
};
|
};
|
||||||
|
|
|
@ -194,7 +194,7 @@ export const removeMemberFromEvent = async (
|
||||||
await sendDirectMessage(bot, memberToPromote.id, {
|
await sendDirectMessage(bot, memberToPromote.id, {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
color: successColor,
|
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(
|
description: `A member left [the full event](${utils.idsToMessageUrl(urlIds)}) in \`${await getGuildName(
|
||||||
bot,
|
bot,
|
||||||
evtGuildId,
|
evtGuildId,
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { Client } from '../../deps.ts';
|
||||||
import { LOCALMODE } from '../../flags.ts';
|
import { LOCALMODE } from '../../flags.ts';
|
||||||
|
|
||||||
export const dbClient = await new Client().connect({
|
export const dbClient = await new Client().connect({
|
||||||
hostname: LOCALMODE ? config.db.localhost : config.db.host,
|
hostname: LOCALMODE ? config.db.localhost : config.db.host,
|
||||||
port: config.db.port,
|
port: config.db.port,
|
||||||
db: config.db.name,
|
db: config.db.name,
|
||||||
username: config.db.username,
|
username: config.db.username,
|
||||||
password: config.db.password,
|
password: config.db.password,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue