mIRC Home    About    Download    Register    News    Help

Print Thread
#246837 05/07/14 08:59 AM
Joined: Jan 2014
Posts: 107
M
Majeye Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Jan 2014
Posts: 107
I have seen and utilized the strawpoll scripting that I saw in a previous thread.. but for some reason, Edit: I had it working, then I changed some other scripts, and now it's not working... perhaps someone can see if I did anything wrong?

Also, would there be a way to only have 1 person do the command, instead of all ops?

Code:
on *:text:!strawpoll *:#:{
  var %regex = /(?:(.+?)\s*[:-]+\s*|())(.+?)$/iS
  if ($regex($strip($2-),%regex)) {
    var %title = $iif($regml(1),$v1,Poll)
    var %options = $regsubex($regml(2),/\s* $+ $chr(44) $+ \s*/g,$chr(44))
  }
  else return

  noop $strawpoll.create(#,%title,%options)
}

alias strawpoll.create {
  var %chan = $1, %title = $urlencode($2), %options
  var %multi = true, %permissive = false

  var %i = 1, %n = $numtok($3,44)
  while (%i <= %n) {
    %options = %options $+ &options[]= $+ $urlencode($gettok($3,%i,44))
    inc %i
  }

  var %sockname = strawpoll. $+ $ticks
  hfree -w %sockname | hmake %sockname
  hadd %sockname headerfile %sockname $+ .header.txt
  hadd %sockname datafile %sockname $+ .data.txt

  hadd %sockname host strawpoll.me
  hadd %sockname request /ajax/new-poll
  hadd %sockname method POST
  hadd %sockname data $+(title=,%title,%options,&multi=,%multi,&permissive=,%permissive)
  hadd %sockname signal strawpoll.create
  hadd %sockname params %chan

  sockopen %sockname $hget(%sockname,host) 80
}

on *:signal:strawpoll.create:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5

  if (* 200 OK iswm $read(%header,1)) && ($regex($read(%data,n,1),(\d+))) {
    msg %chan http://strawpoll.me/ $+ $regml(1)
  }
  else msg %chan Could not create poll.

  hfree -w %sockname
  .remove %header | .remove %data
}

on *:sockopen:strawpoll.*:{
  var %a = sockwrite -n $sockname
  %a $hget($sockname,method) $hget($sockname,request) HTTP/1.0
  %a Host: $hget($sockname,host)
  %a Connection: close
  if ($hget($sockname,data) != $null) {
    %a Content-Type: application/x-www-form-urlencoded
    %a Content-Length: $len($v1)
  }
  %a $+($crlf,$hget($sockname,data))
}

on *:sockread:strawpoll.*:{
  var %header
  var %headerfile = $hget($sockname,headerfile)
  var %datafile = $hget($sockname,datafile)

  if (!$hget($sockname,header.complete)) {
    sockread %header
    while (%header != $null) {
      write %headerfile %header
      sockread %header
    }
    if ($sockbr) hadd $sockname header.complete $true
  }
  if ($hget($sockname,header.complete)) {
    sockread &read
    while ($sockbr) {
      bwrite %datafile -1 -1 &read
      sockread &read
    }
  }
}

on *:sockclose:strawpoll.*:{
  var %header = $hget($sockname,headerfile)
  var %data = $hget($sockname,datafile)
  var %signal = $hget($sockname,signal)
  var %params = $hget($sockname,params)

  if (%signal) .signal %signal 0 $sockname %header %data %params
  else {
    hfree -w $sockname
    .remove %header | .remove %data
  }
}

alias urlencode return $regsubex($1-,/([^A-Z0-9])/gi,$+(%,$base($asc(\1),10,16)))

Last edited by Majeye; 05/07/14 09:11 AM.
Majeye #246840 05/07/14 12:43 PM
Joined: Jan 2004
Posts: 1,330
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
I just tried it and it worked fine, do you have this script in its own file? Do you have another script listening for all (*) socket events?

To have something available to only a single nick use this:
Code:
 if ($nick != the_nick) return

Joined: Jan 2014
Posts: 107
M
Majeye Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Jan 2014
Posts: 107
Thanks for checking, Loki!

Any idea what would cause the bot to stop working 1 out of 6 channels, but still work in the other 5?

all my commands work perfectly in most of the channels I have them in.. but quit working in the 1 I need them to work in.

If needed, I will post my entire script into a paste-bin. :P

Majeye #246845 05/07/14 05:18 PM
Joined: Jan 2004
Posts: 1,330
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
Place the script into it's own file and change the order of your scripts such that this one is up top. In the remote editor go to File > Order to accomplish this. It could be that another script is interfering.

Joined: Jan 2014
Posts: 107
M
Majeye Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Jan 2014
Posts: 107
Put the strawpoll into it's own file and reload it placing it to process before the other scripts?

would it matter what I named the strawpoll script file?

Majeye #246848 05/07/14 06:02 PM
Joined: Jan 2004
Posts: 1,330
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
It does not matter

Joined: Jan 2014
Posts: 107
M
Majeye Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Jan 2014
Posts: 107
Thanks, Loki! works like a charm!


Link Copied to Clipboard