Formatting of code : You can (and must) use [ tcl ] an [ /tcl ] tags (without spaces in tags) to format your TCL codes and have syntax coloration x


Voting System Script
#1
For me, i really like this script; but i need few adjustments;

tcl
####################################################
#      aVote 1.1b eng by arcane (arc-76024@web.de)
#              (#k13, #Prophecy @euIRC) 
#
# (english translation. original script is in german) 
#
# Voting script with user-defined answers
#
# If you decide to use my script, i'd be happy about a short message. :)
#
# For help:
#  /msg <botnick> vhelp
#
#  The syntax is: "!vote <time>|<topic>|<answers>" (separated by "|").
#    The different possible answers are separeted by ":".
#    e.g. "!vote 10m|What's your favourite color? Or don't you have one?|have none:green:red:yellow:blue"
#
#  The time is given in the following way:
#    xxm: xx minutes; xxh: xx hours. No mixing of minutes and hours.
#    e.g. "12m" for 12 minutes, "24h" for 24 hours. "24h 30m" is not allowed.

#  Other commands:
#    "!vote" (without arguments): shows information about current / last vote
#    you vote with "/msg <botnick> vote <answer>"
#    The vote-starter can end the vote using "!endvote" before time's out
#
#
# Features:
#
# - self-defined answers
# - notice when joining the channel for all people who haven't voted yet
# - hostmasks for voters (only one vote per host)
# - no voting using bots
# - ending a vote by the starter
#
# ToDo:
#
# - multiple sessions at the same time
# - reminder for people who are away
# - comments?
# - limiting to user groups (all users, voice-users, ops)
# - free votes (no predefined answers)
#
# History:
#
# - Version 1.0:  (10.02.2003)
#  - published only on forum.egghelp.org
#  - first version
#  - published only in german
# - Version 1.1:  (19.02.2003)
#  - fixed some minor things (thanks to stdragon)
#  - current vote stats are showed on "!vote" and onjoin
#  - changed syntax to "!vote <time>|<topic>|<answers>"
#  - some optical things
#  - english translation available
# - Version 1.1b: (24.02.2003)
#  - fixed one small bug in the onjoin-procedure
#
#
# Thanks to:
#
# - Loki` for his Channel Voter Script 1.15
# - ppslim @forum.egghelp.org for his help
# - stdragon @forum.egghelp.org for looking through my script
####################################################
 
##################### Params #######################
set aversion "Voting System"
set vvotes "0"
 
##################### Bindings #####################
bind pub - !vote avote_anyvote
bind msg - vhelp avote_help
bind msg - vote avote_vote
bind pub - !endvote avote_end
bind join - * avote_reminder
 
##################### Remove old timers ############
if {![info exists vtopic]} {
catch {
killutimer $vtimer
}
}
 
##################### AnyVote ######################
proc avote_anyvote {nick mask hand chan arg} {
global botnick vchan vnick vpeople vvotes vtopic vanswers vcount vtime aversion vtimestart vtimer vhand
 
if {$arg == ""} {
if {$vvotes == "0"} {
puthelp "NOTICE $nick :No open vote."
if {[info exists vtopic]} {
puthelp "NOTICE $nick :Last topic: \"$vtopic\""
puthelp "NOTICE $nick :Results:"
for {set number 0} {$number < [llength $vanswers]} {incr number} {
puthelp "NOTICE $nick :\"[lindex $vanswers $number]\": [lindex $vcount $number]"
}
} else {
puthelp "NOTICE $nick :No votes started yet."
}
return 0
} else {
puthelp "NOTICE $nick :Current vote by $vnick | \"$vtopic\""
puthelp "NOTICE $nick :Current stats:"
for {set number 0} {$number < [llength $vanswers]} {incr number} {
puthelp "NOTICE $nick :\"[lindex $vanswers $number]\": [lindex $vcount $number]"
}
puthelp "NOTICE $nick :Time remaining: [duration [expr (([unixtime] - $vtimestart) - $vtime) * -1]]"
puthelp "NOTICE $nick :Vote with \"/msg $botnick vote <answer>\""
return 0
}
} else { 
if {$vvotes != 0} { 
puthelp "NOTICE $nick :There is already a vote open."
return 0
}
 
set parts [split $arg "|"] 
set time [lindex $parts 0] 
set topic [lindex $parts 1] 
set answers [split [lindex $parts 2] :]
 
if {$time == "" || $topic == "" || [lindex $answers 0] == ""} {
puthelp "NOTICE $nick :The syntax is \"!vote <time>|<topic>|<answers>\" (separated by \"|\")."
puthelp "NOTICE $nick :The different possible answers are separeted by \":\"."
return 0
}
if {[lindex $answers 1] == ""} {
puthelp "NOTICE $nick :You need at least 2 possible answers."
return 0
}
 
set vtimeleft $time
if [string match "*m" [string tolower $vtimeleft]] {
set vtime [expr [string trimright $vtimeleft m] * 60]
set vtimestart [unixtime]
} elseif [string match "*h" [string tolower $vtimeleft]] {
set vtime [expr [string trimright $vtimeleft h] * 3600]
set vtimestart [unixtime]
} else {
puthelp "NOTICE $nick :$time: Wrong time format (m: minutes, h: hours)."
return 0
}
 
set vchan $chan
set vtopic $topic
set vanswers $answers
set vvotes "1"
set vnick $nick
set vhand $hand
 
set vcount [list] 
foreach answer $vanswers { 
lappend vcount 0 
}
 
puthelp "PRIVMSG $vchan :\00306Vote now: \00304\"$vtopic\"\003"
puthelp "PRIVMSG $vchan :\00306Time:\00302 $time\003, \00303Choices:\00302 [join $vanswers " : "]"
puthelp "PRIVMSG $vchan :\00302How to vote:\003 \"/msg $botnick vote <answer>\""
 
if {[info exists vpeople]} { unset vpeople }
 
set vtimer [utimer $vtime "avote_end \"end of time\" 2 3 4 5"]
}
}
 
##################### Vote #########################
proc avote_vote {nick mask hand arg} {
global botnick vchan vpeople vvotes vanswers vcount
 
if {$vvotes == 0} {
puthelp "NOTICE $nick :No open vote."
return 0
}
 
set mask [maskhost $mask]
if {[matchattr $hand b]} {
puthelp "NOTICE $nick :Keine Bots."
puthelp "PRIVMSG $vchan :Someone tries to vote using $nick!"
return 0
} elseif {[info exists vpeople($mask)]} {
puthelp "NOTICE $nick :You have already voted."
return 0
} else {
for {set number 0} {$number < [llength $vanswers]} {incr number} {
if {[string tolower $arg] == [string tolower [lindex $vanswers $number]]} {
puthelp "NOTICE $nick :Your vote has been counted ([string tolower $arg])."
 
set vtemp [lindex $vcount $number]
incr vtemp
set vcount [lreplace $vcount $number $number $vtemp]
 
set vpeople($mask) 1
return 0
}
}
puthelp "NOTICE $nick :$arg: No possible Answer."
puthelp "NOTICE $nick :Possible answers are: [join $vanswers " : "]"
}
}
 
##################### Help #########################
proc avote_help {nick mask hand arg} {
global botnick aversion
 
puthelp "NOTICE $nick :$aversion - help"
puthelp "NOTICE $nick :Command is \"!vote <time>|<topic>|<answers>\" (separated by \"|\"). Answer separeted by \":\"."
puthelp "NOTICE $nick :Example: !vote 10m|What's your favourite color?|green:red:yellow:blue"
puthelp "NOTICE $nick :Other commands: /msg $botnick vhelp: shows this help, !vote (without arguments): shows information about current / last vote"
puthelp "NOTICE $nick :You vote with /msg $botnick vote <answer> | The vote-starter can end the vote using !endvote before time's out." 
}
 
##################### Endvote ######################
proc avote_end {nick mask hand chan arg} {
global botnick vchan vnick vpeople vvotes vtopic vanswers vcount vtime vtimer vhand vtimestart
 
if {$vvotes == 0} {
puthelp "NOTICE $nick :No open vote."
return 0
} 
 
if {$chan == $vchan || $nick == "end of time"} {
if {$hand != $vhand && $nick != "end of time"} {
puthelp "NOTICE $nick :Only the vote-starter can end the vote before time's out."
return 0
}
 
if {$nick == "end of time"} {
puthelp "PRIVMSG $vchan :\00304Topic:\003 $vtopic ended (time out)."
} else {
puthelp "PRIVMSG $vchan :\00304Topic:\003 $vtopic "
}
puthelp "PRIVMSG $vchan :\00303Result:\003"
for {set number 0} {$number < [llength $vanswers]} {incr number} {
puthelp "PRIVMSG $vchan :\"[lindex $vanswers $number]\": [lindex $vcount $number]"
}
 
set vvotes "0"
 
catch {
killutimer $vtimer
}
if {[info exists vpeople]} { unset vpeople }
}
}
 
##################### OnJoin Reminder ##############
proc avote_reminder {nick mask hand chan} {
global botnick vchan vnick vpeople vvotes vtopic vanswers vcount vtime vtimestart
 
if {![info exists vchan]} {
return 0
}
 
set mask [maskhost $mask]
if {$chan == $vchan && [info exists vpeople($mask)] == 0 && $vvotes != 0} {
puthelp "NOTICE $nick :Current vote by $vnick"
puthelp "NOTICE $nick :\"$vtopic\""
puthelp "NOTICE $nick :Current Stats:"
for {set number 0} {$number < [llength $vanswers]} {incr number} {
puthelp "NOTICE $nick :\"[lindex $vanswers $number]\": [lindex $vcount $number]"
}
puthelp "NOTICE $nick :Time remaining: [duration [expr (([unixtime] - $vtimestart) - $vtime) * -1]]"
puthelp "NOTICE $nick :Vote with \"/msg $botnick vote <answer>\""
}
}
 
##################### Log Message ##################
putlog "\0033$aversion loaded"




from this code need adjustment;

tcl
proc avote_end {nick mask hand chan arg} {
global botnick vchan vnick vpeople vvotes vtopic vanswers vcount vtime vtimer vhand vtimestart
 
if {$vvotes == 0} {
puthelp "NOTICE $nick :No open vote."
return 0
} 
 
if {$chan == $vchan || $nick == "end of time"} {
if {$hand != $vhand && $nick != "end of time"} {
puthelp "NOTICE $nick :Only the vote-starter can end the vote before time's out."
return 0
}
 
if {$nick == "end of time"} {
puthelp "PRIVMSG $vchan :\00304Topic:\003 $vtopic ended (time out)."
} else {
puthelp "PRIVMSG $vchan :\00304Topic:\003 $vtopic "
}
puthelp "PRIVMSG $vchan :\00303Result:\003"
for {set number 0} {$number < [llength $vanswers]} {incr number} {
puthelp "PRIVMSG $vchan :\"[lindex $vanswers $number]\": [lindex $vcount $number]"
}
 
set vvotes "0"
 
catch {
killutimer $vtimer
}
if {[info exists vpeople]} { unset vpeople }
}
}



and the output is this: (when the user type !endvote)

tcl
<bot> Topic: What's your favourite color? 
<bot> Result:
<bot> "green": 1
<bot> "red": 1
<bot> "yellow": 0
<bot> "blue": 0



there's 6 lines in output.. but i need the output in 2 lines only like this;

tcl
<bot> Topic: What's your favourite color?
<bot> Result:  "green": (1);  "red": (1);  "yellow": (0); "blue": (0)





this is the command;

** user setting the topic to vote:
<user> !vote 10m|What's your favourite color?|green:red:yellow:blue

**bot reply;
<bot> Vote now: "What's your favourite color?"

<bot> Time: 10m, Choices: green : red : yellow : blue
<bot> How to vote: "/msg bot vote <answer>"



user1 vote
<user1>/msg bot vote green
<botnotice>user1 :Your vote has been counted (1)

user2 vote
<user2>/msg bot vote red
<botnotice>user1 :Your vote has been counted (1)






please help.. big thanks
  Reply
#2
Without redoing all the script, this is what you can do:

Find this part:
tcl
for {set number 0} {$number < [llength $vanswers]} {incr number} {
puthelp "PRIVMSG $vchan :\"[lindex $vanswers $number]\": [lindex $vcount $number]"
}



Replace with;
tcl
set outlist {}
for {set number 0} {$number < [llength $vanswers]} {incr number} {
   lappend outlist "\"[lindex $vanswers $number]\": ([lindex $vcount $number])"
}
puthelp "PRIVMSG $vchan :[join $outlist "; "]"
unset outlist



Short explanation: the for loop is modified to fill a list containing option results strings, and after we display a join of the list, separated with semi-colon + space
irc.zeolia.net - Offrez-moi un café
Merci de ne pas demander d'aide en MP
  Reply
#3
thanks a lot CrazyCat, working perfect.. :)))
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Public quotes system v2.52 Taxick 2 57 06/12/2021, 20:34
Last Post: Taxick

Forum Jump:


Users browsing this thread: 1 Guest(s)