deno fmt + change sendMessage to bot.helpers.sendMessage

This commit is contained in:
Ean Milligan (Bastion) 2023-04-06 23:40:57 -04:00
parent e609654761
commit 988f826545
11 changed files with 38 additions and 52 deletions

View File

@ -23,8 +23,6 @@ export {
InteractionResponseTypes,
MessageComponentTypes,
OverwriteTypes,
sendInteractionResponse,
sendMessage,
startBot,
TextStyles,
} from 'https://deno.land/x/discordeno@17.0.1/mod.ts';

View File

@ -10,11 +10,11 @@ import {
getNestedActivity,
idSeparator,
LfgEmbedIndexes,
lfgStartTimeName,
pathIdxEnder,
pathIdxSeparator,
selfDestructMessage,
tokenMap,
lfgStartTimeName,
} from './utils.ts';
import utils from '../../utils.ts';
import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts';

View File

@ -1,7 +1,7 @@
import { Bot, Interaction } from '../../../deps.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { eventDateId, eventDescriptionId, eventTimeId, eventTimeZoneId } from './step1-gameSelection.ts';
import { createLFGPost, getFinalActivity, idSeparator, pathIdxSeparator, addTokenToMap } from './utils.ts';
import { addTokenToMap, createLFGPost, getFinalActivity, idSeparator, pathIdxSeparator } from './utils.ts';
import { Activities, Activity } from './activities.ts';
import { getDateFromRawInput } from './dateTimeUtils.ts';

View File

@ -1,5 +1,5 @@
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { deleteTokenEarly, LfgEmbedIndexes, generateLFGButtons, idSeparator } from './utils.ts';
import { deleteTokenEarly, generateLFGButtons, idSeparator, LfgEmbedIndexes } from './utils.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { dbClient, queries } from '../../db.ts';
import utils from '../../utils.ts';
@ -7,7 +7,9 @@ import utils from '../../utils.ts';
export const customId = 'createEvent';
const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data?.customId && interaction.member && interaction.guildId && interaction.channelId && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields) {
if (
interaction.data?.customId && interaction.member && interaction.guildId && interaction.channelId && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields
) {
deleteTokenEarly(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
// Get OwnerId and EventTime from embed for DB
@ -20,7 +22,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
components: [{
type: MessageComponentTypes.ActionRow,
components: generateLFGButtons(interaction.data.customId.includes(idSeparator)),
}]
}],
}).catch((e: Error) => utils.commonLoggers.messageSendError('step3-createEvent.ts', 'createEvent', e));
if (!eventMessage) {
somethingWentWrong(bot, interaction, 'creatingEventSendMessageFinalizeEventStep');
@ -34,7 +36,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
dbErrorOut = true;
});
if (dbErrorOut) {
bot.helpers.deleteMessage(eventMessage.channelId, eventMessage.id, 'Failed to log event to DB').catch((e: Error) => utils.commonLoggers.messageDeleteError('step3-createEvent.ts', 'deleteEventFailedDB', e));
bot.helpers.deleteMessage(eventMessage.channelId, eventMessage.id, 'Failed to log event to DB').catch((e: Error) =>
utils.commonLoggers.messageDeleteError('step3-createEvent.ts', 'deleteEventFailedDB', e)
);
somethingWentWrong(bot, interaction, 'creatingEventDBStoreFinalizeEventStep');
return;
}
@ -43,7 +47,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.DeferredUpdateMessage,
});
} else {
somethingWentWrong(bot, interaction, 'noDataFromFinalizeEventStep');
}

View File

@ -139,7 +139,8 @@ export const generateLFGButtons = (whitelist: boolean): [ButtonComponent, Button
const generateMemberTitle = (memberList: Array<LFGMember>, maxMembers: number): string => `Members Joined: ${memberList.length}/${maxMembers}`;
const generateMemberList = (memberList: Array<LFGMember>): string => memberList.length ? memberList.map((member) => `${member.name} - <@${member.id}>`).join('\n') : 'None';
const generateAlternateList = (alternateList: Array<LFGMember>): string => alternateList.length ? alternateList.map((member) => `${member.name} - <@${member.id}>${member.joined ? ' *' : ''}`).join('\n') : 'None';
const generateAlternateList = (alternateList: Array<LFGMember>): string =>
alternateList.length ? alternateList.map((member) => `${member.name} - <@${member.id}>${member.joined ? ' *' : ''}`).join('\n') : 'None';
export enum LfgEmbedIndexes {
Activity,
@ -148,7 +149,7 @@ export enum LfgEmbedIndexes {
Description,
JoinedMembers,
AlternateMembers,
};
}
export const lfgStartTimeName = 'Start Time:';
export const createLFGPost = (
category: string,

View File

@ -1,5 +1,5 @@
import config from '../../config.ts';
import { ApplicationCommandOptionTypes, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes, sendMessage } from '../../deps.ts';
import { ApplicationCommandOptionTypes, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes } from '../../deps.ts';
import { infoColor2, isLFGChannel, somethingWentWrong, successColor } from '../commandUtils.ts';
import { dbClient, queries } from '../db.ts';
import { CommandDetails } from '../types/commandTypes.ts';
@ -24,7 +24,7 @@ const details: CommandDetails = {
const execute = (bot: Bot, interaction: Interaction) => {
dbClient.execute(queries.callIncCnt('cmd-report')).catch((e) => utils.commonLoggers.dbError('report.ts', 'call sproc INC_CNT on', e));
if (interaction.data?.options?.[0].value) {
sendMessage(bot, config.reportChannel, {
bot.helpers.sendMessage(config.reportChannel, {
embeds: [{
color: infoColor2,
title: 'USER REPORT:',

View File

@ -12,7 +12,6 @@ import {
InteractionResponseTypes,
MessageComponentTypes,
OverwriteTypes,
sendMessage,
} from '../../deps.ts';
import { failColor, infoColor2, safelyDismissMsg, somethingWentWrong, successColor } from '../commandUtils.ts';
import { dbClient, lfgChannelSettings, queries } from '../db.ts';
@ -99,16 +98,6 @@ const execute = async (bot: Bot, interaction: Interaction) => {
},
];
if (setupOpts.name === withMgrRole) {
introFields.push({
name: `${config.name} Manager Details:`,
value: `${config.name} Managers with the <@&${managerRoleId}> role may edit or delete events in this guild, along with using the following commands to update the activity members:
\`/join\`
\`/leave\`
\`/alternate\`
The Discord Slash Command system will ensure you provide all the required details.`,
});
if (setupOpts.options?.length) {
setupOpts.options.forEach((opt) => {
if (opt.name === managerRoleStr) {
@ -143,9 +132,17 @@ The Discord Slash Command system will ensure you provide all the required detail
somethingWentWrong(bot, interaction, 'setupMissingRoleMgrOptions');
return;
}
introFields.push({
name: `${config.name} Manager Details:`,
value: `${config.name} Managers with the <@&${managerRoleId}> role may edit or delete events in this guild, along with using the following commands to update the activity members:
\`/join\` \`/leave\` \`/alternate\`
The Discord Slash Command system will ensure you provide all the required details.`,
});
// Test sending a message to the logChannel
await sendMessage(bot, logChannelId, {
await bot.helpers.sendMessage(logChannelId, {
embeds: [{
title: `This is the channel ${config.name} will be logging events to.`,
description: `${config.name} will only send messages here as frequently as your event managers update events.`,
@ -226,7 +223,11 @@ The Discord Slash Command system will ensure you provide all the required detail
}
});
if (msgsToDel.length) {
await bot.helpers.deleteMessages(interaction.channelId, msgsToDel, 'Cleaning LFG Channel').catch((e: Error) => utils.commonLoggers.messageDeleteError('setup.ts', 'bulk-msg-cleanup', e));
for (const msgToDel of msgsToDel) {
await bot.helpers.deleteMessage(interaction.channelId, msgToDel, 'Initial LFG Channel Cleanup').catch((e: Error) =>
utils.commonLoggers.messageDeleteError('setup.ts', 'bulk-msg-cleanup', e)
);
}
}
// Retrofit all old LFG posts that we found
@ -255,7 +256,7 @@ The Discord Slash Command system will ensure you provide all the required detail
// Send the initial introduction message
const createNewEventBtn = 'Create New Event';
const introMsg = await sendMessage(bot, interaction.channelId, {
const introMsg = await bot.helpers.sendMessage(interaction.channelId, {
content: `Welcome to <#${interaction.channelId}>, managed by <@${botId}>!`,
embeds: [{
title: `To get started, click on the '${createNewEventBtn}' button below!`,

View File

@ -1,20 +1,11 @@
import config from '../../config.ts';
import {
// Discordeno deps
Bot,
Guild,
// Log4Deno deps
log,
LT,
// Discordeno deps
sendMessage,
} from '../../deps.ts';
import { Bot, Guild, log, LT } from '../../deps.ts';
import { infoColor1 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const guildCreate = (bot: Bot, guild: Guild) => {
log(LT.LOG, `Handling joining guild ${utils.jsonStringifyBig(guild)}`);
sendMessage(bot, config.logChannel, {
bot.helpers.sendMessage(config.logChannel, {
embeds: [{
title: 'Guild Joined!',
color: infoColor1,

View File

@ -1,13 +1,5 @@
import config from '../../config.ts';
import {
// Discordeno deps
Bot,
// Log4Deno deps
log,
LT,
// Discordeno deps
sendMessage,
} from '../../deps.ts';
import { Bot, log, LT } from '../../deps.ts';
import { warnColor } from '../commandUtils.ts';
import { dbClient } from '../db.ts';
import utils from '../utils.ts';
@ -23,7 +15,7 @@ export const guildDelete = async (bot: Bot, guildId: bigint) => {
log(LT.WARN, `Failed to remove guild from DB: ${utils.jsonStringifyBig(e)}`);
}
sendMessage(bot, config.logChannel, {
bot.helpers.sendMessage(config.logChannel, {
embeds: [{
title: 'Removed from Guild',
color: warnColor,

View File

@ -1,4 +1,4 @@
import { Bot, BotWithCache, Interaction } from '../../deps.ts';
import { Bot, BotWithCache, Interaction, log, LT } from '../../deps.ts';
import { buttons } from '../buttons/_index.ts';
import { commands } from '../commands/_index.ts';
import { idSeparator } from '../buttons/event-creation/utils.ts';
@ -23,6 +23,6 @@ export const interactionCreate = (rawBot: Bot, interaction: Interaction) => {
return;
}
console.log('interaction NOT HANDLED', interaction);
log(LT.WARN, `interaction NOT HANDLED!!! customId: ${interaction.data.customId} name: ${interaction.data.name}`);
}
};

View File

@ -1,6 +1,6 @@
import config from '../../config.ts';
import { LOCALMODE } from '../../flags.ts';
import { ActivityTypes, Bot, BotWithCache, editBotMember, editBotStatus, log, LT, sendMessage } from '../../deps.ts';
import { ActivityTypes, Bot, BotWithCache, editBotMember, editBotStatus, log, LT } from '../../deps.ts';
import { getRandomStatus, successColor } from '../commandUtils.ts';
import utils from '../utils.ts';
@ -45,7 +45,7 @@ export const ready = (rawBot: Bot) => {
}],
status: 'online',
});
sendMessage(bot, config.logChannel, {
bot.helpers.sendMessage(config.logChannel, {
embeds: [{
title: `${config.name} is now Online`,
color: successColor,