73 lines
2.9 KiB
JavaScript
73 lines
2.9 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const discord_js_1 = require("discord.js");
|
|
const fs = __importStar(require("fs"));
|
|
const api_1 = require("./api");
|
|
const discord_1 = require("./discord");
|
|
const queue_1 = require("./queue");
|
|
const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GUILDS] });
|
|
//init logs with a timestamp
|
|
console.log(new Date().toISOString() + '\n\n');
|
|
//get token
|
|
if (!fs.existsSync('./token')) {
|
|
fs.writeFileSync('./token', '');
|
|
console.error('Missing Discord Token, please enter the bot token into the token file');
|
|
process.exit(1);
|
|
}
|
|
const TOKEN = fs.readFileSync('./token').toString();
|
|
//discord connections
|
|
CLIENT.on('ready', client => {
|
|
console.log(`Logged in as ${client.user.tag}`);
|
|
client.guilds.fetch().then(guilds => (0, discord_1.registerCommands)(TOKEN, client.user.id, guilds.map(g => g.id)));
|
|
});
|
|
CLIENT.on('interactionCreate', async (interaction) => {
|
|
if (!interaction.isCommand())
|
|
return;
|
|
try {
|
|
if (interaction.commandName === 'queue')
|
|
await (0, queue_1.createQueue)(interaction);
|
|
else if (interaction.commandName === 'join')
|
|
await (0, queue_1.joinQueue)(interaction);
|
|
else if (interaction.commandName === 'leave')
|
|
await (0, queue_1.leaveQueue)(interaction);
|
|
else if (interaction.commandName === 'ready')
|
|
await (0, queue_1.readyQueue)(interaction);
|
|
else if (interaction.commandName === 'cancel')
|
|
await (0, queue_1.cancelQueue)(interaction);
|
|
else if (interaction.commandName === 'queueinfo')
|
|
await (0, queue_1.queueInfo)(interaction);
|
|
else if (interaction.commandName === 'elo')
|
|
await (0, api_1.getPlayerInteraction)(interaction);
|
|
}
|
|
catch (e) {
|
|
if (typeof e === 'string') {
|
|
if (interaction.deferred || interaction.replied)
|
|
interaction.editReply(e);
|
|
else
|
|
interaction.reply(e);
|
|
}
|
|
else
|
|
console.error(e);
|
|
}
|
|
});
|
|
CLIENT.login(TOKEN);
|