So I got bored and actually wrote something of some value:

Code:
/strawpoll [-mp] <title> options:<optionA>,<optionB>,...
    called as a command

$strawpoll(-mp <title> options:<optionA>,<optionB>,...)
    called as an identifer (put inputs into a variable and then pass the variable to the alias)

-m:
    multi-select mode enabled

-p:
    permissive mode enabled

<title>:
    Title of the poll
    <>'s aren't needed

<optionA>,<optionB>:
    Options to select from.
    <>'s aren't needed

If called as a command the output url is echo'ed to the user

If called as a identifier the output is returned formated as:
  0 errormsg
  1 straw_poll_url


Example Usage in on text event:
Code:
on *:TEXT:!strawpollcreate ?*:#mychannel:{
  tokenize 32 $strawpoll($2-)
  if ($1 == 1) {
    msg # Straw Poll Created: $2-
  }
  else {
    msg # Unable to create straw poll: $2-
  }
}


And now the code:
Code:
#STRAWPOLL_CREATOR on
alias strawpoll {
  var %res
  if ($strawpoll.parse($1-)) {
    %res = $strawpoll.try(strawpoll_creator, $v1)
  }
  else {
    %res = 0 Invalid Format: [-mp] <title> options:<optionA>,<optionB>,<optionC>
  }

  if ($isid) {
    return %res
  }
  elseif ($gettok(%res, 1, 32) == 1) {
    echo -a 03[StrawPoll]: Created $gettok(%res, 2-, 32)
  }
  else {
    echo -a 04[StrawPoll]: Unable to create poll: $gettok(%res, 2-, 32)
  }
}
#STRAWPOLL_CREATOR end

on *:START:{
  var %err
  var %com = strawpoll_creator
  var %cls = $true
  var %js = (function(){strawpoll=function(){throw new Error("Unable to locate a valid HTTP request object")};var x=['MSXML2.SERVERXMLHTTP.6.0','MSXML2.SERVERXMLHTTP.3.0','MSXML2.SERVERXMLHTTP'],xo,i;for(i=0;i<x.length;i+=1)try{xo=new ActiveXObject(x[i]);xo=x[i];strawpoll=function(d){var z=new ActiveXObject(xo),c,i;z.open("GET","http://strawpoll.me",false);z.send();if(z.status!==200)throw new Error("Server Error: "+z.status);c=z.getResponseHeader("Set-Cookie").split(";")[0];if(!c)throw new Error("No Cookie Recieved");z=new ActiveXObject(xo);z.open("POST","http://strawpoll.me/api/v2/polls",false);z.setRequestHeader("Cookie",c);z.setRequestHeader("Origin","http://strawpoll.me");z.setRequestHeader("Referer","http://strawpoll.me/");z.setRequestHeader("Accept","application/json,text/plain,*/*");z.setRequestHeader("Content-Type","application/json;charset=utf-8");z.setRequestHeader("Content-Length",d.length.toString(10));z.send(d);if (z.status!==201)throw new Error("Poll Not Created");i=eval('('+z.responseText+')');if(i.hasOwnProperty("id"))return"http://strawpoll.me/"+i.id;throw new Error("Poll id not returned")};break}catch(e){}}());

  if ($com(%com)) {
    %cls = $false
    %err = Com name in use, unable to continue
  }
  else {
    .comopen %com MSScriptControl.ScriptControl
    if (!$com(%com) || $comerr) {
      %err = Unable to create an instance of MSScriptControl.ScriptControl
    }
    elseif (!$com(%com, language, 4, bstr, jscript) || $comerr) {
      %err = Unable to set the MSScriptControl.ScriptControl instance's language to jscript
    }
    elseif (!$com(%com, ExecuteStatement, 1, bstr, %js) || $comerr) {
      %err = Unable to add jscript to the MSScriptControl.ScriptControl instance
    }
    else {
      .enable #STRAWPOLL_CREATOR
    }
  }
  :error
  %err = $iif($error, $v1, %err)
  reseterror
  if (%err) {
    if (%cls && $com(%com)) {
      .comclose %com
    }
    .disable #STRAWPOLL_CREATOR
    echo -s 04[STRAWPOLL CREATOR]: %err
  }
}

alias -l strawpoll.try {
  var %js = (function(){try{return"1 "+strawpoll(_data_)}catch(e){return"0 "+e.message}}())
  %js = $replace(%js, _data_, $2-)
  echo -a %js
  if (!$com($1, eval, 1, bstr, %js) || $comerr) {
    return 0 com error
  }
  else {
    return $com($1).result
  }
}

alias -l strawpoll.parse {
  var %reg = /^(?:(-[mp]*) )?(.+?) options:(.+)$/i, %n, %switches, %title, %options, %multi, %permissive, %v
  if ($regex($1-, %reg)) {
    %n = 1
    %switches = -
    if (-* iswm $regml(1)) {
      %switches = $v2
      inc %n
    }
    %title = "title":" $+ $replace($regml(%n), \,\\, ", \") $+ "
    %options = $regml($calc(%n +1))
    %multi = "multi": $+ $iif(m isincs %switches, true, false)
    %permissive = "permissive": $+ $iif(p isincs %switches, true, false)

    tokenize 44 %options
    %options = $null
    %n = 0
    while (%n < $0) {
      inc %n
      %v = $regsubex($($ $+ %n, 2), /(?:^[\s\r\n\t]+)|([\s\r\n\t]+$)/g, )
      if ($len(%v)) {
        %options = $addtok(%options, " $+ $replace(%v, \, \\, ", \") $+ ", 44)
      }
    }
    if ($numtok(%options,44) > 1) {
      return ' $+ $replace($+($chr(123),%title,$chr(44),"options":[,%options,],$chr(44),%multi,$chr(44),%permissive,$chr(125)), \, \\, ', \') $+ '
    }
  }
}


Last edited by FroggieDaFrog; 29/04/15 05:25 AM.

I am SReject
My Stuff