aboutsummaryrefslogtreecommitdiff
path: root/handler/command.js
blob: 1179701ea58ed2ecb10dc4bb40521116f0b3f7b5 (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
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
/*
 * 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 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 commandColor = require('../commands/color');
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 === 'color') {
        await commandColor(interaction);
    }

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