started to add bye messages

This commit is contained in:
Lukian LEIZOUR 2024-12-26 14:33:18 +01:00
parent 294af9c6af
commit f37f0d492a
9 changed files with 300 additions and 92 deletions

View file

@ -0,0 +1,72 @@
import { SlashCommandBuilder, CommandInteraction, PermissionFlagsBits, EmbedBuilder, AttachmentBuilder } from "npm:discord.js";
import { connectToDb, getGuild, getByeConfig } from "../../libs/mysql.ts";
import { errorEmbed } from "../../libs/discord.ts";
import { createWelcomeImage } from "../../libs/imageGeneration.ts"
export default {
data: new SlashCommandBuilder()
.setName("byeexample")
.setDescription("Send an example of the goodbye message of the server."),
async execute(interaction: CommandInteraction) {
await interaction.deferReply()
const connection = await connectToDb();
const guild_id = interaction.guild?.id ? interaction.guild?.id : ""
const guild = await getGuild(connection, guild_id)
if (!guild[0]) {
const embed = errorEmbed("Your server must be registered to the bot, use /register to do so.", interaction.client.user.displayAvatarURL());
return interaction.editReply({embeds: [embed]});
}
const member = interaction.guild?.members.cache.get(interaction.user.id)
if (!member?.permissions.has(PermissionFlagsBits.Administrator) && !member?.roles.cache.has(guild[0].admin_role_id)) {
const embed = errorEmbed("You are not allowed to use that command.", interaction.client.user.displayAvatarURL());
return await interaction.editReply({embeds: [embed]});
}
const config = await getByeConfig(connection, guild_id).catch(error => {
console.error(error)
});
connection.end();
if (!config[0]) {
const embed = errorEmbed("Your welcome message must be setup before using that command.", interaction.client.user.displayAvatarURL());
return interaction.editReply({embeds: [embed]});
}
const embed = new EmbedBuilder();
if (config[0].title) {
embed.setTitle(config[0].title);
}
if (config[0].description_format) {
embed.setDescription(config[0].description_format.replace("{user}", `<@${interaction.user.id}>`).replace("{role}", `<@&${config[0].role_id ? config[0].role_id : ""}>`));
}
if (config[0].vignette_url) {
embed.setThumbnail(config[0].vignette_url);
}
var files = [];
if (config[0].background_url) {
const buffer = await createWelcomeImage(config[0].background_url, `https://cdn.discordapp.com/avatars/${interaction.user.id}/${interaction.user.avatar}.jpeg`, interaction.user.id);
if (buffer) {
const attachement = new AttachmentBuilder(buffer, { name: `${interaction.user.id}.png` })
files.push(attachement)
embed.setImage(`attachment://${interaction.user.id}.png`)
}
}
interaction.editReply({content: config[0].message_format ? config[0].message_format.replace("{user}", `<@${interaction.user.id}>`).replace("{role}", `<@&${config[0].role_id ? config[0].role_id : ""}>`) : "", embeds: [embed], files: files});
},
};