1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* MIT License
*
* Copyright (c) 2022- Minteck
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
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 series = JSON.parse(fs.readFileSync("./data/series.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, uid, gid) {
if (bytes > 1000) {
if (bytes > 1000000) {
return (bytes / 1000000).toFixed(2) + " " + l("MB", "Mo", uid, gid);
} else {
return (bytes / 1000).toFixed(2) + " " + l("KB", "Ko", uid, gid);
}
} else {
return bytes + " " + l("B", "o", uid, gid);
}
}
function secondsToPretty(seconds, uid, gid) {
if (seconds > 60) {
if (seconds > 3600) {
if (seconds > 86400) {
return Math.floor(seconds / 86400) + " " + l("day", "jour", uid, gid) + (Math.floor(seconds / 86400) > 1 ? "s" : "");
} else {
return Math.floor(seconds / 3600) + " " + l("hour", "heure", uid, gid) + (Math.floor(seconds / 3600) > 1 ? "s" : "");
}
} else {
return Math.floor(seconds / 60) + " minute" + (Math.floor(seconds / 60) > 1 ? "s" : "");
}
} else {
return Math.floor(seconds) + " " + l("second", "seconde", uid, gid) + (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-exp" + 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 statsCommand = "-";
let statsCommandUsage = "n/a";
let statsCommandsP = statsCommands
try { delete statsCommandsP["eval"]; } catch (e) {}
try {
statsCommand = Object.keys(statsCommandsP).filter(i => i !== "_total").reduce((a, b) => statsCommandsP[a] > statsCommandsP[b] ? a : b);
statsCommandUsage = statsCommandsP[Object.keys(statsCommandsP).reduce((a, b) => statsCommandsP[a] > statsCommandsP[b] ? a : b)].toString();
} catch (e) {
console.error(e);
}
let statsPony = "-";
let statsPonyUsage = "n/a";
try {
statsPony = Object.keys(statsPonies).reduce((a, b) => statsPonies[a] > statsPonies[b] ? a : b);
statsPonyUsage = statsPonies[Object.keys(statsPonies).reduce((a, b) => statsPonies[a] > statsPonies[b] ? a : b)].toString();
} catch (e) {
console.error(e);
}
let statsEpisode = "-";
let statsEpisodeUsage = "n/a";
try {
let statsEpisodeParts = Object.keys(statsEpisodes).reduce((a, b) => statsEpisodes[a] > statsEpisodes[b] ? a : b).split("-");
statsEpisode = series.filter(i => i.command.toLowerCase() === statsEpisodeParts[0].toLowerCase())[0].seasons.filter(i => i.id === statsEpisodeParts[1])[0].episodes.filter(i => i.local === statsEpisodeParts[2])[0].name;
statsEpisodeUsage = statsEpisodes[Object.keys(statsEpisodes).reduce((a, b) => statsEpisodes[a] > statsEpisodes[b] ? a : b)].toString();
} catch (e) {
console.error(e);
}
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").toString().trim() + "." + fs.readFileSync("./.git/refs/heads/trunk").toString().substring(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("Most used command", "Commande la plus utilisée", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "`/" + statsCommand + "`\n(" + l("used " + statsCommandUsage + " times", "utilisée " + statsCommandUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true },
{ name: l("Most viewed pony", "Poney le plus consulté", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: statsPony + "\n(" + l("viewed " + statsPonyUsage + " times", "consulté " + statsPonyUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true },
{ name: l("Most viewed episode", "Épisode le plus consulté", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: statsEpisode + "\n(" + l("viewed " + statsEpisodeUsage + " times", "consulté " + statsEpisodeUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", 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, interaction.user.id, interaction.guild ? interaction.guild.id : 0), inline: true },
{ name: l("Uptime", "Durée de fonctionnement", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: secondsToPretty(process.uptime(), interaction.user.id, interaction.guild ? interaction.guild.id : 0), 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({text: 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)})
],
components: [
new MessageActionRow()
.addComponents(
new MessageButton()
.setStyle("LINK")
.setURL("https://gitlab.minteck.org/minteck/ponyfind")
.setLabel(l("Source Code", "Code source", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
)
.addComponents(
new MessageButton()
.setStyle("LINK")
.setURL("https://minteck.org/legal/#/privacy")
.setLabel(l("Data Privacy", "Politique de confidentialité", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
)
.addComponents(
new MessageButton()
.setStyle("LINK")
.setURL("https://minteck.org/legal/#/terms")
.setLabel(l("Terms and Conditions", "Conditions d'utilisation", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
)
]
});
}
|