vote

By anthony1293 on May 30, 2009

this is one of my first snippets i've made. i know it can be made shorter. but i'm just getting used to it all.
commands:
!set vote - sets a vote for the channel
!yes - votes yes
!no - votes no
!@results - shows the results of the vote
!resetvote - resets the vote for the channel

on *:TEXT:!set vote*:#: {
  if ($nick isop $chan) {
    set %vote [ $+ [ $chan ] ] $3-
    notice $nick you have set the vote for $chan
    msg $chan 14 $nick has set a vote for $chan $+ :4 %vote [ $+ [ $chan ] ]
    timer 1 1 msg $chan 14type 4!yes14 to vote yes and 4!no14 to vote no.
  }
}
on *:TEXT:!vote:#: {
  if (%vote [ $+ [ $chan ] ] == $null) {
    notice $nick there is no current vote set for $chan | halt
  }
  else notice $nick 14 the current vote for $chan is:4 %vote [ $+ [ $chan ] ] 
  timer 1 1 notice $nick 14type 4!yes14 to vote yes and 4!no14 to vote no. 
}
on *:TEXT:@vote:#: {
  if (%vote [ $+ [ $chan ] ] == $null) {
    notice $nick there is no current vote set for $chan | halt
  }
  else msg $chan 14 the current vote for $chan is:4 %vote [ $+ [ $chan ] ]
  timer 1 1 msg $chan 14type 4!yes14 to vote yes and 4!no14 to vote no. 
}
on *:TEXT:!yes:#: {
  if (%vote [ $+ [ $chan ] ] == $null) {
    notice $nick there is no vote currently set for $chan | halt
  }
  if ($readini(vote.ini,$chan,$address($nick,2)) == yes) {
    notice $nick you have already voted you cannot vote again | halt
  }
  if ($readini(vote.ini,$chan,$address($nick,2)) == no) {
    notice $nick you have already voted you cannot vote again | halt
  }
  else inc %yes [ $+ [ $chan ] ]
  writeini vote.ini $chan $address($nick,2) yes
  notice $nick you've voted yes, total number of votes for yes:4 %yes [ $+ [ $chan ] ]
}
on *:TEXT:!no:#: {
  if (%vote [ $+ [ $chan ] ] == $null) {
    notice $nick there is no vote currently set for $chan | halt
  }
  if ($readini(vote.ini,$chan,$address($nick,2)) == no) {
    notice $nick you have already voted you cannot vote again | halt
  }
  if ($readini(vote.ini,$chan,$address($nick,2)) == yes) {
    notice $nick you have already voted you cannot vote again | halt
  }
  else inc %no [ $+ [ $chan ] ]
  writeini vote.ini $chan $address($nick,2) no
  notice $nick you've voted no, total number of votes for no:4 %no [ $+ [ $chan ] ]
}

on $*:TEXT:/^[!@]results/Si:#: {
  if ($readini(vote.ini,$chan,$address($nick,2)) == $null) {
    notice $nick you have not voted yet you cannot see the results | halt
  }
  var %results $iif($left($1,1) == @,msg $chan,notice $nick)
  if (%yes [ $+ [ $chan ] ] == $null) && (%no [ $+ [ $chan ] ] != $null) {
    %results 14the results for:4 %vote [ $+ [ $chan ] ]
    timer 1 1 %results 14yes:4 0
    timer 1 2 %results 14no:4 %no [ $+ [ $chan ] ] | halt
  }
  if (%yes [ $+ [ $chan ] ] != $null) && (%no [ $+ [ $chan ] ] == $null) {
    %results 14the results for:4 %vote [ $+ [ $chan ] ]
    timer 1 1 %results 14yes:4 %yes [ $+ [ $chan ] ]
    timer 1 2 %results 14no:4 0 | halt 
  }
  if (%yes [ $+ [ $chan ] ] != $null) && (%no [ $+ [ $chan ] ] != $null) {
    %results 14the results for:4 %vote [ $+ [ $chan ] ]
    timer 1 1 %results 14yes:4 %yes [ $+ [ $chan ] ]
    timer 1 2 %results 14no:4 %no [ $+ [ $chan ] ] 
  }
}
on *:TEXT:!resetvote:#: {
  if ($nick isop $chan) {
    if (%vote [ $+ [ $chan ] ] == $null) {
      notice $nick the vote has already been reset | halt
    }
    else unset %vote [ $+ [ $chan ] ]
    unset %yes [ $+ [ $chan ] ]
    unset %no [ $+ [ $chan ] ]
    remini vote.ini $chan
    notice $nick you have reset the vote for $chan
    msg $chan 4 $nick 14has reset the vote for4 $chan
  }
  else notice $nick access denied
}

Comments

Sign in to comment.
anthony1293   -  May 30, 2009

yeah i realized that after i made it. but then i didn't have time to change it. but i'll do that now.

 Respond  
Aucun50   -  May 30, 2009

I noticed you used two ini files when one can do all that just fine.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.