mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-25 06:34:58 +05:00
This commit is contained in:
parent
625ab84df0
commit
76ab9c38a0
23 changed files with 81 additions and 90 deletions
34
base/JaBa.js
34
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;
|
||||
}
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -50,7 +50,7 @@ class Pay extends BaseCommand {
|
|||
|
||||
const memberData = await client.findOrCreateMember({
|
||||
id: member.id,
|
||||
guildID: interaction.guildId
|
||||
guildId: interaction.guildId
|
||||
});
|
||||
|
||||
const info = {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -38,7 +38,7 @@ class Clearwarns extends BaseCommand {
|
|||
|
||||
const memberData = await client.findOrCreateMember({
|
||||
id: member.id,
|
||||
guildID: interaction.guildId
|
||||
guildId: interaction.guildId
|
||||
});
|
||||
|
||||
memberData.sanctions = [];
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
### JaBa v4.1.9
|
||||
* Изменения
|
||||
* Переписана система опыта. Теперь при достижении нового уровня опыт сбрасывается и бот оповещает о получении нового уровня.
|
||||
|
||||
* Исправления
|
||||
* Команды *set* и *debug* ничего не делали.
|
||||
|
||||
### JaBa v4.1.8
|
||||
* Добавлено
|
||||
* Возможность сразу сократить ссылку в команде *lmgtfy*.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 = {}) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"BOT_USER": "Вы не можете сделать это с ботом!",
|
||||
"FORCE_STOP": "Игра принудительно окончена {{user}}, никто не победил!",
|
||||
"LEVEL_UP": "Вы достигли следующего уровня! Ваш новый уровень: **{{level}}**",
|
||||
"GUILD_ONLY": "Данную команду можно использовать только на сервере!",
|
||||
"HELLO_SERVER": "Привет, **{{username}}**! Все мои команды доступны через **/** Используйте `/help`, чтобы получить список команд!",
|
||||
"INVALID_NUMBER_RANGE": "Укажите число от **{{min}}** до **{{max}}**!",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jaba",
|
||||
"version": "4.1.8",
|
||||
"version": "4.1.9",
|
||||
"description": "My Discord Bot",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
|
Loading…
Reference in a new issue