mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 13:14:58 +05:00
v3.4.1
Переписана функция случайных чисел supportLink переписана под создание приглашения на сервер по его ID Уменьшено кол-во опыта за сообщение Мелкие правки в локализации и коде
This commit is contained in:
parent
00d8ecdc1b
commit
4a5cc4e28d
6 changed files with 16 additions and 41 deletions
|
@ -33,7 +33,7 @@ class FindWords extends Command {
|
||||||
const participants = [],
|
const participants = [],
|
||||||
winners = [],
|
winners = [],
|
||||||
words = [],
|
words = [],
|
||||||
nbGames = this.client.functions.randomNum(4, 10);
|
nbGames = this.client.functions.randomNum(3, 10);
|
||||||
|
|
||||||
// Store the date wich the game has started
|
// Store the date wich the game has started
|
||||||
const createdAt = Date.now(); // 20929038303
|
const createdAt = Date.now(); // 20929038303
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Number extends Command {
|
||||||
if (currentGames[message.guild.id]) return message.error("economy/number:GAME_RUNNING");
|
if (currentGames[message.guild.id]) return message.error("economy/number:GAME_RUNNING");
|
||||||
|
|
||||||
const participants = [],
|
const participants = [],
|
||||||
number = this.client.functions.randomNum(1000, 10000);
|
number = this.client.functions.randomNum(1000, 6000);
|
||||||
|
|
||||||
await message.sendT("economy/number:GAME_START");
|
await message.sendT("economy/number:GAME_START");
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Eightball extends Command {
|
||||||
async run(message, args) {
|
async run(message, args) {
|
||||||
if (!args[0] || !message.content.endsWith("?")) return message.error("fun/8ball:ERR_QUESTION");
|
if (!args[0] || !message.content.endsWith("?")) return message.error("fun/8ball:ERR_QUESTION");
|
||||||
|
|
||||||
const answerN = this.client.functions.randomNum(1, 21);
|
const answerN = this.client.functions.randomNum(1, 20);
|
||||||
const answer = message.translate(`fun/8ball:RESPONSE_${answerN}`);
|
const answer = message.translate(`fun/8ball:RESPONSE_${answerN}`);
|
||||||
|
|
||||||
message.reply({
|
message.reply({
|
||||||
|
|
|
@ -212,37 +212,23 @@ module.exports = class {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* updateXp
|
|
||||||
* This function update userdata by adding xp
|
|
||||||
*/
|
|
||||||
async function updateXp(client, msg, data) {
|
async function updateXp(client, msg, data) {
|
||||||
// Gets the user informations
|
|
||||||
const points = parseInt(data.memberData.exp);
|
const points = parseInt(data.memberData.exp);
|
||||||
const level = parseInt(data.memberData.level);
|
const level = parseInt(data.memberData.level);
|
||||||
|
|
||||||
// if the member is already in the cooldown db
|
|
||||||
const isInCooldown = xpCooldown[msg.author.id];
|
const isInCooldown = xpCooldown[msg.author.id];
|
||||||
if (isInCooldown) {
|
if (isInCooldown) {
|
||||||
if (isInCooldown > Date.now()) return;
|
if (isInCooldown > Date.now()) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Records in the database the time when the member will be able to win xp again (1min)
|
const toWait = Date.now() + 60000; // 1 min
|
||||||
const toWait = Date.now() + 60000;
|
|
||||||
xpCooldown[msg.author.id] = toWait;
|
xpCooldown[msg.author.id] = toWait;
|
||||||
|
|
||||||
// Gets a random number between 5 and 10
|
const won = client.functions.randomNum(2, 5);
|
||||||
const won = client.functions.randomNum(5, 10);
|
|
||||||
|
|
||||||
const newXp = parseInt(points + won, 10);
|
const newXp = parseInt(points + won, 10);
|
||||||
|
|
||||||
// calculation how many xp it takes for the next new one
|
|
||||||
const neededXp = 5 * (level * level) + 80 * level + 100;
|
const neededXp = 5 * (level * level) + 80 * level + 100;
|
||||||
|
|
||||||
// check if the member up to the next level
|
|
||||||
if (newXp > neededXp) data.memberData.level = parseInt(level + 1, 10);
|
if (newXp > neededXp) data.memberData.level = parseInt(level + 1, 10);
|
||||||
|
|
||||||
// Update user data
|
|
||||||
data.memberData.exp = parseInt(newXp, 10);
|
data.memberData.exp = parseInt(newXp, 10);
|
||||||
await data.memberData.save();
|
await data.memberData.save();
|
||||||
}
|
}
|
|
@ -5,12 +5,6 @@ languages.forEach((lang) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
|
||||||
* Gets message prefix
|
|
||||||
* @param {object} message The Discord message
|
|
||||||
* @param {object} data Server data
|
|
||||||
* @returns The prefix
|
|
||||||
*/
|
|
||||||
getPrefix(message, data) {
|
getPrefix(message, data) {
|
||||||
if (message.channel.type !== "DM") {
|
if (message.channel.type !== "DM") {
|
||||||
const prefixes = [
|
const prefixes = [
|
||||||
|
@ -21,34 +15,31 @@ module.exports = {
|
||||||
message.client.user.username.toLowerCase(),
|
message.client.user.username.toLowerCase(),
|
||||||
data.guild.prefix
|
data.guild.prefix
|
||||||
];
|
];
|
||||||
|
|
||||||
let prefix = null;
|
let prefix = null;
|
||||||
|
|
||||||
prefixes.forEach((p) => {
|
prefixes.forEach((p) => {
|
||||||
if (message.content.startsWith(p) || message.content.toLowerCase().startsWith(p)) prefix = p;
|
if (message.content.startsWith(p) || message.content.toLowerCase().startsWith(p)) prefix = p;
|
||||||
});
|
});
|
||||||
|
|
||||||
return prefix;
|
return prefix;
|
||||||
} else {
|
} else return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// This function return an actual link to the support server
|
async createInvite(client, guildId) {
|
||||||
async supportLink(client) {
|
const guild = client.guilds.cache.get(guildId);
|
||||||
const guild = client.guilds.cache.get(client.config.support.id);
|
|
||||||
const member = guild.me;
|
const member = guild.me;
|
||||||
const channel = guild.channels.cache.find((ch) => ch.permissionsFor(member.id).has(Permissions.FLAGS.CREATE_INSTANT_INVITE) && ch.type === "GUILD_TEXT" || ch.type === "GUILD_VOICE");
|
const channel = guild.channels.cache.find((ch) => ch.permissionsFor(member.id).has(Permissions.FLAGS.CREATE_INSTANT_INVITE) && ch.type === "GUILD_TEXT" || ch.type === "GUILD_VOICE");
|
||||||
if (channel) {
|
if (channel) {
|
||||||
const invite = await channel.createInvite({
|
const invite = await channel.createInvite({
|
||||||
maxAge: 0
|
maxAge: 0,
|
||||||
|
maxUses: 5
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
||||||
return invite ? invite.url : null;
|
return invite ? invite.url : "No URL";
|
||||||
} else {
|
} return "No Invite";
|
||||||
return "";
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// This function sort an array
|
|
||||||
sortByKey(array, key) {
|
sortByKey(array, key) {
|
||||||
return array.sort(function (a, b) {
|
return array.sort(function (a, b) {
|
||||||
const x = a[key];
|
const x = a[key];
|
||||||
|
@ -57,7 +48,6 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// This function return a shuffled array
|
|
||||||
shuffle(pArray) {
|
shuffle(pArray) {
|
||||||
const array = [];
|
const array = [];
|
||||||
pArray.forEach(element => array.push(element));
|
pArray.forEach(element => array.push(element));
|
||||||
|
@ -78,9 +68,8 @@ module.exports = {
|
||||||
return array;
|
return array;
|
||||||
},
|
},
|
||||||
|
|
||||||
// This function return a random number between min and max
|
|
||||||
randomNum(min, max) {
|
randomNum(min, max) {
|
||||||
return Math.floor(Math.random() * (max - min)) + min;
|
return Math.floor(Math.random() * (max - min) + min + 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
convertTime(guild, time) {
|
convertTime(guild, time) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "jaba",
|
"name": "jaba",
|
||||||
"version": "3.4.0",
|
"version": "3.4.1",
|
||||||
"description": "A very complete Discord bot (more than 100 commands) that uses the Discord.js",
|
"description": "A very complete Discord bot (more than 100 commands) that uses the Discord.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|
Loading…
Reference in a new issue