Skip to content

Commit 4518052

Browse files
committed
Merge pull request NARKOZ#86 from kashyapakshay/master
NodeJS Implementation
2 parents 17a16a7 + 3ba1206 commit 4518052

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

nodejs/fucking_coffee.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
3+
/* Before running:
4+
npm install telnet-client
5+
*/
6+
7+
var exec = require('child_process').exec;
8+
var telnet = require('telnet-client');
9+
10+
var me = 'my_username';
11+
12+
exec("who", function(error, stdout, stderr) {
13+
14+
// Exit if no sessions with my username are found
15+
if(stdout.indexOf(me) == -1)
16+
process.exit(/*1*/);
17+
18+
var coffee_machine_ip = 'xxx.xxx.xxx.xxx';
19+
var password = 'xxxx';
20+
var con = new telnet();
21+
22+
con.on('ready', function(prompt) {
23+
con.exec('Password: ' + password, function(error, res) {
24+
25+
// Brew Coffee!
26+
con.exec('sys brew', function(error, res) {
27+
28+
// Wait for 24s
29+
setTimeout(function() {
30+
31+
// Pour Coffee!
32+
con.exec('sys pour', function(error, res) {
33+
con.end();
34+
});
35+
}, 24000);
36+
});
37+
});
38+
});
39+
40+
con.connect({host: coffee_machine_ip});
41+
});

0 commit comments

Comments
 (0)