My first script ever that uses ini's :D
poll is triggered on /pollstart and ended with /pollend
it will amsg the poll question with the suggestion to do !pollcmds to see the options
!pollcmds includes:
!yes for yes
!no for no
!results for the current results (will only display if the person has already voted)
!poll for the poll question again
the !yes or !no options wont count if there is no poll active
when the poll is ended, the counts for yes and no, as well as the question are removed and the ini file with the hostmasks of people who have voted are cleared.
Criticism is appreciated, its one of the more complex scripts I've written so I dont know how it looks.
alias pollstart {
set %question $1-
/amsg [POLL] Poll started: %question (type !pollcmds to see the poll commands.)
}
alias pollend {
/amsg [POLL] Poll ended: %question - results: (yes: %yes $+ ) (No: %no $+ )
/write -c voted.ini
unset %question
unset %yes
unset %no
}
on *:text:!yes:#:{
if ( %question == $null) { halt }
else {
if ($readini(voted.ini,voted,$address($nick,2)) != $null) {
notice $nick You have already voted in this poll, you cannot vote again!
}
else {
if ($readini(voted.ini,voted,$address($nick,2)) == $null) {
writeini -n voted.ini voted $address($nick,2) yes
inc %yes
notice $nick Thanks for voting.
}
}
}
}
on *:text:!no:#:{
if ( %question == $null ) { halt }
else {
if ($readini(voted.ini,voted,$address($nick,2)) != $null) {
notice $nick You have already voted in this poll, you cannot vote again! { halt }
}
else {
if ($readini(voted.ini,voted,$address($nick,2)) == $null) {
writeini -n voted.ini voted $address($nick,2) no
inc %no
notice $nick Thanks for voting.
}
}
}
}
}
on *:text:!poll:#:{
if ( %question == $null ) {
notice $nick There is no poll going on at this time.
}
else {
notice $nick The current poll question is: %question
}
}
on *:text:!pollcmds:#:{
if ( %question == $null ) {
notice $nick There is no poll going on at this time.
}
else {
notice $nick Poll commands: !yes to vote yes, !no to vote no, !poll to see the question, !results to view the current results of the poll (only applicable if you've voted already)
}
}
on *:text:!results:#:{
if ( %question == $null ) {
notice $nick There is no poll going on at this time.
}
else {
if ($readini(voted.ini,voted,$address($nick,2)) == $null) {
notice $nick You need to vote in the poll to see its results.
}
else {
if ($readini(voted.ini,voted,$address($nick,2)) != $null) {
notice $nick The current poll results are: Yes: %yes $+ . No: %no $+ .
}
}
}
Also why no do all ini no vars like:
on *:TEXT:*:#: {
if (!poll == $1) {
if (!$readini(Poll.ini,Polls,Question)) { .notice $nick There is no poll going on at this time. }
elseif ($readini(Poll.ini,Polls,Question)) { .notice $nick The current poll question is: $readini(poll.ini,polls,question) }
}
elseif ($1 == !pollcmds) {
if (!$readini(Poll.ini,Polls,Question)) { .notice $nick There is no poll going on at this time. }
elseif ($readini(Poll.ini,Polls,Question)) { .notice $nick Poll commands: !yes to vote yes, !no to vote no, !poll to see the question, !results to view the current results of the poll (only applicable if you've voted already) }
}
elseif ($1 == !yes) {
if (!$readini(Poll.ini,Polls,Question)) { .notice $nick There is no poll going at the moment }
if ($readini(Poll.ini,Polls,Question)) {
var %voted $readini(poll.ini,polls,voted)
var %a = $numtok(%voted,32)
while (%a) {
if ( $gettok(%voted,%a,32) isin $1- ) { .notice $nick You have already voted }
elseif ( $gettok(%voted,%a,32) !isin $1- ) { writeini poll.ini polls voted $nick $readini(poll.ini,polls,voted) | inc %yes 1 | writeini poll.ini polls yes %yes | .notice $nick Thanks for voting }
}
}
}
elseif ($1 == !no) {
if (!$readini(Poll.ini,Polls,Question)) { .notice $nick There is no poll going at the moment }
if ($readini(Poll.ini,Polls,Question)) {
var %voted $readini(poll.ini,polls,voted)
var %a = $numtok(%voted,32)
while (%a) {
if ( $gettok(%voted,%a,32) isin $1- ) { .notice $nick You have already voted }
elseif ( $gettok(%voted,%a,32) !isin $1- ) { writeini poll.ini polls voted $nick $readini(poll.ini,polls,voted) | inc %no 1 | writeini poll.ini polls no %no | .notice $nick Thanks for voting }
}
}
}
elseif ($1 == !results) {
var %voted $readini(poll.ini,polls,voted)
var %a = $numtok(%voted,32)
while (%a) {
if ( $gettok(%voted,%a,32) isin $1- ) { .notice $nick The polls as of now stand at $readini(poll.ini,polls,yes) yes's and $readini(poll.ini,polls,no) no's }
elseif ( $gettok(%voted,%a,32) !isin $1- ) { .notice $nick You need to vote to see the results }
}
}
}
alias pollstart {
writeini poll.ini polls question $1-
/amsg [POLL] Poll started: $readini(poll.ini,polls,question) (type !pollcmds to see the poll commands.)
}
alias pollend {
/amsg [POLL] Poll ended: $readini(poll.ini,polls,question) - results: (yes: $readini(poll.ini,polls,yes) $+ $chr(41) (No: $readini(poll.ini,polls,no) $+ $chr(41)
/write -c poll.ini
}