-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
94 lines (83 loc) · 2.79 KB
/
main.js
File metadata and controls
94 lines (83 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env node
var codebits = require('codebits');
var prompt = require('prompt');
var colors = require('colors');
var fs = require('fs');
var doge = [
'wow ',
' such popularity ',
' much friendship ',
' amazing '];
console.log('\n -- To end your loneliness insert your username and password! -- \n'.bold.green);
prompt.message = "CODEBITS".green;
prompt.delimiter = ':'.bold.green;
prompt.start();
var schema =
{
properties:
{
username:
{
description: 'user_email'.bold.yellow,
required: true
},
password:
{
description: 'password'.bold.yellow,
hidden: true
}
}};
var schema_yesno = {
properties: {
answer : {
pattern: /^[y|Y][e|E][s|S]|[n|N][o|O]$/,
message: 'type yes or no'.bold.yellow,
required: true,
description: '(yes/no)'.bold.yellow
}
}
};
var promptUser = function(_schema) {
return prompt.get(_schema, function (err, result){
codebits.auth.logIn(result.username, result.password, function (err, token){
if(err){
console.log('**Something went wrong, try again**'.bold.red);
promptUser(schema);
}else{
if(typeof token === 'undefined'){
console.log('**Login FAILED! Try again**'.bold.red);
promptUser(schema);
}else{
var data = fs.readFileSync(__dirname + '/allthethings.txt', "utf8");
console.log(data.bold.yellow);
prompt.start();
prompt.get(schema_yesno, function (err, result){
if(err){
console.log('**Something went wrong, try again**'.bold.red);
console.log('\n...leaving :( \n\n'.bold.red);
}else{
if(result.answer == 'yes'){
console.log('\n \\o/ You are now the most popular person on codebits. Congratulations! /o/ \n'.bold.magenta);
console.log('\n ...adding all the friends... \n'.bold.green);
codebits.users.listAcceptedUsers( function (err, reply){
reply.forEach(function(entry){
codebits.users.addUserAsFriend(entry.id, function (err, reply){
var r = getRandomInt(0, 3);
process.stdout.write(doge[r] + '\r ');
});
});
});
}else{
console.log('You chose to leave.. goodbye!'.bold.green);
}
}
});
}
}
});
});
};
promptUser(schema);
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}