some cleanup in helpers functions

This commit is contained in:
Jonny_Bro (Nikita) 2023-10-10 20:44:42 +05:00
parent 89ce374f37
commit c620e492c9
6 changed files with 58 additions and 55 deletions

View file

@ -14,7 +14,7 @@ module.exports.update = function (client) {
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) {
// const aCmdsSize = commands.filter(cmd => cmd.category === a).size;
@ -24,10 +24,10 @@ module.exports.update = function (client) {
// })
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()];
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) {
if (a.command.name < b.command.name) return -1;
else return 1;
@ -36,7 +36,7 @@ module.exports.update = function (client) {
`**${cmd.command.name}** ${cmd.aliases.length ? `**(${cmd.aliases.join(", ")})**` : ""}`,
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.dm_permission ? "На сервере и в ЛС бота" : "Только на сервере",
cmd.command.dm_permission ? "Servers/DMs" : "Only on servers",
]);
});
text += `${table(categoriesArray)}\n\n`;

View file

@ -7,25 +7,26 @@ const { CronJob } = require("cron"),
*/
module.exports.init = async function (client) {
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 => {
const guildData = await client.findOrCreateGuild({ id: guild.id });
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) {
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
for (const user of users) {
if (guild.members.cache.find(m => m.id === user.id)) {
const userDate = new Date(user.birthdate);
const day = userDate.getDate();
const month = userDate.getMonth();
const year = userDate.getFullYear();
const age = currentYear - year;
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()
@ -52,7 +53,6 @@ module.exports.init = async function (client) {
await msg.react("🎉");
}
}
}
});
}
}

View file

@ -9,18 +9,19 @@ module.exports.init = function (client) {
client.usersData.find({ reminds: { $gt: [] } }).then(users => {
for (const user of users) {
if (!client.users.cache.has(user.id)) client.users.fetch(user.id);
client.databaseCache.usersReminds.set(user.id, user);
}
});
setInterval(async function () {
const dateNow = Date.now();
client.databaseCache.usersReminds.forEach(async user => {
const dUser = client.users.cache.get(user.id);
const cachedUser = client.users.cache.get(user.id);
if (dUser) {
const reminds = user.reminds;
const mustSent = reminds.filter(r => r.sendAt < dateNow);
if (cachedUser) {
const dateNow = Date.now(),
reminds = user.reminds,
mustSent = reminds.filter(r => r.sendAt < dateNow);
if (mustSent.length > 0) {
mustSent.forEach(r => {
@ -42,7 +43,7 @@ module.exports.init = function (client) {
.setColor(client.config.embed.color)
.setFooter(client.config.embed.footer);
dUser.send({
cachedUser.send({
embeds: [embed],
});
});

View file

@ -5,15 +5,14 @@ User.prototype.getUsername = function () {
};
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.";
return language(key, args);
};
BaseInteraction.prototype.replyT = function (key, args, options = {}) {
let string = this.translate(key, args);
if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`;
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${string}` : this.translate(key, args, this.guild ? this.guild.data.language : "en-US");
if (options.edit) return this.editReply({ 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) {
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.";
return language(key, args);
};
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}`;
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${string}` : this.translate(key, args, this.guild ? this.guild.data.language : "en-US");
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 } });

View file

@ -16,9 +16,10 @@ module.exports = {
* @returns {String} Invite Link
*/
async createInvite(client, guildId) {
const guild = client.guilds.cache.get(guildId);
const 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");
const guild = client.guilds.cache.get(guildId),
member = guild.members.me,
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";
},
@ -83,6 +84,7 @@ module.exports = {
randomNum(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);
},
@ -97,6 +99,7 @@ module.exports = {
printDate(client, date, format = null, locale = client.defaultLanguage) {
const languageData = client.languages.find(language => language.name === locale);
if (format === "" || format === null) format = languageData.defaultMomentFormat;
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) {
const languageData = client.languages.find(language => language.name === locale);
const m = moment(time).locale(languageData.moment);
return type ? m.toNow(noPrefix) : m.fromNow(noPrefix);
},

View file

@ -5,5 +5,5 @@
"TIME": "Time (e.g., 10s, 5m, 2h, 1d, 3w)",
"SAVED": "Reminder `{{message}}` saved for **{{time}}**",
"TITLE": "Reminder from JaBa",
"CREATED": "Reminder created for: **{{time}}**"
"CREATED": "Reminder created: **{{time}}**"
}