k44Eqha/main.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-10-22 05:48:50 +02:00
require("dotenv").config();
require('./util');
2018-07-14 05:29:41 +02:00
global.config = require('./config');
if (config.testmode) console.log('TEST MODE');
2018-05-12 07:19:31 +02:00
global.exitHook = require('async-exit-hook');
global.Discord = require('discord.js');
global.fs = require('fs');
2022-01-04 05:40:43 +01:00
global.dClient = new Discord.Client({
intents: 32767,
2022-01-04 06:31:34 +01:00
restRequestTimeout: 5*60*1000,
allowedMentions: {parse: []}
2022-01-04 05:40:43 +01:00
});
2018-05-12 07:19:31 +02:00
2018-08-14 08:10:31 +02:00
// error handling
{
2022-01-04 06:31:34 +01:00
let webhook = new Discord.WebhookClient({url: config.webhooks.error, allowedMentions: {parse: []}});
2022-01-04 05:40:43 +01:00
global.handleError = function logError(error, title) {
2018-08-31 00:45:23 +02:00
let msg = error && (error.stack || error.message || error);
2022-01-04 05:40:43 +01:00
console.error(title + ':\n' + msg);
2018-08-14 08:10:31 +02:00
try {
webhook.send(`${title ? `**${title}:**` : ""}\`\`\`\n${msg}\n\`\`\``).catch(()=>{});
2018-08-14 08:10:31 +02:00
} catch(e) {}
}
2022-01-04 05:40:43 +01:00
process.on('unhandledRejection', error => handleError(error, "Unhandled Rejection"));
exitHook.uncaughtExceptionHandler(error => handleError(error, "Uncaught Exception"));
dClient.on('error', error => handleError(error, "Discord Client Error"));
dClient.on('warn', error => handleError(error, "Discord Client Warning"));
2018-08-14 08:10:31 +02:00
}
2022-01-04 04:04:16 +01:00
dClient.login(config.DISCORD_TOKEN);
2018-05-12 07:19:31 +02:00
dClient.once('ready', () => {
console.log('Discord Client Ready');
2022-01-04 07:26:27 +01:00
require('./eval-exec');
2022-01-04 04:21:13 +01:00
require('./mppbridger');
require('./misc');
2018-11-05 08:03:31 +01:00
require('./ddpbridge');
2019-07-02 02:23:24 +02:00
require('./prbridge');
2018-05-12 07:19:31 +02:00
2018-08-31 00:45:23 +02:00
});