Remove servers and add proper error handling to command handler

This commit is contained in:
= 2021-11-23 09:26:40 +01:00
parent 0d419311f8
commit 1cda2e5af1

View file

@ -1,7 +1,5 @@
const { Client, Intents } = require('discord.js'); const { Client, Intents } = require('discord.js');
const express = require("express");
const crypto = require("crypto"); const crypto = require("crypto");
const app = express();
const parser = require("body-parser"); const parser = require("body-parser");
app.use(parser.json()); app.use(parser.json());
app.use(parser.urlencoded({extended: false})); app.use(parser.urlencoded({extended: false}));
@ -10,20 +8,6 @@ const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_
const load = require("load-slash-commands"); const load = require("load-slash-commands");
const fs = require("fs"); const fs = require("fs");
var commands = []; var commands = [];
const ws = require("ws");
const server = new ws.Server({port: 443});
var connections = [];
server.on("connection", (conn) => {
console.log("Connection.");
connections.push(conn);
conn.on("close", () => {
connections.splice(connections.indexOf(conn), 1);
});
conn.on("error", () => {});
});
server.on("listening", () => {console.log("LIstening!!!")});
class Logger{ class Logger{
log(msg){ log(msg){
@ -98,33 +82,6 @@ client.on('ready', () => {
loadCommands(yes); loadCommands(yes);
}); });
*/ */
app.get("/", (req, res) => {
res.sendFile(__dirname + "/panel/index.html");
});
app.get("/index.js", (req, res) => {
res.sendFile(__dirname + "/panel/index.js");
});
app.get("/login", (req, res) => {
res.sendFile(__dirname + "/panel/login.html");
});
app.get("/login.js", (req, res) => {
res.sendFile(__dirname + "/panel/login.js");
});
app.post("/api/login", (req, res) => {
var pubHash = crypto.createHash("sha256");
pubHash.update(req.body);
var pub = pubHash.digest("hex");
var auth = JSON.parse(fs.readFileSync("auth.json").toString());
var userObj = null;
Object.keys(auth.users).forEach(user => {
if(auth.users[user] == pub) userObj = {user, token: auth.users[user]}
});
if(userObj === null){
res.json({success: false});
} else{
res.json({success: true, user: userObj});
}
});
}); });
client.on('interactionCreate', async interaction => { client.on('interactionCreate', async interaction => {
@ -134,6 +91,7 @@ client.on('interactionCreate', async interaction => {
try{ try{
cmd.run(interaction, client, this); cmd.run(interaction, client, this);
} catch(e){ } catch(e){
interaction.reply("An error occured whilst attempting to run this command: " + e.stack);
console.log("An error occured whilst attempting to run a command:"); console.log("An error occured whilst attempting to run a command:");
console.log(e); console.log(e);
} }
@ -155,4 +113,3 @@ client.on("messageCreate", (msg) => {
}); });
client.login(process.env.TOKEN); client.login(process.env.TOKEN);
app.listen(3000);