Permalink
Browse files

Added readme.md

Added config.json.example
Now exiting process once rickrolling has completed.
Also, the game.
  • Loading branch information...
0 parents commit c69871abbbf68cc4e978eee07b7fb241ca222311 @emilyrose committed Jul 6, 2012
Showing with 214 additions and 0 deletions.
  1. +21 −0 config.json.example
  2. +22 −0 package.json
  3. +15 −0 readme.md
  4. +156 −0 rickroll.js
@@ -0,0 +1,21 @@
+{
+ "numbers" : {
+
+ "from" : ""
+ , "to" : [
+
+ ""
+ , ""
+ , ""
+ , ""
+ ]
+ }
+ , "play" : ""
+ , "accountSid" : ""
+ , "authToken" : ""
+ , "applicationSid" : ""
+ , "ports" : {
+
+ "app": 6666
+ }
+}
@@ -0,0 +1,22 @@
+{
+ "name": "rickrollio",
+ "version": "0.0.1",
+ "scripts": {
+ "start": "node server"
+ },
+ "dependencies": {
+ "express": "~3.0.0beta4",
+ "twilio-api": "~0.3.0",
+ "async": "~0.1.22"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "engines": {
+ "node": "0.8.x"
+ },
+ "author": "Emily Rose <emily@contactvibe.com>",
+ "description": "Rick-roll your friends (or strangers) with twilio!",
+ "repository": {
+ "url": ""
+ }
+}
@@ -0,0 +1,15 @@
+# rickrollio
+
+__rickroll your friends (or strangers) with twilio!__
+
+_a little package for the quick hack I wrote to troll everyone that gave me their number @ nodeconf 2012. have fun!_
+
+ Step 1) Open config.json.example, save it as config.json
+ Step 2) Add your accountSid, authToken, applicationSid, & play URL (audio file)
+ Step 3) Enter the phone numbers to be dialed (and your number)
+ Step 4) ????
+ Step 5) Profit. (run `node rickroll`)
+
+#### NOTE: numbers must be formatted properly. e.g. "+18008675309"
+
+You should see console.log output for the call durations once everyone has completed their roll (or rejected the call). You can now run statistics on the effectiveness of your trolling. ;3
@@ -0,0 +1,156 @@
+;(function() {
+
+ var fs = require('fs');
+
+ /**
+ * Load and verify configuration
+ */
+ var config = (function() {
+
+ try {
+
+ var buff = fs.readFileSync('./config.json');
+
+ var
+ conf = JSON.parse(buff)
+ , error = undefined
+ ;
+
+ if(!conf.accountSid) {
+
+ error = "Invalid accountSid";
+ }
+ else if((!conf.numbers) || !conf.numbers.from
+ || !conf.numbers.to) {
+
+ error = "Invalid number parameters";
+ }
+ else if(!conf.authToken) {
+
+ error = "Invalid authToken";
+ }
+ else if (!conf.applicationSid) {
+
+ error = "Invalid accountSid";
+ }
+ else if (!conf.play) {
+ error = "Invalid play URL";
+ }
+
+ if(error) {
+
+ console.log("config.json: %s\r\n", error);
+ process.exit(1);
+ }
+ }
+ catch (e) {
+
+ console.log("config.json: %s\r\n", e);
+ process.exit(2);
+ }
+
+ return conf;
+ })();
+
+ var
+ express = require('express')
+ , twilio = require('twilio-api')
+ , async = require('async')
+ , dnode = require('dnode')
+ , net = require('net')
+ , app = express.createServer()
+ , voiceActive = false // in a call
+ , twapp // twilio app
+ , cli = new twilio.Client(
+
+ config.accountSid
+ , config.authToken
+ )
+ ;
+
+ app.use(cli.middleware());
+ app.listen(config.ports.app);
+
+ cli.account.getApplication(config.applicationSid, function(err, twip) {
+
+ if(err) {
+
+ console.log(err);
+ return;
+ }
+
+ twapp = twip;
+ twip.register();
+ callEveryone("RICKROLL", function(err, res) {
+
+ if(err) { console.log(err); return; }
+ console.log("rickroll complete...");
+ console.log(res);
+ process.exit(0);
+ });
+ });
+
+ /**
+ * Alert everyone on the call list
+ */
+ var callEveryone = function callEveryone(id, done) {
+
+ var calls = [];
+
+ config.numbers.to.forEach(function(num) {
+
+ calls.push(getCaller(id, num));
+ });
+
+ async.parallel(calls, function(err, res) {
+
+ if(err) {
+
+ done(err, undefined);
+ return;
+ }
+
+ done(null, res);
+ });
+ };
+
+ /**
+ * Wrap a placeCall call with async callback
+ */
+ var getCaller = function getCaller(id, num) {
+
+ return function(cb) {
+
+ placeCall(id, num, cb);
+ }
+ };
+
+ /**
+ * Initiate a voice alert
+ */
+ var placeCall = function placeCall(id, num, cb) {
+
+ if(!num || typeof cb !== "function") {
+
+ console.log("Invalid placeCall parameters.");
+ return false;
+ }
+
+ twapp.makeCall(config.numbers.from, num, function(err, call) {
+
+ if(err) throw err;
+
+ call.on('connected', function(status) {
+
+ //Called when the caller picks up
+ call.play(config.play);
+ });
+
+ call.on('ended', function(status, duration) {
+
+ cb(null, status, duration);
+ });
+ });
+ };
+
+})();

0 comments on commit c69871a

Please sign in to comment.