From 3e7bb04b4a60201c4b52b30e3e8627ef09116a2b Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 11:56:02 -0500 Subject: [PATCH] NodeJS Implementation --- nodejs/fucking_coffee.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 nodejs/fucking_coffee.js diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js new file mode 100644 index 0000000..6e0b00e --- /dev/null +++ b/nodejs/fucking_coffee.js @@ -0,0 +1,40 @@ +/* Before running: + npm install telnet-client +*/ + +var exec = require('child_process').exec; +var telnet = require('telnet-client') + +var me = 'my_username' + +exec("who", function(error, stdout, stderr) { + + // Exit if no sessions with my username are found + if(stdout.indexOf(me) == -1) + process.exit(/*1*/) + + var coffee_machine_ip = '10.10.42.42' + var password = '1234' + var cmd = 'Password: ' + password + var con = new telnet() + + con.on('ready', function(prompt) { + con.exec(cmd, function(error, res) { + + // Brew Coffee! + con.exec('sys brew', function(error, res) { + + // Wait for 24s + setTimeout(function() { + + // Pour Coffee! + con.exec('sys pour', function(error, res) { + con.end() + }) + }, 24000); + }) + }) + }) + + con.connect({host: coffee_machine_ip}) +});