sshChat-CLI/commands/login.js

42 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2023-01-11 20:48:57 +00:00
var unirest = require('unirest');
2023-01-13 04:51:24 +00:00
async function login(key, conns, MYKEY, USERNAME, DISCORD_USERID) {
2023-01-11 20:48:57 +00:00
getUSERNAME(key)
.then((data) => {
console.log("Hello, " + data + "\nYou are now logged in.\n\n\n")
2023-01-12 15:29:32 +00:00
USERNAME[0] = data
2023-01-11 20:48:57 +00:00
MYKEY.push(key)
LOGGEDIN = true
2023-01-13 04:51:24 +00:00
getDISCORDID(key)
.then((discord) => {
DISCORD_USERID[0] = [discord]
2023-01-11 20:48:57 +00:00
for (const conn of conns) {
2023-01-13 04:51:24 +00:00
conn.write(`${USERNAME} | <@${discord}> is now logged in.`)
2023-01-11 20:48:57 +00:00
}
})
2023-01-13 04:51:24 +00:00
})
2023-01-11 20:48:57 +00:00
.catch(err => {
console.log("Invalid Key")
for (const conn of conns) {
conn.write("Invalid Key, please try again.")
}
})
}
// API Functions
async function getUSERNAME(key) {
let requestUSERNAME = await unirest
2023-01-13 04:51:24 +00:00
.get('https://api.discord-linux.com/name')
.headers({ 'Accept': 'application/json', 'Content-Type': 'application/json', 'x-discord-linux-auth': key })
return requestUSERNAME.body.message
}
async function getDISCORDID(key) {
let requestUSERNAME = await unirest
.get('https://api.discord-linux.com/discordid')
2023-01-11 20:48:57 +00:00
.headers({ 'Accept': 'application/json', 'Content-Type': 'application/json', 'x-discord-linux-auth': key })
2023-01-13 04:51:24 +00:00
return requestUSERNAME.body.message
2023-01-11 20:48:57 +00:00
}
module.exports = { login }