mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-21 20:54:58 +05:00
some cleanup in helpers functions
This commit is contained in:
parent
89ce374f37
commit
c620e492c9
6 changed files with 58 additions and 55 deletions
|
@ -14,7 +14,7 @@ module.exports.update = function (client) {
|
||||||
if (!categories.includes(cmd.category)) categories.push(cmd.category);
|
if (!categories.includes(cmd.category)) categories.push(cmd.category);
|
||||||
});
|
});
|
||||||
|
|
||||||
let text = `# JaBa имеет **${commands.length} ${client.functions.getNoun(commands.length, "команда", "команды", "команд")}** в **${categories.length} ${client.functions.getNoun(categories.length, "категории", "категориях", "категориях")}**! \n\n#### Содержимое таблицы \n**Название**: Название команды \n**Описание**: Описание команды \n**Использование**: Использование команды ( [] - обязательно, () - необязательно ) \n**Разрешено использование**: Где можно использовать команду \n\n`;
|
let text = `# JaBa has **${commands.length} ${client.functions.getNoun(commands.length, "command", "commands", "commands")}** in **${categories.length} ${client.functions.getNoun(categories.length, "category", "categories", "categories")}**! \n\n#### Table content \n**Name**: Command name \n**Description**: Command description \n**Usage**: How to use the command (*[]* - required, *()* - optional) \n**Accessible in**: Where you can use the command \n\n`;
|
||||||
|
|
||||||
// categories.sort(function(a, b) {
|
// categories.sort(function(a, b) {
|
||||||
// const aCmdsSize = commands.filter(cmd => cmd.category === a).size;
|
// const aCmdsSize = commands.filter(cmd => cmd.category === a).size;
|
||||||
|
@ -24,10 +24,10 @@ module.exports.update = function (client) {
|
||||||
// })
|
// })
|
||||||
|
|
||||||
categories.sort().forEach(cat => {
|
categories.sort().forEach(cat => {
|
||||||
const categoriesArray = [["Название", "Описание", "Использование", "Разрешено использование"]];
|
const categoriesArray = [["Name", "Description", "Usage", "Accessible in"]];
|
||||||
const cmds = [...new Map(commands.filter(cmd => cmd.category === cat).map(v => [v.constructor.name, v])).values()];
|
const cmds = [...new Map(commands.filter(cmd => cmd.category === cat).map(v => [v.constructor.name, v])).values()];
|
||||||
|
|
||||||
text += `### ${cat} (${cmds.length} ${client.functions.getNoun(cmds.length, "команда", "команды", "команд")})\n\n`;
|
text += `### ${cat} (${cmds.length} ${client.functions.getNoun(cmds.length, "command", "commands", "commands")})\n\n`;
|
||||||
cmds.sort(function (a, b) {
|
cmds.sort(function (a, b) {
|
||||||
if (a.command.name < b.command.name) return -1;
|
if (a.command.name < b.command.name) return -1;
|
||||||
else return 1;
|
else return 1;
|
||||||
|
@ -36,7 +36,7 @@ module.exports.update = function (client) {
|
||||||
`**${cmd.command.name}** ${cmd.aliases.length ? `**(${cmd.aliases.join(", ")})**` : ""}`,
|
`**${cmd.command.name}** ${cmd.aliases.length ? `**(${cmd.aliases.join(", ")})**` : ""}`,
|
||||||
client.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:DESCRIPTION`),
|
client.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:DESCRIPTION`),
|
||||||
`${cmd.command.name} ${client.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:USAGE`).replace(/\n/, " \\| ")}`,
|
`${cmd.command.name} ${client.translate(`${cmd.category.toLowerCase()}/${cmd.command.name}:USAGE`).replace(/\n/, " \\| ")}`,
|
||||||
cmd.command.dm_permission ? "На сервере и в ЛС бота" : "Только на сервере",
|
cmd.command.dm_permission ? "Servers/DMs" : "Only on servers",
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
text += `${table(categoriesArray)}\n\n`;
|
text += `${table(categoriesArray)}\n\n`;
|
||||||
|
|
|
@ -7,50 +7,50 @@ const { CronJob } = require("cron"),
|
||||||
*/
|
*/
|
||||||
module.exports.init = async function (client) {
|
module.exports.init = async function (client) {
|
||||||
new CronJob("0 5 * * *", async function () {
|
new CronJob("0 5 * * *", async function () {
|
||||||
const date = new Date(),
|
|
||||||
currentDay = date.getDate(),
|
|
||||||
currentMonth = date.getMonth(),
|
|
||||||
currentYear = date.getFullYear();
|
|
||||||
|
|
||||||
client.guilds.cache.forEach(async guild => {
|
client.guilds.cache.forEach(async guild => {
|
||||||
const guildData = await client.findOrCreateGuild({ id: guild.id });
|
const guildData = await client.findOrCreateGuild({ id: guild.id });
|
||||||
|
|
||||||
if (guildData.plugins.birthdays) {
|
if (guildData.plugins.birthdays) {
|
||||||
const channel = client.channels.cache.get(guildData.plugins.birthdays);
|
const channel = client.channels.cache.get(guildData.plugins.birthdays),
|
||||||
|
date = new Date(),
|
||||||
|
currentDay = date.getDate(),
|
||||||
|
currentMonth = date.getMonth(),
|
||||||
|
currentYear = date.getFullYear();
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
if (guild.members.cache.find(m => m.id === user.id)) {
|
if (!guild.members.cache.find(m => m.id === user.id)) return;
|
||||||
const userDate = new Date(user.birthdate);
|
|
||||||
const day = userDate.getDate();
|
|
||||||
const month = userDate.getMonth();
|
|
||||||
const year = userDate.getFullYear();
|
|
||||||
const age = currentYear - year;
|
|
||||||
|
|
||||||
if (currentMonth === month && currentDay === day) {
|
const userDate = new Date(user.birthdate),
|
||||||
const embed = new EmbedBuilder()
|
day = userDate.getDate(),
|
||||||
.setAuthor({
|
month = userDate.getMonth(),
|
||||||
name: client.user.getUsername(),
|
year = userDate.getFullYear(),
|
||||||
iconURL: client.user.displayAvatarURL(),
|
age = currentYear - year;
|
||||||
})
|
|
||||||
.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({
|
if (currentMonth === month && currentDay === day) {
|
||||||
embeds: [embed],
|
const embed = new EmbedBuilder()
|
||||||
});
|
.setAuthor({
|
||||||
await msg.react("🎉");
|
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("🎉");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,18 +9,19 @@ module.exports.init = function (client) {
|
||||||
client.usersData.find({ reminds: { $gt: [] } }).then(users => {
|
client.usersData.find({ reminds: { $gt: [] } }).then(users => {
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
if (!client.users.cache.has(user.id)) client.users.fetch(user.id);
|
if (!client.users.cache.has(user.id)) client.users.fetch(user.id);
|
||||||
|
|
||||||
client.databaseCache.usersReminds.set(user.id, user);
|
client.databaseCache.usersReminds.set(user.id, user);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(async function () {
|
setInterval(async function () {
|
||||||
const dateNow = Date.now();
|
|
||||||
client.databaseCache.usersReminds.forEach(async user => {
|
client.databaseCache.usersReminds.forEach(async user => {
|
||||||
const dUser = client.users.cache.get(user.id);
|
const cachedUser = client.users.cache.get(user.id);
|
||||||
|
|
||||||
if (dUser) {
|
if (cachedUser) {
|
||||||
const reminds = user.reminds;
|
const dateNow = Date.now(),
|
||||||
const mustSent = reminds.filter(r => r.sendAt < dateNow);
|
reminds = user.reminds,
|
||||||
|
mustSent = reminds.filter(r => r.sendAt < dateNow);
|
||||||
|
|
||||||
if (mustSent.length > 0) {
|
if (mustSent.length > 0) {
|
||||||
mustSent.forEach(r => {
|
mustSent.forEach(r => {
|
||||||
|
@ -42,7 +43,7 @@ module.exports.init = function (client) {
|
||||||
.setColor(client.config.embed.color)
|
.setColor(client.config.embed.color)
|
||||||
.setFooter(client.config.embed.footer);
|
.setFooter(client.config.embed.footer);
|
||||||
|
|
||||||
dUser.send({
|
cachedUser.send({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,15 +5,14 @@ User.prototype.getUsername = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseInteraction.prototype.translate = function (key, args) {
|
BaseInteraction.prototype.translate = function (key, args) {
|
||||||
const language = this.client.translations.get(this.guild ? (this.guild.data ? this.guild.data.language : "ru-RU") : "ru-RU");
|
const language = this.client.translations.get(this.guild ? this.guild.data.language : "en-US");
|
||||||
if (!language) throw "Interaction: Invalid language set in data.";
|
if (!language) throw "Interaction: Invalid language set in data.";
|
||||||
|
|
||||||
return language(key, args);
|
return language(key, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseInteraction.prototype.replyT = function (key, args, options = {}) {
|
BaseInteraction.prototype.replyT = function (key, args, options = {}) {
|
||||||
let string = this.translate(key, args);
|
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${string}` : this.translate(key, args, this.guild ? this.guild.data.language : "en-US");
|
||||||
if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`;
|
|
||||||
|
|
||||||
if (options.edit) return this.editReply({ content: string, ephemeral: options.ephemeral || false });
|
if (options.edit) return this.editReply({ content: string, ephemeral: options.ephemeral || false });
|
||||||
else return this.reply({ content: string, ephemeral: options.ephemeral || false });
|
else return this.reply({ content: string, ephemeral: options.ephemeral || false });
|
||||||
|
@ -32,15 +31,14 @@ BaseInteraction.prototype.error = function (key, args, options = {}) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Message.prototype.translate = function (key, args) {
|
Message.prototype.translate = function (key, args) {
|
||||||
const language = this.client.translations.get(this.guild ? this.guild.data.language : "ru-RU");
|
const language = this.client.translations.get(this.guild ? this.guild.data.language : "en-US");
|
||||||
if (!language) throw "Message: Invalid language set in data.";
|
if (!language) throw "Message: Invalid language set in data.";
|
||||||
|
|
||||||
return language(key, args);
|
return language(key, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
Message.prototype.replyT = function (key, args, options = {}) {
|
Message.prototype.replyT = function (key, args, options = {}) {
|
||||||
let string = this.translate(key, args, this.guild ? this.guild.data.language : "ru-RU");
|
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${string}` : this.translate(key, args, this.guild ? this.guild.data.language : "en-US");
|
||||||
if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`;
|
|
||||||
|
|
||||||
if (options.edit) return this.edit({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });
|
if (options.edit) return this.edit({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });
|
||||||
else return this.reply({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });
|
else return this.reply({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });
|
||||||
|
|
|
@ -16,9 +16,10 @@ module.exports = {
|
||||||
* @returns {String} Invite Link
|
* @returns {String} Invite Link
|
||||||
*/
|
*/
|
||||||
async createInvite(client, guildId) {
|
async createInvite(client, guildId) {
|
||||||
const guild = client.guilds.cache.get(guildId);
|
const guild = client.guilds.cache.get(guildId),
|
||||||
const member = guild.members.me;
|
member = guild.members.me,
|
||||||
const channel = guild.channels.cache.find(ch => (ch.permissionsFor(member.id).has(PermissionsBitField.Flags.CreateInstantInvite) && ch.type === ChannelType.GuildText) || ch.type === "GUILD_VOICE");
|
channel = guild.channels.cache.find(ch => (ch.permissionsFor(member.id).has(PermissionsBitField.Flags.CreateInstantInvite) && ch.type === ChannelType.GuildText) || ch.type === "GUILD_VOICE");
|
||||||
|
|
||||||
if (channel) return (await channel.createInvite()).url || "No channels found or missing permissions";
|
if (channel) return (await channel.createInvite()).url || "No channels found or missing permissions";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -83,6 +84,7 @@ module.exports = {
|
||||||
randomNum(min, max) {
|
randomNum(min, max) {
|
||||||
min = Math.ceil(min);
|
min = Math.ceil(min);
|
||||||
max = Math.floor(max);
|
max = Math.floor(max);
|
||||||
|
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -97,6 +99,7 @@ module.exports = {
|
||||||
printDate(client, date, format = null, locale = client.defaultLanguage) {
|
printDate(client, date, format = null, locale = client.defaultLanguage) {
|
||||||
const languageData = client.languages.find(language => language.name === locale);
|
const languageData = client.languages.find(language => language.name === locale);
|
||||||
if (format === "" || format === null) format = languageData.defaultMomentFormat;
|
if (format === "" || format === null) format = languageData.defaultMomentFormat;
|
||||||
|
|
||||||
return moment(new Date(date)).locale(languageData.moment).format(format);
|
return moment(new Date(date)).locale(languageData.moment).format(format);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -112,6 +115,7 @@ module.exports = {
|
||||||
convertTime(client, time, type = false, noPrefix = false, locale = client.defaultLanguage) {
|
convertTime(client, time, type = false, noPrefix = false, locale = client.defaultLanguage) {
|
||||||
const languageData = client.languages.find(language => language.name === locale);
|
const languageData = client.languages.find(language => language.name === locale);
|
||||||
const m = moment(time).locale(languageData.moment);
|
const m = moment(time).locale(languageData.moment);
|
||||||
|
|
||||||
return type ? m.toNow(noPrefix) : m.fromNow(noPrefix);
|
return type ? m.toNow(noPrefix) : m.fromNow(noPrefix);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
"TIME": "Time (e.g., 10s, 5m, 2h, 1d, 3w)",
|
"TIME": "Time (e.g., 10s, 5m, 2h, 1d, 3w)",
|
||||||
"SAVED": "Reminder `{{message}}` saved for **{{time}}**",
|
"SAVED": "Reminder `{{message}}` saved for **{{time}}**",
|
||||||
"TITLE": "Reminder from JaBa",
|
"TITLE": "Reminder from JaBa",
|
||||||
"CREATED": "Reminder created for: **{{time}}**"
|
"CREATED": "Reminder created: **{{time}}**"
|
||||||
}
|
}
|
Loading…
Reference in a new issue