From 76ab9c38a0dd06b77fd14cbba1433c8e006cdd0e Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Mon, 3 Oct 2022 20:21:42 +0500 Subject: [PATCH] 4.1.9 - https://github.com/JonnyBro/JaBa-logs --- base/JaBa.js | 34 +++++++++++++++---------------- commands/Administration/set.js | 8 +++++--- commands/Economy/money.js | 6 +++--- commands/Economy/number.js | 2 +- commands/Economy/pay.js | 2 +- commands/Economy/profile.js | 4 ++-- commands/Economy/rob.js | 2 +- commands/Economy/tictactoe.js | 2 +- commands/Moderation/clearwarns.js | 2 +- commands/Moderation/warn.js | 2 +- commands/Moderation/warns.js | 2 +- commands/Owner/debug.js | 12 ++++++----- dashboard/public/docs/updates.md | 7 +++++++ dashboard/routes/guild-manager.js | 2 +- dashboard/routes/guild-stats.js | 2 +- events/CommandHandler.js | 2 +- events/Guild/guildMemberAdd.js | 2 +- events/MessageHandler.js | 29 ++++++++++++++++++-------- events/ready.js | 7 ------- helpers/cleanup.js | 6 +++--- helpers/extenders.js | 33 +++--------------------------- languages/ru-RU/misc.json | 1 + package.json | 2 +- 23 files changed, 81 insertions(+), 90 deletions(-) diff --git a/base/JaBa.js b/base/JaBa.js index ef635a6d..e6b0b62a 100644 --- a/base/JaBa.js +++ b/base/JaBa.js @@ -111,7 +111,7 @@ class JaBa extends Client { /** * Load commands from directory - * @param {String} dir Directory where's all commands/subdirectories located + * @param {String} dir Directory where's all commands located * @returns */ async loadCommands(dir) { @@ -211,7 +211,7 @@ class JaBa extends Client { /** * Load events from directory - * @param {String} dir Directory where's all events/subdirectories located + * @param {String} dir Directory where's all events located * @returns */ async loadEvents(dir) { @@ -340,34 +340,34 @@ class JaBa extends Client { * @param {Boolean} isLean Return JSON instead Mongoose model? * @returns {import("./Member")} Mongoose model or JSON of this member */ - async findOrCreateMember({ id: memberID, guildID }, isLean) { - if (this.databaseCache.members.get(`${memberID}${guildID}`)) return isLean ? this.databaseCache.members.get(`${memberID}${guildID}`).toJSON() : this.databaseCache.members.get(`${memberID}${guildID}`); + async findOrCreateMember({ id: memberID, guildId }, isLean) { + if (this.databaseCache.members.get(`${memberID}${guildId}`)) return isLean ? this.databaseCache.members.get(`${memberID}${guildId}`).toJSON() : this.databaseCache.members.get(`${memberID}${guildId}`); else { let memberData = (isLean ? await this.membersData.findOne({ - guildID, + guildID: guildId, id: memberID }).lean() : await this.membersData.findOne({ - guildID, + guildID: guildId, id: memberID })); if (memberData) { - if (!isLean) this.databaseCache.members.set(`${memberID}${guildID}`, memberData); + if (!isLean) this.databaseCache.members.set(`${memberID}${guildId}`, memberData); return memberData; } else { memberData = new this.membersData({ id: memberID, - guildID: guildID + guildID: guildId }); await memberData.save(); const guild = await this.findOrCreateGuild({ - id: guildID + id: guildId }); if (guild) { guild.members.push(memberData._id); await guild.save(); } - this.databaseCache.members.set(`${memberID}${guildID}`, memberData); + this.databaseCache.members.set(`${memberID}${guildId}`, memberData); return isLean ? memberData.toJSON() : memberData; } @@ -380,24 +380,24 @@ class JaBa extends Client { * @param {Boolean} isLean Return JSON instead Mongoose model? * @returns {import("./Guild")} Mongoose model or JSON of this guild */ - async findOrCreateGuild({ id: guildID }, isLean) { - if (this.databaseCache.guilds.get(guildID)) return isLean ? this.databaseCache.guilds.get(guildID).toJSON() : this.databaseCache.guilds.get(guildID); + async findOrCreateGuild({ id: guildId }, isLean) { + if (this.databaseCache.guilds.get(guildId)) return isLean ? this.databaseCache.guilds.get(guildId).toJSON() : this.databaseCache.guilds.get(guildId); else { let guildData = (isLean ? await this.guildsData.findOne({ - id: guildID + id: guildId }).populate("members").lean() : await this.guildsData.findOne({ - id: guildID + id: guildId }).populate("members")); if (guildData) { - if (!isLean) this.databaseCache.guilds.set(guildID, guildData); + if (!isLean) this.databaseCache.guilds.set(guildId, guildData); return guildData; } else { guildData = new this.guildsData({ - id: guildID + id: guildId }); await guildData.save(); - this.databaseCache.guilds.set(guildID, guildData); + this.databaseCache.guilds.set(guildId, guildData); return isLean ? guildData.toJSON() : guildData; } diff --git a/commands/Administration/set.js b/commands/Administration/set.js index 6b60cd6b..79073313 100644 --- a/commands/Administration/set.js +++ b/commands/Administration/set.js @@ -46,12 +46,14 @@ class Set extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Object} data */ - async execute(client, interaction) { + async execute(client, interaction, data) { const type = interaction.options.getString("type"); const member = interaction.options.getMember("user"); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); - const memberData = await client.findOrCreateMember({ - id: member.id + + const memberData = member.id === interaction.user.id ? data : await client.findOrCreateMember({ + id: member.id, + guildId: interaction.guildId }); const int = interaction.options.getInteger("int"); if (int < 0) return interaction.error("administration/set:INVALID_NUMBER", null, { ephemeral: true }); diff --git a/commands/Economy/money.js b/commands/Economy/money.js index de97d0d0..5d165343 100644 --- a/commands/Economy/money.js +++ b/commands/Economy/money.js @@ -45,9 +45,9 @@ class Money extends BaseCommand { const member = interaction.options.getMember("user") || interaction.member; if (member.user.bot) return interaction.error("economy/money:BOT_USER"); - const memberData = (member.id === interaction.user.id) ? data.memberData : await client.findOrCreateMember({ + const memberData = member.id === interaction.user.id ? data.memberData : await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id)); @@ -55,7 +55,7 @@ class Money extends BaseCommand { await asyncForEach(guilds, async guild => { const data = await client.findOrCreateMember({ id: member.id, - guildID: guild.id + guildId: guild.id }); globalMoney += data.money + data.bankSold; }); diff --git a/commands/Economy/number.js b/commands/Economy/number.js index d6f8b491..5fef8ec5 100644 --- a/commands/Economy/number.js +++ b/commands/Economy/number.js @@ -79,7 +79,7 @@ class Number extends BaseCommand { const memberData = await client.findOrCreateMember({ id: msg.author.id, - guildID: interaction.guildId + guildId: interaction.guildId }); const info = { diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index a718d4e9..4907b0a4 100644 --- a/commands/Economy/pay.js +++ b/commands/Economy/pay.js @@ -50,7 +50,7 @@ class Pay extends BaseCommand { const memberData = await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); const info = { diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 3dbb9e70..8a81e9b2 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -48,7 +48,7 @@ class Profile extends BaseCommand { const memberData = (member.id === interaction.user.id ? data.memberData : await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId })); const userData = (member.id === interaction.user.id ? data.userData : await client.findOrCreateUser({ id: member.id @@ -60,7 +60,7 @@ class Profile extends BaseCommand { await asyncForEach(guilds, async guild => { const data = await client.findOrCreateMember({ id: member.id, - guildID: guild.id + guildId: guild.id }); globalMoney += data.money + data.bankSold; }); diff --git a/commands/Economy/rob.js b/commands/Economy/rob.js index 2548cddf..187f4265 100644 --- a/commands/Economy/rob.js +++ b/commands/Economy/rob.js @@ -45,7 +45,7 @@ class Rob extends BaseCommand { const memberData = await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); if (amount > memberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: member.toString() }); const isInCooldown = memberData.cooldowns.rob || 0; diff --git a/commands/Economy/tictactoe.js b/commands/Economy/tictactoe.js index 06c9cc52..2ca298cf 100644 --- a/commands/Economy/tictactoe.js +++ b/commands/Economy/tictactoe.js @@ -42,7 +42,7 @@ class TicTacToe extends BaseCommand { }).then(async winner => { const memberData = await client.findOrCreateMember({ id: winner.id, - guildID: interaction.guildId + guildId: interaction.guildId }); const info = { diff --git a/commands/Moderation/clearwarns.js b/commands/Moderation/clearwarns.js index bdde63e3..7817e83e 100644 --- a/commands/Moderation/clearwarns.js +++ b/commands/Moderation/clearwarns.js @@ -38,7 +38,7 @@ class Clearwarns extends BaseCommand { const memberData = await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); memberData.sanctions = []; diff --git a/commands/Moderation/warn.js b/commands/Moderation/warn.js index b4184bad..4bd07df4 100644 --- a/commands/Moderation/warn.js +++ b/commands/Moderation/warn.js @@ -40,7 +40,7 @@ class Warn extends BaseCommand { const memberData = await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); const modal = new ModalBuilder() diff --git a/commands/Moderation/warns.js b/commands/Moderation/warns.js index 19124397..3efb9f99 100644 --- a/commands/Moderation/warns.js +++ b/commands/Moderation/warns.js @@ -39,7 +39,7 @@ class Warns extends BaseCommand { const memberData = await client.findOrCreateMember({ id: member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); const embed = new EmbedBuilder() diff --git a/commands/Owner/debug.js b/commands/Owner/debug.js index 3c1e8883..73052fd5 100644 --- a/commands/Owner/debug.js +++ b/commands/Owner/debug.js @@ -68,7 +68,7 @@ class Debug extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Array} data */ - async execute(client, interaction) { + async execute(client, interaction, data) { const command = interaction.options.getSubcommand(); if (command === "set") { @@ -78,8 +78,9 @@ class Debug extends BaseCommand { const userData = await client.findOrCreateUser({ id: member.id }); - const memberData = await client.findOrCreateMember({ - id: member.id + const memberData = member.id === interaction.user.id ? data : await client.findOrCreateMember({ + id: member.id, + guildId: interaction.guildId }); const int = interaction.options.getInteger("int"); @@ -136,8 +137,9 @@ class Debug extends BaseCommand { const userData = await client.findOrCreateUser({ id: member.id }); - const memberData = await client.findOrCreateMember({ - id: member.id + const memberData = member.id === interaction.user.id ? data : await client.findOrCreateMember({ + id: member.id, + guildId: interaction.guildId }); const int = interaction.options.getInteger("int"); diff --git a/dashboard/public/docs/updates.md b/dashboard/public/docs/updates.md index 0e334445..f42c32d3 100644 --- a/dashboard/public/docs/updates.md +++ b/dashboard/public/docs/updates.md @@ -1,3 +1,10 @@ +### JaBa v4.1.9 +* Изменения + * Переписана система опыта. Теперь при достижении нового уровня опыт сбрасывается и бот оповещает о получении нового уровня. + +* Исправления + * Команды *set* и *debug* ничего не делали. + ### JaBa v4.1.8 * Добавлено * Возможность сразу сократить ссылку в команде *lmgtfy*. diff --git a/dashboard/routes/guild-manager.js b/dashboard/routes/guild-manager.js index f8656c1c..3156b0d2 100644 --- a/dashboard/routes/guild-manager.js +++ b/dashboard/routes/guild-manager.js @@ -17,7 +17,7 @@ router.get("/:serverID", CheckAuth, async(req, res) => { // Fetch guild informations const guildInfos = await utils.fetchGuild(guild.id, req.client, req.user.guilds); - const memberData = await req.client.findOrCreateMember({ id: req.userInfos.id, guildID: guild.id }); + const memberData = await req.client.findOrCreateMember({ id: req.userInfos.id, guildId: guild.id }); res.render("manager/guild", { guild: guildInfos, diff --git a/dashboard/routes/guild-stats.js b/dashboard/routes/guild-stats.js index 19b75b94..f6c7b458 100644 --- a/dashboard/routes/guild-stats.js +++ b/dashboard/routes/guild-stats.js @@ -14,7 +14,7 @@ router.get("/:serverID", CheckAuth, async (req, res) => { }); } - const memberData = await req.client.findOrCreateMember({ id: req.userInfos.id, guildID: guild.id }); + const memberData = await req.client.findOrCreateMember({ id: req.userInfos.id, guildId: guild.id }); // Fetch guild informations const membersData = await req.client.membersData.find({ diff --git a/events/CommandHandler.js b/events/CommandHandler.js index cab24135..3b8eecee 100644 --- a/events/CommandHandler.js +++ b/events/CommandHandler.js @@ -36,7 +36,7 @@ class CommandHandler extends BaseEvent { const memberData = await client.findOrCreateMember({ id: interaction.member.id, - guildID: interaction.guildId + guildId: interaction.guildId }); data.memberData = memberData; } diff --git a/events/Guild/guildMemberAdd.js b/events/Guild/guildMemberAdd.js index 26f2f7e2..10c99121 100644 --- a/events/Guild/guildMemberAdd.js +++ b/events/Guild/guildMemberAdd.js @@ -40,7 +40,7 @@ class GuildMemberAdd extends BaseEvent { const memberData = await client.findOrCreateMember({ id: member.id, - guildID: member.guild.id + guildId: member.guild.id }); if (memberData.mute.muted && memberData.mute.endDate > Date.now()) { member.guild.channels.cache.forEach((channel) => { diff --git a/events/MessageHandler.js b/events/MessageHandler.js index 42b39b43..abc8da7d 100644 --- a/events/MessageHandler.js +++ b/events/MessageHandler.js @@ -33,7 +33,7 @@ class MessageCreate extends BaseEvent { if (message.guild) { const memberData = await client.findOrCreateMember({ id: message.author.id, - guildID: message.guild.id + guildId: message.guild.id }); data.memberData = memberData; } @@ -75,24 +75,37 @@ class MessageCreate extends BaseEvent { } } +/** + * + * @param {import("../base/JaBa")} client + * @param {import("discord.js").Message} msg + * @param {*} data + * @returns + */ async function updateXp(client, msg, data) { - const points = parseInt(data.memberData.exp); - const level = parseInt(data.memberData.level); - const isInCooldown = xpCooldown[msg.author.id]; + const points = parseInt(data.memberData.exp), + level = parseInt(data.memberData.level), + isInCooldown = xpCooldown[msg.author.id]; + if (isInCooldown) { if (isInCooldown > Date.now()) return; } - const toWait = Date.now() + 60000; // 1 min + const toWait = Date.now() + (60 * 1000); // 1 min xpCooldown[msg.author.id] = toWait; - const won = client.functions.randomNum(1, 4); + const won = client.functions.randomNum(1, 2); const newXp = parseInt(points + won, 10); const neededXp = 5 * (level * level) + 80 * level + 100; - if (newXp > neededXp) data.memberData.level = parseInt(level + 1, 10); + if (newXp > neededXp) { + data.memberData.level = parseInt(level + 1, 10); + data.memberData.exp = 0; + msg.replyT("misc:LEVEL_UP", { + level: data.memberData.level + }, { mention: false }); + } else data.memberData.exp = parseInt(newXp, 10); - data.memberData.exp = parseInt(newXp, 10); await data.memberData.save(); } diff --git a/events/ready.js b/events/ready.js index 880bf781..4a8774bd 100644 --- a/events/ready.js +++ b/events/ready.js @@ -18,31 +18,24 @@ class Ready extends BaseEvent { let tUsers = client.users.cache.size - hiddenGuild.memberCount; let tServers = client.guilds.cache.size - 1; - // Logs some informations using logger client.logger.log(`Loaded a total of ${commands.length} command(s).`, "ready"); client.logger.log(`${client.user.tag}, ready to serve ${tUsers} users in ${tServers} servers.`, "ready"); client.logger.log(`Invite Link: ${client.generateInvite({ scopes: ["bot", "applications.commands"] , permissions: [ PermissionsBitField.Flags.Administrator ] })}`, "ready"); - // Birthday Announce const birthdays = require("../helpers/birthdays"); birthdays.init(client); - // Unmute users const checkUnmutes = require("../helpers/checkUnmutes"); checkUnmutes.init(client); - // Send reminds const checkReminds = require("../helpers/checkReminds"); checkReminds.init(client); - // Clear transactions const cleanup = require("../helpers/cleanup"); cleanup.init(client); - // Start the dashboard if (client.config.dashboard.enabled) client.dashboard.init(client); - // Update status const version = require("../package.json").version; const status = [ { name: "help", type: ActivityType.Watching }, diff --git a/helpers/cleanup.js b/helpers/cleanup.js index f701c390..6f46b5df 100644 --- a/helpers/cleanup.js +++ b/helpers/cleanup.js @@ -25,9 +25,9 @@ module.exports.init = async function (client) { for (const user of res) { client.users.fetch(user.id).then(u => { if (u.username.match(/.*Deleted User.* [A-z0-9]+/g)) { - client.databaseCache.users.delete(user.id); - client.usersData.deleteOne({ id: user.id }); - console.log(`Removed from database deleted user - ID: ${u.id} Username: ${u.username}`); + client.databaseCache.users.delete(u.id); + client.usersData.deleteOne({ id: u.id }); + client.logger.log(`Removed from database deleted user - ID: ${u.id} Username: ${u.username}`); } }); } diff --git a/helpers/extenders.js b/helpers/extenders.js index aa4f098d..d9d4070b 100644 --- a/helpers/extenders.js +++ b/helpers/extenders.js @@ -1,25 +1,12 @@ const { Message, CommandInteraction } = require("discord.js"); -/** - * - * @param {String} key - * @param {Array} args - * @returns {String} - */ CommandInteraction.prototype.translate = function (key, args) { const language = this.client.translations.get(this.guild ? this.guild.data.language : "ru-RU"); - if (!language) throw "Message: Invalid language set in data."; + if (!language) throw "Interaction: Invalid language set in data."; return language(key, args); }; -/** - * - * @param {String} key - * @param {Array} args - * @param {Array} options - * @returns {import("discord.js").BaseCommandInteraction} - */ CommandInteraction.prototype.replyT = function (key, args, options = {}) { let string = this.translate(key, args, this.guild ? this.guild.data.language : "ru-RU"); if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`; @@ -28,26 +15,12 @@ CommandInteraction.prototype.replyT = function (key, args, options = {}) { else return this.reply({ content: string, ephemeral: options.ephemeral || false }); }; -/** - * - * @param {String} key - * @param {Array} args - * @param {Array} options - * @returns {import("discord.js").BaseCommandInteraction} - */ CommandInteraction.prototype.error = function (key, args, options = {}) { options.prefixEmoji = "error"; return this.replyT(key, args, options); }; -/** - * - * @param {String} key - * @param {Array} args - * @param {Array} options - * @returns {import("discord.js").BaseCommandInteraction} - */ CommandInteraction.prototype.success = function (key, args, options = {}) { options.prefixEmoji = "success"; @@ -65,8 +38,8 @@ Message.prototype.replyT = function (key, args, options = {}) { let string = this.translate(key, args, this.guild ? this.guild.data.language : "ru-RU"); if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`; - if (options.edit) return this.edit({ content: string }); - else return this.reply({ content: string }); + if (options.edit) return this.edit({ content: string, allowedMentions: { repliedUser: options.mention || true } }); + else return this.reply({ content: string, allowedMentions: { repliedUser: options.mention || true } }); }; Message.prototype.error = function (key, args, options = {}) { diff --git a/languages/ru-RU/misc.json b/languages/ru-RU/misc.json index 583c5f4b..7b52d477 100644 --- a/languages/ru-RU/misc.json +++ b/languages/ru-RU/misc.json @@ -1,6 +1,7 @@ { "BOT_USER": "Вы не можете сделать это с ботом!", "FORCE_STOP": "Игра принудительно окончена {{user}}, никто не победил!", + "LEVEL_UP": "Вы достигли следующего уровня! Ваш новый уровень: **{{level}}**", "GUILD_ONLY": "Данную команду можно использовать только на сервере!", "HELLO_SERVER": "Привет, **{{username}}**! Все мои команды доступны через **/** Используйте `/help`, чтобы получить список команд!", "INVALID_NUMBER_RANGE": "Укажите число от **{{min}}** до **{{max}}**!", diff --git a/package.json b/package.json index 9e809726..6f578380 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jaba", - "version": "4.1.8", + "version": "4.1.9", "description": "My Discord Bot", "main": "index.js", "private": true,