From 7d252983773b51190eb2f33b705c8b1392eb4fdb Mon Sep 17 00:00:00 2001 From: ninjdai1 Date: Fri, 11 Nov 2022 21:05:55 +0100 Subject: [PATCH] Added emoji registering for artists Using /setemoji, staff can define an emoji for artists, that will automatically be added to the start of a ticket when taken. --- commands/misc/setemoji.js | 35 +++++++++++++++++++++++ index.js | 7 +++++ interactions/buttons/src/ticket/ticket.js | 5 ++-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 commands/misc/setemoji.js diff --git a/commands/misc/setemoji.js b/commands/misc/setemoji.js new file mode 100644 index 0000000..1babff0 --- /dev/null +++ b/commands/misc/setemoji.js @@ -0,0 +1,35 @@ +const { SlashCommandBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('setemoji') + .setDescription('Définir l\'émoji de l\'artiste ciblé.e') + .setDefaultMemberPermissions(0x4) + .addStringOption(option => + option.setName('emoji') + .setDescription('Émoji') + .setRequired(true)) + .addUserOption(option => + option.setName('artist') + .setDescription('Artiste à qui ajouter l\'émoji !') + .setRequired(true)), + async execute(interaction, client) { + const emoji = interaction.options.getString('emoji'); + const member = interaction.options.getMember('artist'); + + const userAlreadyPresent = await client.database.artists.findOne({ where: { name: member.id } }); + const emojiAlreadyPresent = await client.database.artists.findOne({ where: { emoji: emoji } }); + if(emojiAlreadyPresent) return interaction.reply({ content: `Émoji ${emoji} déjà utilisé ! (Par <@${emojiAlreadyPresent.name}>)`, ephemeral: true }); + + if(userAlreadyPresent){ + await client.database.artists.update({ emoji: emoji }, {where: { name: member.id }}); + await interaction.reply({ content: `Émoji de <@${member.id}> modifié en ${emoji} !`, ephemeral: true }); + } else { + await client.database.artists.create({ + name: member.id, + emoji: emoji, + }); + await interaction.reply({ content: `Émoji de <@${member.id}> défini sur ${emoji} !`, ephemeral: true }); + } + }, +}; \ No newline at end of file diff --git a/index.js b/index.js index d76ceab..8d2c9ab 100644 --- a/index.js +++ b/index.js @@ -39,13 +39,20 @@ const modlog = sequelize.define('sanctions', { moderatorid: Sequelize.STRING }); +const artists = sequelize.define('artists', { + name: Sequelize.STRING,//id + emoji: Sequelize.STRING, +}); + client.database = { sequelize: sequelize, modlog: modlog, blacklistdb: blacklistdb, + artists: artists, }; blacklistdb.sync(); modlog.sync(); +artists.sync(); const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js')); for (const file of eventFiles) { diff --git a/interactions/buttons/src/ticket/ticket.js b/interactions/buttons/src/ticket/ticket.js index 0e8b165..45eb5fc 100644 --- a/interactions/buttons/src/ticket/ticket.js +++ b/interactions/buttons/src/ticket/ticket.js @@ -1,7 +1,7 @@ const { PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder } = require('discord.js') module.exports = { - async execute(interaction) { + async execute(interaction, client) { await interaction.deferUpdate({ ephemeral: true }); switch (interaction.customId.replace("ticket_","").split("-")[0]) { case 'close': @@ -141,7 +141,8 @@ module.exports = { .setEmoji("🔒") .setCustomId(`ticket_close-${interaction.customId.replace("ticket_","").split("-")[1]}`), ]); - await interaction.channel.setName("🟢"+interaction.channel.name); + const artist = await client.database.artists.findOne({ where: { name: interaction.user.id } }); + await interaction.channel.setName((artist ? artist.emoji :"🟢")+interaction.channel.name); await interaction.followUp({ embeds: [ new EmbedBuilder() .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.avatarURL() })