diff options
Diffstat (limited to 'commands/info.js')
-rw-r--r-- | commands/info.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/commands/info.js b/commands/info.js new file mode 100644 index 0000000..d6d25b0 --- /dev/null +++ b/commands/info.js @@ -0,0 +1,78 @@ +const fs = require('fs'); +const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +function bytesToPretty(bytes) { + if (bytes > 1000) { + if (bytes > 1000000) { + return (bytes / 1000000).toFixed(2) + " MB"; + } else { + return (bytes / 1000).toFixed(2) + " KB"; + } + } else { + return bytes + " B"; + } +} + +function secondsToPretty(seconds) { + if (seconds > 60) { + if (seconds > 3600) { + if (seconds > 216000) { + return Math.floor(seconds / 216000) + " day" + (Math.floor(seconds / 216000) > 1 ? "s" : ""); + } else { + return Math.floor(seconds / 3600) + " hour" + (Math.floor(seconds / 3600) > 1 ? "s" : ""); + } + } else { + return Math.floor(seconds / 60) + " minute" + (Math.floor(seconds / 60) > 1 ? "s" : ""); + } + } else { + return Math.floor(seconds) + " second" + (Math.floor(seconds) > 1 ? "s" : ""); + } +} + +module.exports = async (interaction) => { + let suffix = ""; + if (official.includes(interaction.guild ? interaction.guild.id : 0)) { + suffix = ".official-" + (interaction.guild ? interaction.guild.id : 0); + } else { + if ((interaction.guild ? interaction.guild.id : 0) === fpserver) { + suffix = ".francoponies-epk" + fs.readFileSync("./config/fpexperience.txt").toString(); + } + } + + let size = 0; + for (let file of fs.readdirSync("./data")) size += fs.readFileSync("./data/" + file).length; + let sizep = bytesToPretty(size); + + let fields = [ + { name: l("Software version", "Version du logiciel", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "v" + fs.readFileSync("./config/version.txt") + "." + fs.readFileSync("./.git/refs/heads/trunk").toString().substr(0, 8) + suffix + " (#" + client.shard.count + ")", inline: false }, + { name: l("Kernel version", "Version du noyau", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: process.version, inline: true }, + { name: l("Experience channel", "Canal d'expériences", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: channel, inline: true }, + { name: l("Known ponies", "Poneys connus", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())).length.toString(), inline: true }, + { name: l("Awaiting issue reports", "Rapports de problèmes en attente", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: fs.readdirSync("./reports").length.toString(), inline: true }, + { name: l("Database size", "Taille de la base de données", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: sizep, inline: true }, + { name: l("Memory usage", "Utilisation de la mémoire", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: bytesToPretty(process.memoryUsage().rss + process.memoryUsage().heapTotal + process.memoryUsage().external + process.memoryUsage().arrayBuffers), inline: true }, + { name: l("Uptime", "Durée de fonctionnement", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: secondsToPretty(process.uptime()), inline: true }, + ]; + + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#d6dc28') + .setTitle(l("Bot stats", "Statistiques du robot", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Ponyfind is a Discord bot that helps you get easy and fast access to data relative to My Little Pony (generations 4 and 5).", "Ponyfind est un robot Discord qui vous aide à obtenir un accès simple et rapide à des données relatives à My Little Pony (générations 4 et 5).", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .addFields(fields) + .setFooter(l("made with ♥ by Minteck, a My Little Pony fan", "fait avec ♥ par Minteck, une fan de My Little Pony", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); +}
\ No newline at end of file |