⭐ First Version Of The Bot
commit
946a2ac970
@ -0,0 +1,4 @@
|
||||
TOKEN=YOUR_DISCORD_BOT_TOKEN_GOES_HERE
|
||||
PROJECT=YOUR_PROJECT_NAME
|
||||
LOGIN=YOUR_USERNAME
|
||||
ACCOUNT_KEY=YOUR_ACCOUNT_API_KEY
|
@ -0,0 +1,24 @@
|
||||
module.exports = {
|
||||
"rules": {
|
||||
"no-console": `off`,
|
||||
"indent": [`error`, `tab`],
|
||||
"semi": [`error`, `always`],
|
||||
"quotes": [`error`, `backtick`],
|
||||
"keyword-spacing": [
|
||||
`error`,
|
||||
{
|
||||
"before": true, "after": true
|
||||
}
|
||||
],
|
||||
"no-async-promise-executor": 0,
|
||||
"no-case-declarations": 0,
|
||||
},
|
||||
"extends": `eslint:recommended`,
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true,
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020
|
||||
},
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
.env
|
||||
node_modules/
|
||||
package-lock.json
|
||||
notes.js
|
||||
config.json
|
@ -0,0 +1,54 @@
|
||||
const Discord = require(`discord.js`);
|
||||
|
||||
module.exports = async (bot) => {
|
||||
async function getData() {
|
||||
// Require https module
|
||||
const superagent = require(`superagent`);
|
||||
// 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`;
|
||||
// Get the url and store the informations
|
||||
let { body } = await superagent.get(url);
|
||||
return body;
|
||||
}
|
||||
// Log when the bot is on
|
||||
console.log(`${bot.user.username} en ligne!`);
|
||||
// Find the status channel
|
||||
let channel = bot.channels.cache.find(c => c.id === bot.config.channel);
|
||||
// Returns an error if the channel is not configured of invalid in the config file
|
||||
if (!channel) return console.log(`You need to set a valid channel in the configuration file (config.json)`);
|
||||
// Fetch all the messages of the status channel
|
||||
await channel.messages.fetch();
|
||||
// Check wether to purge or not the channel on start
|
||||
let amountToPurge = bot.config.purgeAmount;
|
||||
// Check if the amount of messages to delete is valid in the config file
|
||||
if (isNaN(amountToPurge) || parseInt(amountToPurge) < 1 || parseInt(amountToPurge) > 100) return console.log(`You need to set a valid amount of messages to purge (beetween 1 and 100) in the configuration file (config.json)`);
|
||||
// If purgeOnRestart is set to true in the config bulkDelete the channel
|
||||
if (bot.config.purgeOnRestart) channel.bulkDelete(amountToPurge);
|
||||
// Creates a discord MessageEmbed
|
||||
let embed = new Discord.MessageEmbed()
|
||||
.setDescription(`**Status of the languages**`)
|
||||
.setFooter(`Last edit ${new Date()}`);
|
||||
// Get the data with the getData() function
|
||||
let data = await getData();
|
||||
// For every object in the body array add a field to the embed
|
||||
for (let languages of data) {
|
||||
// Field data
|
||||
embed.addField(`${languages.name} (${languages.code})`, `Translated Progress: ${languages.translated_progress}%\nApproved progress: ${languages.approved_progress}%\nPhrases: ${languages.phrases}, Translated: ${languages.translated}, Approved: ${languages.approved}\nWords: ${languages.words}, Translated: ${languages.words_translated}, Approved: ${languages.words_approved}`);
|
||||
}
|
||||
// Send the message
|
||||
let message = await channel.send(embed);
|
||||
|
||||
// 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)`);
|
||||
setInterval(async () => {
|
||||
let embedEdit = new Discord.MessageEmbed();
|
||||
embedEdit.setDescription(`**Status of the languages**`)
|
||||
.setFooter(`Last edit ${new Date()}`);
|
||||
let newData = await getData();
|
||||
for (let languages of newData) {
|
||||
// Field data
|
||||
embedEdit.addField(`${languages.name} (${languages.code})`, `Translated Progress: ${languages.translated_progress}%\nApproved progress: ${languages.approved_progress}%\nPhrases: ${languages.phrases}, Translated: ${languages.translated}, Approved: ${languages.approved}\nWords: ${languages.words}, Translated: ${languages.words_translated}, Approved: ${languages.words_approved}`);
|
||||
}
|
||||
message.edit(embedEdit);
|
||||
}, bot.config.editTime);
|
||||
};
|
@ -0,0 +1,73 @@
|
||||
# A discord bot allowing you to see the status of your crowdin translations
|
||||
|
||||
|
||||
### You really don't like editing the status message you sent with the translations informations every day ? This bot is for you !!
|
||||
|
||||
# Features
|
||||
|
||||
- Message updating with the new informations every X times.
|
||||
- Language name
|
||||
- Language code
|
||||
- Translated progress
|
||||
- Approved progress
|
||||
- Phrases count
|
||||
- Phrases translated
|
||||
- Phrases approved
|
||||
- Words count
|
||||
- Words translated
|
||||
- Words approved
|
||||
|
||||
# Configuration
|
||||
|
||||
> Rename the ``config.json.example`` file to ``config.json``.
|
||||
|
||||
> Rename the ``.env.example`` file to ``.env``.
|
||||
|
||||
### Token
|
||||
|
||||
Replace ``YOUR_DISCORD_BOT_TOKEN_GOES_HERE`` by your discord bot token in the .env file.
|
||||
|
||||
### Project Name
|
||||
|
||||
Replace ``YOUR_PROJECT_NAME`` by your crowdin project name in the .env file.
|
||||
|
||||
### Login
|
||||
|
||||
Replace ``YOUR_USERNAME`` by your crowdin username in the .env file.
|
||||
|
||||
### Account Key
|
||||
|
||||
Replace ``YOUR_ACCOUNT_API_KEY`` by your crowdin account key in the .env file. (know how to get this key <a href="https://support.crowdin.com/account-settings/#api">here.</a>
|
||||
|
||||
### Status Channel
|
||||
|
||||
Put your channel id in the ``channel`` key in the config.json file.
|
||||
|
||||
### Edit Time
|
||||
|
||||
Put the time you want the bot to check and update with new data. (In millisecond) in the ``editTime`` key in the config.json file.
|
||||
|
||||
### Purge On Restart
|
||||
|
||||
Wether you want the bot to purge the status channel on start or not. Put true or false in the ``purgeOnRestart`` key in config.json file.
|
||||
|
||||
### Purge Amount
|
||||
|
||||
Put the amount of messages you want the bot to purge on restart in the ``purgeAmount`` key in the config.json file.
|
||||
|
||||
# TO DO
|
||||
|
||||
- Ability to see specific language status using a command
|
||||
|
||||
# Bugs and glitches
|
||||
|
||||
Feel free to report all bugs and glitches by creating an issue in the <a href="https://github.com/Mr-KayJayDee/discord-crowdin-status/issues">issue section.</a>
|
||||
|
||||
A correct and understandable issue contains :
|
||||
- Steps to reproduce
|
||||
- *Code that summonned the error (optional)*
|
||||
- The complete error
|
||||
|
||||
You can also join me on my <a href="https://discord.gg/Uqd2sQP">discord server.</a>
|
||||
|
||||
<a href="https://discord.gg/Uqd2sQP"><img src="https://discord.com/api/guilds/527836578912010251/widget.png" alt="Amandine support server"/></a>
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"channel": "XXXXXXXXXXXX", // the channel id where you want the status message to be"
|
||||
"editTime": 10000, // the time beetween two message edit (in ms)
|
||||
"purgeOnRestart": true, // wether to purge or not the status channel on restart
|
||||
"purgeAmount": 100 // the amount of messages to purge on start
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
const Discord = require(`discord.js`);
|
||||
const bot = new Discord.Client({
|
||||
disableEveryone: true,
|
||||
autoReconnect: true
|
||||
});
|
||||
const {
|
||||
promisify
|
||||
} = require(`util`);
|
||||
const readdir = promisify(require(`fs`).readdir);
|
||||
|
||||
require(`dotenv`).config();
|
||||
bot.login(process.env.TOKEN);
|
||||
|
||||
bot.config = require(`./config.json`);
|
||||
bot.commands = new Discord.Collection();
|
||||
bot.aliases = new Discord.Collection();
|
||||
|
||||
(async function() {
|
||||
const eventFiles = await readdir(`./Events/`);
|
||||
eventFiles.forEach(file => {
|
||||
const eventName = file.split(`.`)[0];
|
||||
const event = require(`./Events/${file}`);
|
||||
bot.on(eventName, event.bind(null, bot));
|
||||
delete require.cache[require.resolve(`./Events/${file}`)];
|
||||
});
|
||||
})();
|
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "discord-crowdin-status",
|
||||
"version": "1.0.0",
|
||||
"description": "A discord bot allowing you to see the status of your crowdin translations",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Mr¤KayJayDee <killian.dalcin@gmail.com> (https://github.com/Mr-KayJayDee)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Mr-KayJayDee/discord-crowdin-status.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Mr-KayJayDee/discord-crowdin-status/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Mr-KayJayDee/discord-crowdin-status#readme",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"superagent": "^6.1.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue