From aec6ec7c58f45e126aa8dce5eada21c28ec8b47f Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Mon, 15 Jan 2024 23:19:59 +0500 Subject: [PATCH] v4.4.1 - https://blog.jababot.ru --- commands/Administration/config.js | 74 ++++++++++++++++++++++--------- commands/General/help.js | 2 +- commands/Music/clips.js | 2 +- commands/Music/play.js | 9 +++- commands/Music/volume.js | 2 +- commands/Owner/reload.js | 2 +- helpers/birthdays.js | 53 ++++++++++++++++++++++ package.json | 2 +- 8 files changed, 118 insertions(+), 28 deletions(-) diff --git a/commands/Administration/config.js b/commands/Administration/config.js index 6cf1bf9f..45a99696 100644 --- a/commands/Administration/config.js +++ b/commands/Administration/config.js @@ -198,38 +198,70 @@ class Config extends BaseCommand { async function changeSetting(interaction, setting, state, channel, guildData) { const settingSplitted = setting.split("."); - if (settingSplitted.length === 2 && guildData.plugins[settingSplitted[0]] === undefined) guildData.plugins[settingSplitted[0]] = {}; + if (settingSplitted.length === 2) { + if (guildData.plugins[settingSplitted[0]] === undefined) guildData.plugins[settingSplitted[0]] = {}; - if (!state) { - guildData.plugins[settingSplitted[0]][settingSplitted[1]] = null; - - guildData.markModified(`plugins.${settingSplitted[0]}`); - await guildData.save(); - - return interaction.reply({ - content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: **${interaction.translate("common:DISABLED")}**`, - ephemeral: true, - }); - } else { - if (settingSplitted[1] === "ticketsCategory" && channel.type !== ChannelType.GuildCategory) return interaction.reply({ content: interaction.translate("administration/config:TICKETS_NOT_CATEGORY"), ephemeral: true }); - - if (channel) { - guildData.plugins[settingSplitted[0]][settingSplitted[1]] = channel.id; + if (!state) { + guildData.plugins[settingSplitted[0]][settingSplitted[1]] = null; guildData.markModified(`plugins.${settingSplitted[0]}`); await guildData.save(); return interaction.reply({ - content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: **${interaction.translate("common:ENABLED")}** (${channel.toString()})`, + content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: **${interaction.translate("common:DISABLED")}**`, ephemeral: true, }); - } else + } else { + if (settingSplitted[1] === "ticketsCategory" && channel.type !== ChannelType.GuildCategory) return interaction.reply({ content: interaction.translate("administration/config:TICKETS_NOT_CATEGORY"), ephemeral: true }); + + if (channel) { + guildData.plugins[settingSplitted[0]][settingSplitted[1]] = channel.id; + + guildData.markModified(`plugins.${settingSplitted[0]}`); + await guildData.save(); + + return interaction.reply({ + content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: **${interaction.translate("common:ENABLED")}** (${channel.toString()})`, + ephemeral: true, + }); + } else + return interaction.reply({ + content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: ${ + guildData.plugins[setting] ? `**${interaction.translate("common:ENABLED")}** (<#${guildData.plugins[setting]}>)` : `**${interaction.translate("common:DISABLED")}**` + }`, + ephemeral: true, + }); + } + } else { + if (!state) { + guildData.plugins[setting] = null; + + guildData.markModified(`plugins.${setting}`); + await guildData.save(); + return interaction.reply({ - content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: ${ - guildData.plugins[setting] ? `**${interaction.translate("common:ENABLED")}** (<#${guildData.plugins[setting]}>)` : `**${interaction.translate("common:DISABLED")}**` - }`, + content: `${interaction.translate(`administration/config:${setting.toUpperCase()}`)}: **${interaction.translate("common:DISABLED")}**`, ephemeral: true, }); + } else { + if (channel) { + guildData.plugins[setting] = channel.id; + + guildData.markModified(`plugins.${setting}`); + await guildData.save(); + + return interaction.reply({ + content: `${interaction.translate(`administration/config:${setting.toUpperCase()}`)}: **${interaction.translate("common:ENABLED")}** (${channel.toString()})`, + ephemeral: true, + }); + } else + return interaction.reply({ + content: `${interaction.translate(`administration/config:${setting.toUpperCase()}`)}: ${ + guildData.plugins[setting] ? `**${interaction.translate("common:ENABLED")}** (<#${guildData.plugins[setting]}>)` : `**${interaction.translate("common:DISABLED")}**` + }`, + ephemeral: true, + }); + } } } diff --git a/commands/General/help.js b/commands/General/help.js index 05124150..e73e264d 100644 --- a/commands/General/help.js +++ b/commands/General/help.js @@ -127,7 +127,7 @@ class Help extends BaseCommand { commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()], results = commands.filter(c => c.command.name.includes(command)); - return interaction.respond( + return await interaction.respond( results.slice(0, 25).map(command => ({ name: command.command.name, value: command.command.name, diff --git a/commands/Music/clips.js b/commands/Music/clips.js index 971e6ae2..2aeb0ef6 100644 --- a/commands/Music/clips.js +++ b/commands/Music/clips.js @@ -90,7 +90,7 @@ class Clips extends BaseCommand { files = fs.readdirSync("./clips"), results = files.filter(f => f.includes(query)); - return interaction.respond( + return await interaction.respond( results.slice(0, 25).map(file => ({ name: file.substring(0, file.length - 4), value: `./clips/${file}`, diff --git a/commands/Music/play.js b/commands/Music/play.js index 57a4eab0..f80c3a0a 100644 --- a/commands/Music/play.js +++ b/commands/Music/play.js @@ -110,12 +110,17 @@ class Play extends BaseCommand { const results = await client.player.search(query); - return interaction.respond( + return results.tracks.length > 0 ? await interaction.respond( results.tracks.slice(0, 10).map(track => ({ name: (`${track.author} - ${track.title}`.length >= 100) & (`${track.author} - ${track.title}`.slice(0, 80) + "...") || `${track.author} - ${track.title}`, value: track.url, })), - ); + ) : await interaction.respond([ + { + name: "Nothing", + value: "Nothing", + }, + ]); } } diff --git a/commands/Music/volume.js b/commands/Music/volume.js index 80e8b2d1..45e4f75c 100644 --- a/commands/Music/volume.js +++ b/commands/Music/volume.js @@ -71,7 +71,7 @@ class Volume extends BaseCommand { const int = interaction.options.getInteger("int"), results = Array.from({ length: 100 }, (_, k) => k + 1).filter(i => i.toString().includes(int)); - return interaction.respond( + return await interaction.respond( results.slice(0, 25).map(i => ({ name: i, value: i, diff --git a/commands/Owner/reload.js b/commands/Owner/reload.js index 6db21d1d..7de5ed55 100644 --- a/commands/Owner/reload.js +++ b/commands/Owner/reload.js @@ -73,7 +73,7 @@ class Reload extends BaseCommand { const command = interaction.options.getString("command"), results = client.commands.filter(c => c.command.name.includes(command)); - return interaction.respond( + return await interaction.respond( results .map(c => c) .slice(0, 25) diff --git a/helpers/birthdays.js b/helpers/birthdays.js index 6ccb5e6c..33354de0 100644 --- a/helpers/birthdays.js +++ b/helpers/birthdays.js @@ -64,3 +64,56 @@ module.exports.init = async function (client) { cronjob.start(); }; + +module.exports.run = async function (client) { + client.guilds.cache.forEach(async guild => { + const guildData = await client.findOrCreateGuild(guild.id); + + if (guildData.plugins.birthdays) { + const channel = guild.channels.cache.get(guildData.plugins.birthdays) || await guild.channels.fetch(guildData.plugins.birthdays), + date = new Date(), + currentDay = date.getDate(), + currentMonth = date.getMonth(), + currentYear = date.getFullYear(); + + if (channel) { + client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => { + for (const user of users) { + if (!guild.members.cache.find(m => m.id === user.id)) return; + + const userDate = new Date(user.birthdate), + day = userDate.getDate(), + month = userDate.getMonth(), + year = userDate.getFullYear(), + age = currentYear - year; + + if (currentMonth === month && currentDay === day) { + const embed = new EmbedBuilder() + .setAuthor({ + name: client.user.getUsername(), + iconURL: client.user.displayAvatarURL(), + }) + .setColor(client.config.embed.color) + .setFooter(client.config.embed.footer) + .addFields([ + { + name: client.translate("economy/birthdate:HAPPY_BIRTHDAY", null, guildData.language), + value: client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", { + name: user.username, + user: user.id, + age: `**${age}** ${client.functions.getNoun(age, client.translate("misc:NOUNS:AGE:1", null, guildData.language), client.translate("misc:NOUNS:AGE:2", null, guildData.language), client.translate("misc:NOUNS:AGE:5", null, guildData.language))}`, + }, guildData.language), + }, + ]); + + const msg = await channel.send({ + embeds: [embed], + }); + await msg.react("🎉"); + } + } + }); + } + } + }); +}; diff --git a/package.json b/package.json index 0ff9f9b1..ab43c765 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jaba", - "version": "4.4.0", + "version": "4.4.1", "description": "My Discord Bot", "main": "index.js", "scripts": {