Problems creating a polling system for a twitch bot

204 views Asked by At

I am attempting to create a script that is capable of polling a twitch channel. I have written the basic idea of it but i'm having trouble working out the kinks. I have experience programming in C and Java but am still very new to mIRC. I'm having issues with my scripts simply not doing anything.

The input for !startpoll should look like this: !startpoll Question goes here? ~ option1 ~ option2 ~ option3 ~ option4 ~ option5

on 5:text:!startpoll*:#: {
  if(%pollopen == 1) msg $chan Error, A poll is already started please end it before starting another. | return
  set %pollopen 1
  msg $chan A poll has begun
  tokenizelist 126 $2-
if($4 == null) {
msg $chan Vote 1 for $2 or 2 for $3 $+ .
set %text1 $2
set %text2 $3
set %responses 2
}
elseif($5 == null) {
msg $chan Vote 1 for $2 $+ , 2 for $3 or 3 for $4 $+ .
set %text1 $2
set %text2 $3
set %text3 $4
set %responses 3
}
elseif($6 == null) {
msg $chan Vote 1 for $2 $+ , 2 for $3 $+ , 3 for $4 or 4 for $5 $+ .
set %text1 $2
set %text2 $3
set %text3 $4
set %text4 $5
set %responses 4 
}
elseif($7 == null) {
msg $chan Vote 1 for $2 $+ , 2 for $3 $+ , 3 for $4 $+ , 4 for $5 or 5 for $6 $+ .
set %text1 $2
set %text2 $3
set %text3 $4
set %text4 $5
set %text5 $6
set %responses 5
}
else msg $chan Error only 5 possible responses may be given.
}

on *:text:!vote*:#: {
if(pollopen == 1) {
if($nick isin %nicklist) {
  msg $chan You may only vote once.
  return
}
else $addtok( $nick , %nicklist , 32 )
if($2 == 1) inc %option1
elseif($2 == 2) inc %option2
elseif(($2 == 3) && (%responses > 2)) inc %option3
elseif(($2 == 4) && (%responses > 3)) inc %option4
elseif(($2 == 5) && (%responses > 4)) inc %option5
else msg $chan Only the numbers 1-5 are accepted as voting responses.
}
elseif(pollopen == 0) msg $chan No poll is open.
}

on 5:text:!endpoll:#: {
  $sorttok(%option1 %option2 %option3 %option4 %option5 , nr)
  if($1 == %option1) msg $chan %text1 is the top choice.
  elseif($1 == %option2) msg $chan %text2 is the top choice.
  elseif($1 == %option3) msg $chan %text3 is the top choice.
  elseif($1 == %option4) msg $chan %text4 is the top choice.
  elseif($1 == %option5) msg $chan %text5 is the top choice.
  set %text1 null
  set %text2 null
  set %text3 null
  set %text4 null
  set %text5 null
  set %responses null
  set %option1 0
  set %option2 0
  set %option3 0
  set %option4 0
  set %option5 0
  set %pollopen 0
}

alias tokenizelist {
  var %x 1
  tokenize $1 $2-
  while ($(,$ $+ %x) != $null) {
    echo $ $+ %x = $v1
    inc %x
  }
}

I really appreciate any help or advice you could have!

0

There are 0 answers