-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfun.js
More file actions
104 lines (93 loc) · 2.74 KB
/
fun.js
File metadata and controls
104 lines (93 loc) · 2.74 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
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env node
var request = require('request');
var colors = require('colors');
var os = require('os');
var yargs = require('yargs');
const CFonts = require('cfonts');
var jokesstart ={
description: 'Start the joke',
alias: 'j',
demand:true
}
var nextjoke = {
description: 'Next joke',
alias: 'j',
demand: true
}
var textoption ={
description: 'Text to check sentiment',
alias: 't',
demand: true
}
var argv = yargs
.command('start','Start the jokes',{
jokes:jokesstart
})
.command('next','Next joke',{
joke: nextjoke
})
.command('check','Check sentiments of the sentence',{
text: textoption
})
.command('')
.help()
.argv;
/////////////////////////////////////////////////////
function jokes(){
request({
url: 'https://api.chucknorris.io/jokes/random',
json: true
},function(err,res,body){
var out = body.value;
console.log(colors.rainbow('Joke:-',out));
});
}
//////////////////////////////////////////////////////////////////////////
var pd = require('paralleldots');
pd.apiKey = '3sw7JbnMDKCZJaTaXnoQqoUoCUSgXDwdT70TXLONfmI';
function sentiment(){
console.log(argv.text);
pd.sentiment(argv.text,'en')
.then((response) => {
console.log(colors.green.bold('overall-' + JSON.parse(response).sentiment));
console.log(colors.red.bold('Probabilities:-'));
console.log(colors.green.bold('Positivity-'+JSON.parse(response).probabilities.positive));
console.log(colors.green.bold('Negativity-'+JSON.parse(response).probabilities.negative));
console.log(colors.green.bold('Neutral-'+JSON.parse(response).probabilities.neutral));
}).catch((error) =>{
console.log(error);
})
}
///////////////////////////////////////////////////////////////////////////
var command = argv._[0];
//////////////////////////////////////////////
//commands
if(command === 'start')
{
CFonts.say(`Hello|${os.userInfo().username}`, {
font: 'block', // define the font face
align: 'center', // define text alignment
colors: ['red'], // define all colors
background: 'black', // define the background color, you can also use `backgroundColor` here as key
letterSpacing: 1, // define letter spacing
lineHeight: 0.3, // define the line height
space: true, // define if the output text should have empty lines on top and on the bottom
maxLength: '13', // define how many character can be on one line
});
console.log( '\x1b[31m\x1b[1mWarning:\x1b[22m \x1b[93mJokes may makes \x1b[4m you\x1b[24m laugh.\x1b[0m' );
console.log('Jokes started..');
jokes();
}
else if(command === 'next')
{
console.log('Jokes loading...');
jokes();
}
else if(command ==='check')
{
sentiment();
}
else
{
console.log('Invalid command..');
}