Skip to content

Commit

Permalink
Allow user to save the token if they wish
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoMagdaleno committed Jun 18, 2020
1 parent 91b7fb2 commit a286ef7
Show file tree
Hide file tree
Showing 5 changed files with 713 additions and 7 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
48 changes: 41 additions & 7 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const request = require('request-promise-native');
const inquirer = require('inquirer');
const ProgressBar = require('progress');
const Configstore = require('configstore');
const packageJson = require('./package.json');
const fs = require('fs');

const config = new Configstore(packageJson.name)

const ENDPOINT = 'https://discordapp.com/api/v6/';
var headers = {};
Expand Down Expand Up @@ -73,15 +78,44 @@ async function removeMessages(type, target, user){
}
}

async function getToken(){
if (fs.existsSync(config.path)){
token = config.get('token')
return token
} else {
var answers = await inquirer.prompt([{
'type': 'input',
'name': 'token',
'message': 'Token'
}])

var wantsToSave = await inquirer.prompt([{
'type': 'list',
'name': 'save',
'message': 'Would you like to save your token for later use?',
'choices': [{
'value': 'yes',
'name': 'Yes'
},
{
'value': 'no',
'name': 'No'
}]
}])
if (wantsToSave.save == 'yes'){
config.set('token', answers.token)
}
token = answers.token
return token
}
}

async function userInput() {
var answers = await inquirer.prompt([{
'type': 'input',
'name': 'token',
'message': 'Token'
}]);

let token = await getToken()

headers = {
'Authorization': answers.token
'Authorization': token
};

let user = JSON.parse(await request({
Expand Down Expand Up @@ -143,7 +177,7 @@ async function userInput() {

return x;
});

y
answers = await inquirer.prompt([
{
'type': 'list',
Expand Down
Loading

0 comments on commit a286ef7

Please sign in to comment.