aboutsummaryrefslogtreecommitdiff
path: root/handler/command.js
blob: 9733e6cb42f3ab18bf6c39f751e64524807f4cd7 (plain)
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
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();

const commandRandom = require('../commands/random');
const commandInfo = require('../commands/info');
const commandEval = require('../commands/eval');
const commandConfig = require('../commands/config');
const commandPony = require('../commands/pony');
const commandEpisode = require('../commands/episode');
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;
    }
    statsCommands["_total"] = Object.keys(statsCommands).filter(i => i !== "_total").map(i => statsCommands[i]).reduce((a, b) => a + b);
    fs.writeFile("./stats/commands.json", JSON.stringify(statsCommands), () => {});

    if (statsHour[new Date().getUTCHours().toString()] === undefined) {
        statsHour[new Date().getUTCHours().toString()] = {};
    }
    if (statsHour[new Date().getUTCHours().toString()][interaction.commandName] !== undefined) {
        statsHour[new Date().getUTCHours().toString()][interaction.commandName]++;
    } else {
        statsHour[new Date().getUTCHours().toString()][interaction.commandName] = 1;
    }
    statsHour[new Date().getUTCHours().toString()]["_total"] = Object.keys(statsHour[new Date().getUTCHours().toString()]).filter(i => i !== "_total").map(i => statsHour[new Date().getUTCHours().toString()][i]).reduce((a, b) => a + b);
    fs.writeFile("./stats/by-hour.json", JSON.stringify(statsHour), () => {});

    if (statsDay[new Date().getUTCDay().toString()] === undefined) {
        statsDay[new Date().getUTCDay().toString()] = {};
    }
    if (statsDay[new Date().getUTCDay().toString()][interaction.commandName] !== undefined) {
        statsDay[new Date().getUTCDay().toString()][interaction.commandName]++;
    } else {
        statsDay[new Date().getUTCDay().toString()][interaction.commandName] = 1;
    }
    statsDay[new Date().getUTCDay().toString()]["_total"] = Object.keys(statsDay[new Date().getUTCDay().toString()]).filter(i => i !== "_total").map(i => statsDay[new Date().getUTCDay().toString()][i]).reduce((a, b) => a + b);
    fs.writeFile("./stats/by-day.json", JSON.stringify(statsDay), () => {});

    if (statsDate[new Date().toISOString().split("T")[0]] === undefined) {
        statsDate[new Date().toISOString().split("T")[0]] = {};
    }
    if (statsDate[new Date().toISOString().split("T")[0]][interaction.commandName] !== undefined) {
        statsDate[new Date().toISOString().split("T")[0]][interaction.commandName]++;
    } else {
        statsDate[new Date().toISOString().split("T")[0]][interaction.commandName] = 1;
    }
    statsDate[new Date().toISOString().split("T")[0]]["_total"] = Object.keys(statsDate[new Date().toISOString().split("T")[0]]).filter(i => i !== "_total").map(i => statsDate[new Date().toISOString().split("T")[0]][i]).reduce((a, b) => a + b);
    fs.writeFile("./stats/by-date.json", JSON.stringify(statsDate), () => {});

    if (interaction.commandName === 'random') {
        await commandRandom(interaction);
    }

    if (interaction.commandName === 'help') {
        await commandHelp(interaction);
    }

    if (interaction.commandName === 'info') {
        await commandInfo(interaction);
    }

    if (interaction.commandName === 'eval') {
        await commandEval(interaction);
    }

    if (interaction.commandName === 'config') {
        await commandConfig(interaction);
    }

    if (interaction.commandName === 'pony') {
        await commandPony(interaction);
    }

    if (interaction.commandName === 'episode') {
        await commandEpisode(interaction);
    }
}