|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/* Before running: |
| 4 | + npm install twilio |
| 5 | +*/ |
| 6 | + |
| 7 | +var exec = require('child_process').exec; |
| 8 | + |
| 9 | +var me = 'my_username'; |
| 10 | + |
| 11 | +exec("who -q", function(error, stdout, stderr) { |
| 12 | + |
| 13 | + // Exit if no sessions with my username are found |
| 14 | + if(stdout.indexOf(me) == -1) |
| 15 | + process.exit(1); |
| 16 | + |
| 17 | + var TWILIO_ACCOUNT_SID = process.env['TWILIO_ACCOUNT_SID']; |
| 18 | + var TWILIO_AUTH_TOKEN = process.env['TWILIO_AUTH_TOKEN']; |
| 19 | + |
| 20 | + // Phone numbers |
| 21 | + var MY_NUMBER = '+xxx'; |
| 22 | + var HER_NUMBER = '+xxx'; |
| 23 | + |
| 24 | + // Reasons |
| 25 | + var reasons = [ |
| 26 | + 'Working hard', |
| 27 | + 'Gotta ship this feature', |
| 28 | + 'Someone fucked the system again' |
| 29 | + ]; |
| 30 | + |
| 31 | + // Generate BS message |
| 32 | + var reason = reasons[Math.floor(Math.random() * reasons.length)]; |
| 33 | + var textMessage = 'Late at work. ' + reason; |
| 34 | + |
| 35 | + var client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN); |
| 36 | + |
| 37 | + // Shoot text |
| 38 | + client.messages.create({ |
| 39 | + body: textMessage, |
| 40 | + to: HER_NUMBER, |
| 41 | + from: MY_NUMBER |
| 42 | + }, function(error, message) { |
| 43 | + if(error) |
| 44 | + console.log('Failed to send SMS: ' + error.message); |
| 45 | + else { |
| 46 | + var currentdate = new Date(); |
| 47 | + |
| 48 | + console.log('Message sent at: '+ (currentdate.getMonth() + 1) + '/' |
| 49 | + + currentdate.getDate() + '/' |
| 50 | + + currentdate.getFullYear() + ' ' |
| 51 | + + currentdate.getHours() + ':' |
| 52 | + + currentdate.getMinutes() + ':' |
| 53 | + + currentdate.getSeconds() + '| Excuse: ' + reason); |
| 54 | + } |
| 55 | + }); |
| 56 | +}); |
0 commit comments