Jump to content
Sign in to follow this  
Popey456963

Strawpoll Creator

Recommended Posts

Thought I hadn't programmed anything for a while, so should probably do something. I made a straw poll program to quickly create map lists. To use, you need Node and the required Node packages, you simply run the file, type in whether you'd like active or all, and it will give you a URL back.

var concat = require('concat-stream');
var JSONStream = require('JSONStream');
var strawpoll = require('strawpoll');
var prompt = require('prompt');

prompt.start();

prompt.get(['type'], function (err, result) {
  if (err) { return onErr(err); }
  makeStraw(result.type);
});

function onErr(err) {
  console.log(err);
  return 1;
}

function makeStraw(polltype) {
  var array = [];
  if (polltype === "active") {
    array = ['Cache','Cobblestone','Dust II','Inferno','Mirage','Overpass','Train'];
  } else if (polltype === 'reserve') {
    array = ['Aztec','Cache','Cobblestone','Dust','Dust II','Inferno','Mirage','Nuke','Overpass','Train','Vertigo'];    
  } else if (typeof(polltype) === Array) {
    array = polltype.split(",");
  }
  var stream = strawpoll({
    title: 'What Map?',
    options: array,
    multi: false,
    permissive: false
  })
    .pipe(JSONStream.parse('id'))
    .pipe(concat(function(id) {
      console.log("http://strawpoll.me/" + id.toString());
    }));
}

Crappy Example:

a204813192.png

Edited by Guest

Share this post


Link to post

Nifty and helpful little code. +1

Hard coded values for the maps, what if valve add more? -1

limited to only active or inactive maps, what if you want to mix and match? -1

-1 for a string comparison in JavaScript (I am assuming).

-1 for terrible bracket indentation.

-3. Boo Popey ;)

Share this post


Link to post
Hard coded values for the maps, what if valve add more? -1

Fixed in latest version with option to add your own.

limited to only active or inactive maps, what if you want to mix and match? -1

Again, fixed in latest version.

-1 for a string comparison in JavaScript (I am assuming).

Fine, I'll use type comparison, if I really must... (fixed)

-1 for terrible bracket indentation.

What do you have against my bracket indentation? It's beautttiffull. In all serious, because of Node making use of so many stupid anonymous functions and all that, you have to have some weird bits like:

  })
    .pipe(JSONStream.parse('id'))
    .pipe(concat(function(id) {
      console.log("http://strawpoll.me/" + id.toString());
    }));

And if you're talking about the indentation for the JavaScript if statement, it's the syntax used everywhere else...

if (condition1) {
    block of code to be executed if condition1 is true
} else if (condition2) {
    block of code to be executed if the condition1 is false and condition2 is true
} else {
    block of code to be executed if the condition1 is false and condition2 is false
}

Thanks for the constructive criticism Skeff, always good =)

Share this post


Link to post
popey always coding, such a busy man :P Maybe this will be good for gathers when deciding on maps :P

As an update to this, what you could code is a 2-way VETO process generator. So, one team / one captain can pick maps to remove and keep on each team.

have the option for a BO1 / BO3 / BO5. This would be great for gathers, as then its more on fair maps for the team that picks the map as a team choice.

There's something for you to do :D

However, I like the response that it receives with the link. I guess you could add the results link just under too, which wouldn't be much more to add at all ^.^

Share this post


Link to post

And if you're talking about the indentation for the JavaScript if statement, it's the syntax used everywhere else...

if (condition1) {
    block of code to be executed if condition1 is true
} else if (condition2) {
    block of code to be executed if the condition1 is false and condition2 is true
} else {
    block of code to be executed if the condition1 is false and condition2 is false
}

This is generally considered to be an American indentation. It should be as follows:

if (condition1)
{
    //Foo
}
else if (condition2)
{
    //Bar
}
else
{
    //Baz
}

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...