From 1cda2e5af14b5911ffd01c946c678e6c9c13f718 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 23 Nov 2021 09:26:40 +0100 Subject: [PATCH] Remove servers and add proper error handling to command handler --- index.js | 47 ++--------------------------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/index.js b/index.js index 9b25c7c..bd8e240 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ const { Client, Intents } = require('discord.js'); -const express = require("express"); const crypto = require("crypto"); -const app = express(); const parser = require("body-parser"); app.use(parser.json()); 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 fs = require("fs"); 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{ log(msg){ @@ -98,33 +82,6 @@ client.on('ready', () => { 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 => { @@ -134,6 +91,7 @@ client.on('interactionCreate', async interaction => { try{ cmd.run(interaction, client, this); } 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(e); } @@ -154,5 +112,4 @@ client.on("messageCreate", (msg) => { } }); -client.login(process.env.TOKEN); -app.listen(3000); \ No newline at end of file +client.login(process.env.TOKEN); \ No newline at end of file