From 3631cbebcdcd63ba83068ff211ee9a029bd800a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 1 Jan 2025 15:20:23 +0100 Subject: [PATCH] update test command --- .gitignore | 4 +- prisma/schema.prisma | 157 ++++++++++++++---------------- prisma/schema/embed.ts | 22 ++--- prisma/schema/embedauthor.ts | 2 +- prisma/schema/embedfield.ts | 2 +- prisma/schema/embedfooter.ts | 2 +- prisma/schema/guild.ts | 6 +- prisma/schema/leaver.ts | 10 +- prisma/schema/welcomer.ts | 14 +-- src/events/client/ready.ts | 71 +++++++------- src/selectMenus/testMenu.ts | 49 +++++----- src/utils/messages.ts | 178 ++++++++++++++++++++++------------- 12 files changed, 281 insertions(+), 236 deletions(-) diff --git a/.gitignore b/.gitignore index e360329..4009d27 100644 --- a/.gitignore +++ b/.gitignore @@ -132,4 +132,6 @@ dist .pnp.* # test folder -test \ No newline at end of file +test +/prisma/schema/* +/prisma/ERD.md \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3e12497..8d10853 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,13 +1,17 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? -// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init - generator client { provider = "prisma-client-js" } +generator zod { + provider = "zod-prisma" + output = "./schema" + relationModel = "true" + modelSuffix = "Model" + useDecimalJs = "true" + prismaJsonNullability = "true" + modelCase = "PascalCase" +} + datasource db { provider = "postgresql" url = env("DATABASE_URL") @@ -15,111 +19,109 @@ datasource db { model Guild { id String @id @unique - welcomer Welcomer? + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt leaver Leaver? - createdAt DateTime? @default(now()) - updatedAt DateTime? @updatedAt + welcomer Welcomer? } model Welcomer { - id Int @unique @default(autoincrement()) /// @zod.optional() - guildId String @unique - guild Guild? @relation(fields: [guildId], references: [id]) - channelId String - content String - embeds Embed[] /// @zod.max(10) + id Int @id @default(autoincrement()) /// @zod.optional() + guildId String @unique + channelId String? + content String? + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt DM DM? - createdAt DateTime? @default(now()) - updatedAt DateTime? @updatedAt + embeds Embed[] + guild Guild? @relation(fields: [guildId], references: [id]) } model Leaver { - id Int @unique @default(autoincrement()) /// @zod.optional() - guildId String @unique - guild Guild? @relation(fields: [guildId], references: [id]) - channelId String - content String - embeds Embed[] + id Int @id @default(autoincrement()) /// @zod.optional() + guildId String @unique + channelId String? + content String? createdAt DateTime? @default(now()) updatedAt DateTime? @updatedAt + embeds Embed[] + guild Guild? @relation(fields: [guildId], references: [id]) } model DM { - id Int @unique @default(autoincrement()) - moduleId Int @unique - module Welcomer @relation(fields: [moduleId], references: [id]) + id Int @id @default(autoincrement()) /// @zod.optional() + moduleId Int @unique message String - embeds Embed[] createdAt DateTime? @default(now()) updatedAt DateTime? @updatedAt + module Welcomer @relation(fields: [moduleId], references: [id]) + embeds Embed[] } - + model Embed { - id Int @id @default(autoincrement()) /// @zod.optional() - title String? @db.VarChar(256) + id Int @id @default(autoincrement()) /// @zod.optional() + title String? @db.VarChar(256) description String? @db.VarChar(4096) color String? timestamp DateTime? timestampNow Boolean? - footer EmbedFooter? - fields EmbedField[] - author EmbedAuthor? - image EmbedImage? thumbnail String? url String? - created DateTime? @default(now()) /// @zod.optional() - updated DateTime? @default(now()) /// @zod.optional() - - // relations - welcomerId Int? - welcomer Welcomer? @relation(fields: [welcomerId], references: [id]) - leaverId Int? - leaver Leaver? @relation(fields: [leaverId], references: [id]) - DMId Int? - DM DM? @relation(fields: [DMId], references: [id]) + created DateTime? @default(now()) + updated DateTime? @default(now()) + welcomerId Int? + leaverId Int? + DMId Int? + DM DM? @relation(fields: [DMId], references: [id]) + leaver Leaver? @relation(fields: [leaverId], references: [id]) + welcomer Welcomer? @relation(fields: [welcomerId], references: [id]) + author EmbedAuthor? + fields EmbedField[] + footer EmbedFooter? + image EmbedImage? } model EmbedImage { - id Int @id @default(autoincrement()) - embedId Int @unique - embed Embed @relation(fields: [embedId], references: [id]) + id Int @id @default(autoincrement()) /// @zod.optional() + embedId Int @unique url String width Int? heigth Int? createdAt DateTime? @default(now()) updatedAt DateTime? @updatedAt + embed Embed? @relation(fields: [embedId], references: [id]) } model EmbedAuthor { - id Int @id @default(autoincrement())/// @zod.optional() - embedId Int? @unique/// @zod.optional() - embed Embed? @relation(fields: [embedId], references: [id])/// @zod.optional() + id Int @id @default(autoincrement()) /// @zod.optional() + embedId Int? @unique name String? iconUrl String? - url String? @db.VarChar(256) + url String? @db.VarChar(256) createdAt DateTime? @default(now()) updatedAt DateTime? @updatedAt + embed Embed? @relation(fields: [embedId], references: [id]) } model EmbedField { - id Int @id @default(autoincrement())/// @zod.optional() - embedId Int? @unique/// @zod.optional() - embed Embed? @relation(fields: [embedId], references: [id])/// @zod.optional() + id Int @id @default(autoincrement()) /// @zod.optional() + embedId Int? @unique name String value String inline Boolean? createdAt DateTime? @default(now()) updatedAt DateTime? @updatedAt + embed Embed? @relation(fields: [embedId], references: [id]) } model EmbedFooter { - id Int @id @default(autoincrement())/// @zod.optional() - embedId Int? @unique /// @zod.optional() - embed Embed? @relation(fields: [embedId], references: [id]) /// @zod.optional() + id Int @id @default(autoincrement()) /// @zod.optional() + embedId Int? @unique text String? @db.VarChar(2048) iconUrl String? - createdAt DateTime? @default(now())/// @zod.optional() - updatedAt DateTime? @updatedAt/// @zod.optional() + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt + embed Embed? @relation(fields: [embedId], references: [id]) } model User { @@ -129,8 +131,8 @@ model User { avatar String? accessToken String? refreshToken String? - createdAt DateTime? @default(now()) - updatedAt DateTime? @updatedAt + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt guilds UserGuild[] } @@ -140,11 +142,11 @@ model UserGuild { icon String? banner String? permissions String? - channels Channels[] userId String + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt + channels Channels[] user User @relation(fields: [userId], references: [id]) - createdAt DateTime? @default(now()) - updatedAt DateTime? @updatedAt } model Channels { @@ -152,29 +154,8 @@ model Channels { type String name String guildId String - guild UserGuild @relation(fields: [guildId], references: [id]) channelId String - createdAt DateTime? @default(now()) - updatedAt DateTime? @updatedAt + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt + guild UserGuild @relation(fields: [guildId], references: [id]) } - -generator zod { - provider = "zod-prisma" - output = "./schema" // (default) the directory where generated zod schemas will be saved - - relationModel = true // (default) Create and export both plain and related models. - // relationModel = "default" // Do not export model without relations. - // relationModel = false // Do not generate related model - - modelCase = "PascalCase" // (default) Output models using pascal case (ex. UserModel, PostModel) - // modelCase = "camelCase" // Output models using camel case (ex. userModel, postModel) - - modelSuffix = "Model" // (default) Suffix to apply to your prisma models when naming Zod schemas - - // useDecimalJs = false // (default) represent the prisma Decimal type using as a JS number - useDecimalJs = true // represent the prisma Decimal type using Decimal.js (as Prisma does) - - // https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-by-null-values - prismaJsonNullability = true // (default) uses prisma's scheme for JSON field nullability - // prismaJsonNullability = false // allows null assignment to optional JSON fields -} \ No newline at end of file diff --git a/prisma/schema/embed.ts b/prisma/schema/embed.ts index 00c8190..f0bde88 100644 --- a/prisma/schema/embed.ts +++ b/prisma/schema/embed.ts @@ -1,5 +1,5 @@ import * as z from "zod" -import { CompleteEmbedFooter, RelatedEmbedFooterModel, CompleteEmbedField, RelatedEmbedFieldModel, CompleteEmbedAuthor, RelatedEmbedAuthorModel, CompleteEmbedImage, RelatedEmbedImageModel, CompleteWelcomer, RelatedWelcomerModel, CompleteLeaver, RelatedLeaverModel, CompleteDM, RelatedDMModel } from "./index" +import { CompleteDM, RelatedDMModel, CompleteLeaver, RelatedLeaverModel, CompleteWelcomer, RelatedWelcomerModel, CompleteEmbedAuthor, RelatedEmbedAuthorModel, CompleteEmbedField, RelatedEmbedFieldModel, CompleteEmbedFooter, RelatedEmbedFooterModel, CompleteEmbedImage, RelatedEmbedImageModel } from "./index" export const EmbedModel = z.object({ id: z.number().int().optional(), @@ -18,13 +18,13 @@ export const EmbedModel = z.object({ }) export interface CompleteEmbed extends z.infer { - footer?: CompleteEmbedFooter | null - fields: CompleteEmbedField[] + DM?: CompleteDM | null + leaver?: CompleteLeaver | null + welcomer?: CompleteWelcomer | null author?: CompleteEmbedAuthor | null + fields?: CompleteEmbedField | null + footer?: CompleteEmbedFooter | null image?: CompleteEmbedImage | null - welcomer?: CompleteWelcomer | null - leaver?: CompleteLeaver | null - DM?: CompleteDM | null } /** @@ -33,11 +33,11 @@ export interface CompleteEmbed extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedEmbedModel: z.ZodSchema = z.lazy(() => EmbedModel.extend({ - footer: RelatedEmbedFooterModel.nullish(), - fields: RelatedEmbedFieldModel.array(), + DM: RelatedDMModel.nullish(), + leaver: RelatedLeaverModel.nullish(), + welcomer: RelatedWelcomerModel.nullish(), author: RelatedEmbedAuthorModel.nullish(), + fields: RelatedEmbedFieldModel.nullish(), + footer: RelatedEmbedFooterModel.nullish(), image: RelatedEmbedImageModel.nullish(), - welcomer: RelatedWelcomerModel.nullish(), - leaver: RelatedLeaverModel.nullish(), - DM: RelatedDMModel.nullish(), })) diff --git a/prisma/schema/embedauthor.ts b/prisma/schema/embedauthor.ts index e658c3c..d276763 100644 --- a/prisma/schema/embedauthor.ts +++ b/prisma/schema/embedauthor.ts @@ -21,5 +21,5 @@ export interface CompleteEmbedAuthor extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedEmbedAuthorModel: z.ZodSchema = z.lazy(() => EmbedAuthorModel.extend({ - embed: RelatedEmbedModel.optional().nullish(), + embed: RelatedEmbedModel.nullish(), })) diff --git a/prisma/schema/embedfield.ts b/prisma/schema/embedfield.ts index 1b5576e..524a814 100644 --- a/prisma/schema/embedfield.ts +++ b/prisma/schema/embedfield.ts @@ -21,5 +21,5 @@ export interface CompleteEmbedField extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedEmbedFieldModel: z.ZodSchema = z.lazy(() => EmbedFieldModel.extend({ - embed: RelatedEmbedModel.optional().nullish(), + embed: RelatedEmbedModel.nullish(), })) diff --git a/prisma/schema/embedfooter.ts b/prisma/schema/embedfooter.ts index b1b2454..a783f48 100644 --- a/prisma/schema/embedfooter.ts +++ b/prisma/schema/embedfooter.ts @@ -20,5 +20,5 @@ export interface CompleteEmbedFooter extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedEmbedFooterModel: z.ZodSchema = z.lazy(() => EmbedFooterModel.extend({ - embed: RelatedEmbedModel.optional().nullish(), + embed: RelatedEmbedModel.nullish(), })) diff --git a/prisma/schema/guild.ts b/prisma/schema/guild.ts index 74f5226..3143b02 100644 --- a/prisma/schema/guild.ts +++ b/prisma/schema/guild.ts @@ -1,5 +1,5 @@ import * as z from "zod" -import { CompleteWelcomer, RelatedWelcomerModel, CompleteLeaver, RelatedLeaverModel } from "./index" +import { CompleteLeaver, RelatedLeaverModel, CompleteWelcomer, RelatedWelcomerModel } from "./index" export const GuildModel = z.object({ id: z.string(), @@ -8,8 +8,8 @@ export const GuildModel = z.object({ }) export interface CompleteGuild extends z.infer { - welcomer?: CompleteWelcomer | null leaver?: CompleteLeaver | null + welcomer?: CompleteWelcomer | null } /** @@ -18,6 +18,6 @@ export interface CompleteGuild extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedGuildModel: z.ZodSchema = z.lazy(() => GuildModel.extend({ - welcomer: RelatedWelcomerModel.nullish(), leaver: RelatedLeaverModel.nullish(), + welcomer: RelatedWelcomerModel.nullish(), })) diff --git a/prisma/schema/leaver.ts b/prisma/schema/leaver.ts index 714ad8d..724af37 100644 --- a/prisma/schema/leaver.ts +++ b/prisma/schema/leaver.ts @@ -1,18 +1,18 @@ import * as z from "zod" -import { CompleteGuild, RelatedGuildModel, CompleteEmbed, RelatedEmbedModel } from "./index" +import { CompleteEmbed, RelatedEmbedModel, CompleteGuild, RelatedGuildModel } from "./index" export const LeaverModel = z.object({ id: z.number().int().optional(), guildId: z.string(), - channelId: z.string(), - content: z.string(), + channelId: z.string().nullish(), + content: z.string().nullish(), createdAt: z.date().nullish(), updatedAt: z.date().nullish(), }) export interface CompleteLeaver extends z.infer { - guild?: CompleteGuild | null embeds: CompleteEmbed[] + guild: CompleteGuild } /** @@ -21,6 +21,6 @@ export interface CompleteLeaver extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedLeaverModel: z.ZodSchema = z.lazy(() => LeaverModel.extend({ - guild: RelatedGuildModel.nullish(), embeds: RelatedEmbedModel.array(), + guild: RelatedGuildModel, })) diff --git a/prisma/schema/welcomer.ts b/prisma/schema/welcomer.ts index ec4055a..467f6f7 100644 --- a/prisma/schema/welcomer.ts +++ b/prisma/schema/welcomer.ts @@ -1,19 +1,19 @@ import * as z from "zod" -import { CompleteGuild, RelatedGuildModel, CompleteEmbed, RelatedEmbedModel, CompleteDM, RelatedDMModel } from "./index" +import { CompleteDM, RelatedDMModel, CompleteEmbed, RelatedEmbedModel, CompleteGuild, RelatedGuildModel } from "./index" export const WelcomerModel = z.object({ id: z.number().int().optional(), guildId: z.string(), - channelId: z.string(), - content: z.string(), + channelId: z.string().nullish(), + content: z.string().nullish(), createdAt: z.date().nullish(), updatedAt: z.date().nullish(), }) export interface CompleteWelcomer extends z.infer { - guild?: CompleteGuild | null - embeds: CompleteEmbed[] DM?: CompleteDM | null + embeds: CompleteEmbed[] + guild: CompleteGuild } /** @@ -22,7 +22,7 @@ export interface CompleteWelcomer extends z.infer { * NOTE: Lazy required in case of potential circular dependencies within schema */ export const RelatedWelcomerModel: z.ZodSchema = z.lazy(() => WelcomerModel.extend({ - guild: RelatedGuildModel.nullish(), - embeds: RelatedEmbedModel.array().max(10), DM: RelatedDMModel.nullish(), + embeds: RelatedEmbedModel.array(), + guild: RelatedGuildModel, })) diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index caa74d8..28409f5 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -3,40 +3,43 @@ import WelcomerClient from "../../structure/WelcomerClient"; import { EventType } from "../../types"; import { waitForManager } from "../../utils/functions"; - export default class ReadyEvent implements EventType { - name = "ready"; - once = true; - async execute(client: WelcomerClient) { - console.log(`${client.user?.username} is ready (Cluster: ${client.cluster.id})!`) - await setStatus(); - setInterval(async () => { - await setStatus(); - }, 120000); - - async function setStatus() { - const messages = [ - `/config`, - `welcomer.app`, - `${(await client.cluster.broadcastEval(`this.guilds.cache.size`)).reduce((prev, val) => prev + val, 0)} guilds`, - ]; - - const message = messages[Math.floor(Math.random() * messages.length)]!; - client.user?.setActivity(message, { type: ActivityType.Watching }); - } - if (client.cluster.id === 0) { - await waitForManager(client); - for (const command of client.commands.values()) { - if (command.type !== ApplicationCommandType.ChatInput) continue; - command.contexts = [0]; - command.dmPermission = false; - } - await client.application?.commands.set([...client.commands.values()]).then(async (commandsData) => { - console.log("Commands registered!"); - // console.log(commandsData); - }) - } + name = "ready"; + once = true; + async execute(client: WelcomerClient) { + console.log( + `${client.user?.username} is ready (Cluster: ${client.cluster.id})!` + ); + await setStatus(); + setInterval(async () => { + await setStatus(); + }, 120000); + async function setStatus() { + const messages = [ + `/config`, + `welcomer.app`, + `${( + await client.cluster.broadcastEval(`this.guilds.cache.size`) + ).reduce((prev, val) => prev + val, 0)} guilds`, + ]; - }; -} \ No newline at end of file + const message = messages[Math.floor(Math.random() * messages.length)]!; + client.user?.setActivity(message, { type: ActivityType.Watching }); + } + if (client.cluster.id === 0) { + await waitForManager(client); + for (const command of client.commands.values()) { + if (command.type !== ApplicationCommandType.ChatInput) continue; + command.contexts = [0]; + command.dmPermission = false; + } + await client.application?.commands + .set([...client.commands.values()]) + .then(() => { + console.log("Commands registered!"); + // console.log(commandsData); + }); + } + } +} diff --git a/src/selectMenus/testMenu.ts b/src/selectMenus/testMenu.ts index b798d70..f02b863 100644 --- a/src/selectMenus/testMenu.ts +++ b/src/selectMenus/testMenu.ts @@ -46,7 +46,10 @@ export default class TestMenu implements SelectMenuType { if (!guildModule) return sendInteractionMessage( interaction, - { content: `No ${arg} module found. Please enable it first with the [dashboard]()`, ephemeral: true }, + { + content: `No ${arg} module found. Please enable it first with the [dashboard]()`, + ephemeral: true, + }, true ); const realChannelId = guildModule.channelId; @@ -55,32 +58,36 @@ export default class TestMenu implements SelectMenuType { const realChannelPermissionErrors: string[] = []; const realChannel = interaction.guild!.channels.cache.get(realChannelId); - const currentChannel = interaction.channel; + let currentChannel = interaction.channel; + + if (!realChannel) { + InfoEmbed.setColor("#ff0000").setDescription( + `Channel is not set, please set it with the [dashboard]()` + ); + return sendInteractionMessage( + interaction, + { embeds: [InfoEmbed], ephemeral: true }, + true + ); + } InfoEmbed.setColor("#33cc33") .setDescription( `This is a test function, test message will be sent in this channel, if ${value.toLowerCase()} module is not enabled, nothing will be sent.` ) - .addFields( - { - name: "``Enabled``", - value: guildModule - ? "**:white_check_mark: enabled**" - : "** disabled**", - }, - { - name: "<:channel:1011932902637977650> ``Channel:``", - value: guildModule.channelId - ? `<#${guildModule.channelId}>` - : "**NOT SET (No messages will be sent)**", - } - ); + .addFields({ + name: "<:channel:1011932902637977650> ``Channel:``", + value: "<#" + guildModule.channelId + ">", + }); const permissionNames = { [PermissionsBitField.Flags.SendMessages.toString()]: "Send Messages", [PermissionsBitField.Flags.EmbedLinks.toString()]: "Embed Links", [PermissionsBitField.Flags.AttachFiles.toString()]: "Attach Files", }; + if (currentChannel === realChannel) { + currentChannel = null; + } for (const channel of [currentChannel, realChannel]) { if (!channel) continue; @@ -127,6 +134,11 @@ export default class TestMenu implements SelectMenuType { }); } + sendInteractionMessage( + interaction, + { embeds: [InfoEmbed], ephemeral: true }, + true + ); switch (arg) { case "welcomer": welcomeCard( @@ -152,10 +164,5 @@ export default class TestMenu implements SelectMenuType { } catch (error) { console.log(error); } - sendInteractionMessage( - interaction, - { embeds: [InfoEmbed], ephemeral: true }, - true - ); } } diff --git a/src/utils/messages.ts b/src/utils/messages.ts index c1d9d28..713db0f 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -1,74 +1,126 @@ -import { ActionRowBuilder, AutocompleteInteraction, BaseMessageOptions, ButtonBuilder, GuildMember, GuildTextBasedChannel, Interaction, InteractionReplyOptions, InteractionResponse, Message, MessageCreateOptions } from "discord.js"; +import { + ActionRowBuilder, + AutocompleteInteraction, + BaseMessageOptions, + ButtonBuilder, + GuildMember, + GuildTextBasedChannel, + Interaction, + InteractionReplyOptions, + InteractionResponse, + Message, + MessageCreateOptions, +} from "discord.js"; import WelcomerClient from "../structure/WelcomerClient"; import { helpButton } from "./buttons"; const baseMessage: BaseMessageOptions = { - content: "", - embeds: [], - components: [], - files: [], -} + content: "", + embeds: [], + components: [], + files: [], +}; -export const sendInteractionMessage = async (interaction: Exclude, message: InteractionReplyOptions = baseMessage, follow: boolean = false): Promise | InteractionResponse> => { - if (!interaction || !message) throw new Error("Missing parameters for sendInteractionMessage") - try { - if (follow) { - return await interaction.followUp({ ...message, fetchReply: true }); - } else if (interaction.deferred || interaction.replied) { - return await interaction.editReply(message); - } else { - return await interaction.reply(message); - } - } catch (error) { - throw new Error("An error occured in sendInteractionMessage function ! " + error) +export const sendInteractionMessage = async ( + interaction: Exclude, + message: InteractionReplyOptions = baseMessage, + follow: boolean = false +): Promise | InteractionResponse> => { + if (!interaction || !message) + throw new Error("Missing parameters for sendInteractionMessage"); + try { + if (follow) { + return await interaction.followUp({ ...message, fetchReply: true }); + } else if (interaction.deferred || interaction.replied) { + return await interaction.editReply(message); + } else { + return await interaction.reply(message); } + } catch (error) { + throw new Error( + "An error occured in sendInteractionMessage function ! " + error + ); + } +}; -} +export const sendDmMessage = async ( + client: WelcomerClient, + user: GuildMember, + message: MessageCreateOptions = baseMessage +) => { + try { + if ( + !message.content && + message.embeds.length === 0 && + message.files.length === 0 + ) + return; + const fetchedUser = await client.users.fetch(user); + return await fetchedUser.send(message); + } catch (error) { + return error; + } +}; -export const sendDmMessage = async (client: WelcomerClient, user: GuildMember, message: MessageCreateOptions = baseMessage) => { - try { - const fetchedUser = await client.users.fetch(user) - return await fetchedUser.send(message); - } catch (error) { - return error; - } -} +export const sendChannelMessage = async ( + channel: GuildTextBasedChannel, + message: MessageCreateOptions = baseMessage +) => { + try { + if ( + !message.content && + message.embeds.length === 0 && + message.files.length === 0 + ) + return; -export const sendChannelMessage = async (channel: GuildTextBasedChannel, message: MessageCreateOptions = baseMessage) => { - try { - return await channel.send(message); - } catch (error) { - console.log("An error occured in sendChannelMessage function !", error) - return error; - } -} + return await channel.send(message); + } catch (error) { + console.log("An error occured in sendChannelMessage function !", error); + return error; + } +}; -export const sendErrorMessage = async (interaction: Exclude, error: string) => { - try { - (await interaction.fetchReply()).removeAttachments(); - await sendInteractionMessage( - interaction, - { - content: error, - ephemeral: true, - embeds: [], - components: [new ActionRowBuilder().addComponents(helpButton)], - files: [], - }, - true - ); - } catch { - return; - } -} +export const sendErrorMessage = async ( + interaction: Exclude, + error: string +) => { + try { + (await interaction.fetchReply()).removeAttachments(); + await sendInteractionMessage( + interaction, + { + content: error, + ephemeral: true, + embeds: [], + components: [ + new ActionRowBuilder().addComponents(helpButton), + ], + files: [], + }, + true + ); + } catch { + return; + } +}; -export const sendTempMessage = async (interaction: Exclude, message: InteractionReplyOptions = baseMessage, follow: boolean=false, time: number = 5000) => { - try { - const sentMessage = await sendInteractionMessage(interaction, message, follow); - setTimeout(async () => { - sentMessage.delete(); - }, time); - } catch (error) { - throw(`An error occured in sendTempMessage function: ${error}`) - } -} \ No newline at end of file +export const sendTempMessage = async ( + interaction: Exclude, + message: InteractionReplyOptions = baseMessage, + follow: boolean = false, + time: number = 5000 +) => { + try { + const sentMessage = await sendInteractionMessage( + interaction, + message, + follow + ); + setTimeout(async () => { + sentMessage.delete(); + }, time); + } catch (error) { + throw `An error occured in sendTempMessage function: ${error}`; + } +};