diff options
-rw-r--r-- | bot.js | 17 | ||||
-rw-r--r-- | commands/pony.js | 10 | ||||
-rw-r--r-- | handler/button.js | 7 | ||||
-rw-r--r-- | handler/command.js | 8 | ||||
-rw-r--r-- | handler/menu.js | 7 |
5 files changed, 45 insertions, 4 deletions
@@ -12,6 +12,12 @@ if (!fs.existsSync("./user/userdata.json")) fs.writeFileSync("./user/userdata.js if (!fs.existsSync("./user/spoilers.json")) fs.writeFileSync("./user/spoilers.json", "{}"); if (!fs.existsSync("./user/servers.json")) fs.writeFileSync("./user/servers.json", "{}"); if (!fs.existsSync("./reports")) fs.mkdirSync("./reports"); +if (!fs.existsSync("./stats")) fs.mkdirSync("./stats"); +if (!fs.existsSync("./stats/commands.json")) fs.writeFileSync("./stats/commands.json", "{}"); +if (!fs.existsSync("./stats/ponies.json")) fs.writeFileSync("./stats/ponies.json", "{}"); +if (!fs.existsSync("./stats/buttons.json")) fs.writeFileSync("./stats/buttons.json", "{}"); +if (!fs.existsSync("./stats/menu.json")) fs.writeFileSync("./stats/menu.json", "{}"); +if (!fs.existsSync("./stats/queries.json")) fs.writeFileSync("./stats/queries.json", "{}"); const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./config/token." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString()); const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js'); @@ -25,9 +31,14 @@ const buttonHandler = require('./handler/button'); const menuHandler = require('./handler/menu'); const errorHandler = require('./handler/errors'); -global.langs = JSON.parse(fs.readFileSync("./user/userdata.json")); -global.spoils = JSON.parse(fs.readFileSync("./user/spoilers.json")); -global.servers = JSON.parse(fs.readFileSync("./user/servers.json")); +global.langs = JSON.parse(fs.readFileSync("./user/userdata.json").toString()); +global.spoils = JSON.parse(fs.readFileSync("./user/spoilers.json").toString()); +global.servers = JSON.parse(fs.readFileSync("./user/servers.json").toString()); +global.statsCommands = JSON.parse(fs.readFileSync("./stats/commands.json").toString()); +global.statsPonies = JSON.parse(fs.readFileSync("./stats/ponies.json").toString()); +global.statsButtons = JSON.parse(fs.readFileSync("./stats/buttons.json").toString()); +global.statsMenu = JSON.parse(fs.readFileSync("./stats/menu.json").toString()); +global.statsQueries = JSON.parse(fs.readFileSync("./stats/queries.json").toString()); global.cooldowns = {}; global.l = (en, fr, id, gid) => { diff --git a/commands/pony.js b/commands/pony.js index f15e732..1cd6006 100644 --- a/commands/pony.js +++ b/commands/pony.js @@ -12,10 +12,18 @@ const official = fs.readFileSync("./config/official.txt").toString().replace(/\r const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); module.exports = async (interaction) => { - query = interaction.options.getString('query'); + query = interaction.options.getString('query').toLowerCase(); result = getResult(query); if (result.results.length > 0 && getEmbed(result.results[0], interaction.user.id, interaction.guild ? interaction.guild.id : 0) !== false) { + if (statsQueries[result.results[0]] !== undefined) { + if (!statsQueries[result.results[0]].includes(query)) { + statsQueries[result.results[0]].push(query); + } + } else { + statsQueries[result.results[0]] = [ query ]; + } + fs.writeFile("./stats/queries.json", JSON.stringify(statsQueries), () => {}); if (result.results[0].toLowerCase().trim() === query.toLowerCase().trim()) { keys = [null, result.results[0]]; if (interaction.guild) { diff --git a/handler/button.js b/handler/button.js index 30a8e58..7f5893f 100644 --- a/handler/button.js +++ b/handler/button.js @@ -7,6 +7,13 @@ const getEmbed = require("../modules/embed"); module.exports = async (interaction) => {
keys = interaction.customId.split("|")
+ console.log(interaction.user.tag + " (" + interaction.user.id + ") pressed button " + keys[0]);
+ if (statsButtons[keys[0]] !== undefined) {
+ statsButtons[keys[0]]++;
+ } else {
+ statsButtons[keys[0]] = 1;
+ }
+ fs.writeFile("./stats/buttons.json", JSON.stringify(statsButtons), () => {});
if (keys[0] === "pony.display") {
let row;
diff --git a/handler/command.js b/handler/command.js index 1447332..3869c6d 100644 --- a/handler/command.js +++ b/handler/command.js @@ -19,6 +19,14 @@ const commandPony = require('../commands/pony'); const commandHelp = require('../commands/help');
module.exports = async (interaction) => {
+ console.log(interaction.user.tag + " (" + interaction.user.id + ") used command /" + interaction.commandName);
+ if (statsCommands[interaction.commandName] !== undefined) {
+ statsCommands[interaction.commandName]++;
+ } else {
+ statsCommands[interaction.commandName] = 1;
+ }
+ fs.writeFile("./stats/commands.json", JSON.stringify(statsCommands), () => {});
+
if (interaction.commandName === 'random') {
await commandRandom(interaction);
}
diff --git a/handler/menu.js b/handler/menu.js index 6552735..1102b9e 100644 --- a/handler/menu.js +++ b/handler/menu.js @@ -3,6 +3,13 @@ const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = req module.exports = async (interaction) => {
keys = interaction.values[0].split("|")
+ console.log(interaction.user.tag + " (" + interaction.user.id + ") selected menu item " + keys[0]);
+ if (statsMenu[keys[0]] !== undefined) {
+ statsMenu[keys[0]]++;
+ } else {
+ statsMenu[keys[0]] = 1;
+ }
+ fs.writeFile("./stats/menu.json", JSON.stringify(statsMenu), () => {});
if (keys[0].startsWith("report.issue.")) {
item = keys[0].substr(13)
|