SocialvoidJS/examples/node/index.js

33 lines
690 B
JavaScript
Raw Normal View History

2021-10-11 12:18:05 +02:00
const { createInterface } = require("readline");
const { Client } = require("../../dist/mod.js");
const readline = createInterface({
2021-10-29 10:08:21 +02:00
input: process.stdin,
output: process.stdout,
2021-10-11 12:18:05 +02:00
});
const client = new Client();
function prompt(query) {
2021-10-29 10:08:21 +02:00
return new Promise((resolve) => {
readline.question(query + " ", resolve);
});
2021-10-11 12:18:05 +02:00
}
async function login() {
2021-10-29 10:08:21 +02:00
if (!client.sessionExists) {
await client.newSession();
}
2021-10-11 12:18:05 +02:00
2021-10-29 10:08:21 +02:00
const session = await client.session.get();
2021-10-11 12:18:05 +02:00
2021-10-29 10:08:21 +02:00
if (!session.authenticated) {
await client.session.authenticateUser(
prompt("Username:"),
prompt("Password:"),
prompt("OTP (if set):"),
);
}
2021-10-11 12:18:05 +02:00
}
2021-10-11 12:47:57 +02:00
module.exports = { client, login, prompt };