|
|
@ -1,14 +1,17 @@
|
|
|
|
const Discord = require(`discord.js`);
|
|
|
|
const { EmbedBuilder } = require(`discord.js`);
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = async (bot) => {
|
|
|
|
module.exports = async (bot) => {
|
|
|
|
async function getData() {
|
|
|
|
async function getData() {
|
|
|
|
// Require https module
|
|
|
|
// Require https module
|
|
|
|
const superagent = require(`superagent`);
|
|
|
|
const superagent = require(`superagent`);
|
|
|
|
// Request url
|
|
|
|
// Request url
|
|
|
|
let url = `https://api.crowdin.com/api/project/${process.env.PROJECT}/status?login=${process.env.LOGIN}&account-key=${process.env.ACCOUNT_KEY}&json`;
|
|
|
|
let url = `https://api.crowdin.com/api/v2/projects/${process.env.PROJECT_ID}/languages/progress`;
|
|
|
|
// Get the url and store the informations
|
|
|
|
// Get the url and store the informations
|
|
|
|
let { body } = await superagent.get(url);
|
|
|
|
let {
|
|
|
|
return body;
|
|
|
|
body
|
|
|
|
|
|
|
|
} = await superagent.get(url).set(`Authorization`, `Bearer ${process.env.ACCESS_TOKEN}`);
|
|
|
|
|
|
|
|
// Return the body
|
|
|
|
|
|
|
|
return body.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Log when the bot is on
|
|
|
|
// Log when the bot is on
|
|
|
|
console.log(`${bot.user.username} en ligne!`);
|
|
|
|
console.log(`${bot.user.username} en ligne!`);
|
|
|
@ -26,31 +29,48 @@ module.exports = async (bot) => {
|
|
|
|
if (bot.config.purgeOnRestart) channel.bulkDelete(amountToPurge);
|
|
|
|
if (bot.config.purgeOnRestart) channel.bulkDelete(amountToPurge);
|
|
|
|
// Display or not the project link
|
|
|
|
// Display or not the project link
|
|
|
|
let link = bot.config.displayLink ? `\nYou can help translating by following [this](${bot.config.projectLink}) link.` : ``;
|
|
|
|
let link = bot.config.displayLink ? `\nYou can help translating by following [this](${bot.config.projectLink}) link.` : ``;
|
|
|
|
// Creates a discord MessageEmbed
|
|
|
|
// Creates a discord EmbedBuilder
|
|
|
|
let embed = new Discord.MessageEmbed()
|
|
|
|
let embed = new EmbedBuilder()
|
|
|
|
.setDescription(`**Status of the languages**${link}`)
|
|
|
|
.setDescription(`**Status of the languages**${link}`)
|
|
|
|
.setFooter(`Last edit ${new Date()}`);
|
|
|
|
.setFooter({ text: `Last edit ${new Date()}` });
|
|
|
|
// Get the data with the getData() function
|
|
|
|
// Get the data with the getData() function
|
|
|
|
let data = await getData();
|
|
|
|
let data = await getData();
|
|
|
|
// For every object in the body array add a field to the embed
|
|
|
|
// For every object in the body array add a field to the embed
|
|
|
|
for (let languages of data) {
|
|
|
|
for (let languages of data) {
|
|
|
|
// Field data
|
|
|
|
let data = languages.data;
|
|
|
|
embed.addField(`${languages.name} (${languages.code})`, `Translated Progress: ${languages.translated_progress}%\nApproved progress: ${languages.approved_progress}%\nSentences: ${languages.phrases}, Translated: ${languages.translated}, Approved: ${languages.approved}\nWords: ${languages.words}, Translated: ${languages.words_translated}, Approved: ${languages.words_approved}`);
|
|
|
|
embed.addFields([
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: `${data.languageId}`,
|
|
|
|
|
|
|
|
value: `Translated Progress: ${data.translationProgress}%
|
|
|
|
|
|
|
|
Approved progress: ${data.approvalProgress}%
|
|
|
|
|
|
|
|
Sentences: ${data.phrases.total}, Translated: ${data.phrases.translated}, Approved: ${data.phrases.approved}
|
|
|
|
|
|
|
|
Words: ${data.words.total}, Translated: ${data.words.translated}, Approved: ${data.words.approved}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Send the message
|
|
|
|
// Send the message
|
|
|
|
let message = await channel.send(embed);
|
|
|
|
let message = await channel.send({ embeds: [embed] });
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the edit time is valid in the config file
|
|
|
|
// Check if the edit time is valid in the config file
|
|
|
|
if (isNaN(bot.config.editTime)) return console.log(`You need to set a valid edit time in the configuration file (config.json)`);
|
|
|
|
if (isNaN(bot.config.editTime)) return console.log(`You need to set a valid edit time in the configuration file (config.json)`);
|
|
|
|
setInterval(async () => {
|
|
|
|
setInterval(async () => {
|
|
|
|
let embedEdit = new Discord.MessageEmbed();
|
|
|
|
|
|
|
|
|
|
|
|
let embedEdit = new EmbedBuilder();
|
|
|
|
embedEdit.setDescription(`**Status of the languages**${link}`)
|
|
|
|
embedEdit.setDescription(`**Status of the languages**${link}`)
|
|
|
|
.setFooter(`Last edit ${new Date()}`);
|
|
|
|
.setFooter({ text: `Last edit ${new Date()}` });
|
|
|
|
let newData = await getData();
|
|
|
|
let newData = await getData();
|
|
|
|
for (let languages of newData) {
|
|
|
|
for (let languages of newData) {
|
|
|
|
// Field data
|
|
|
|
let data = languages.data;
|
|
|
|
embedEdit.addField(`${languages.name} (${languages.code})`, `Translated Progress: ${languages.translated_progress}%\nApproved progress: ${languages.approved_progress}%\nSentences: ${languages.phrases}, Translated: ${languages.translated}, Approved: ${languages.approved}\nWords: ${languages.words}, Translated: ${languages.words_translated}, Approved: ${languages.words_approved}`);
|
|
|
|
embedEdit.addFields([
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: `${data.languageId}`,
|
|
|
|
|
|
|
|
value: `Translated Progress: ${data.translationProgress}%
|
|
|
|
|
|
|
|
Approved progress: ${data.approvalProgress}%
|
|
|
|
|
|
|
|
Sentences: ${data.phrases.total}, Translated: ${data.phrases.translated}, Approved: ${data.phrases.approved}
|
|
|
|
|
|
|
|
Words: ${data.words.total}, Translated: ${data.words.translated}, Approved: ${data.words.approved}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message.edit(embedEdit);
|
|
|
|
message.edit({ embeds: [embedEdit] });
|
|
|
|
}, bot.config.editTime);
|
|
|
|
}, bot.config.editTime);
|
|
|
|
};
|
|
|
|
};
|