From 22928e3f9c91f6d7dcbdb6d6442de0026ba5bca9 Mon Sep 17 00:00:00 2001 From: raven Date: Thu, 12 Jan 2023 23:51:24 -0500 Subject: [PATCH] Adding discord IDs --- commands/login.js | 19 +++++++++++++++---- node | 0 sshChat.js | 25 +++++++++++++++++++------ 3 files changed, 34 insertions(+), 10 deletions(-) delete mode 100644 node diff --git a/commands/login.js b/commands/login.js index 574ca4e..683b4d1 100644 --- a/commands/login.js +++ b/commands/login.js @@ -1,16 +1,20 @@ var unirest = require('unirest'); -async function login(key, conns, MYKEY, USERNAME) { +async function login(key, conns, MYKEY, USERNAME, DISCORD_USERID) { getUSERNAME(key) .then((data) => { console.log("Hello, " + data + "\nYou are now logged in.\n\n\n") USERNAME[0] = data MYKEY.push(key) LOGGEDIN = true + getDISCORDID(key) + .then((discord) => { + DISCORD_USERID[0] = [discord] for (const conn of conns) { - conn.write(`${USERNAME} is now logged in.`) + conn.write(`${USERNAME} | <@${discord}> is now logged in.`) } }) + }) .catch(err => { console.log("Invalid Key") for (const conn of conns) { @@ -23,9 +27,16 @@ async function login(key, conns, MYKEY, USERNAME) { // API Functions async function getUSERNAME(key) { let requestUSERNAME = await unirest - .get('https://api.discord-linux.com/hello') + .get('https://api.discord-linux.com/name') .headers({ 'Accept': 'application/json', 'Content-Type': 'application/json', 'x-discord-linux-auth': key }) - return requestUSERNAME.body.message.replace("Hello, ", "").replace("!", "") + return requestUSERNAME.body.message + } + + async function getDISCORDID(key) { + let requestUSERNAME = await unirest + .get('https://api.discord-linux.com/discordid') + .headers({ 'Accept': 'application/json', 'Content-Type': 'application/json', 'x-discord-linux-auth': key }) + return requestUSERNAME.body.message } module.exports = { login } \ No newline at end of file diff --git a/node b/node deleted file mode 100644 index e69de29..0000000 diff --git a/sshChat.js b/sshChat.js index e80fb88..176c861 100644 --- a/sshChat.js +++ b/sshChat.js @@ -25,6 +25,7 @@ let MYKEY = [] let conns = [] let connectedUsers = []; let USERNAME = ["annon" + rand] +let DISCORD_USERID = [] function sleep(ms) { return new Promise((resolve) => { @@ -179,7 +180,7 @@ async function handleCommand(input) { start(MYKEY[0]) break; case ">login": - login(command[1], conns, MYKEY, USERNAME) + login(command[1], conns, MYKEY, USERNAME, DISCORD_USERID) break; case ">exit": console.log("Sending close message...") @@ -194,12 +195,24 @@ async function handleCommand(input) { console.log("Command not found.") } } else { - for (const conn of conns) + if (DISCORD_USERID.length !== 0){ + for (const conn of conns) + conn.write(`${DISCORD_USERID[0]}: ${input}`) + } else { + for (const conn of conns) + conn.write(`${USERNAME}: ${input}`) + } + if (DISCORD_USERID.length !== 0){ + console.log(`${DISCORD_USERID[0]}: ${input}`) + } else { + console.log(`${USERNAME}: ${input}`) + } + + + } - conn.write(`${USERNAME[0]}: ${input}`) - - } - console.log(`${USERNAME[0]}: ${input}`) + + } swarm.on('connection', conn => {