This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

aVote 1.1b eng by arcane - please help me out

Support & discussion of released scripts, and announcements of new releases.
Post Reply
u
unudoitrei
Voice
Posts: 2
Joined: Thu Jul 02, 2009 6:12 am

aVote 1.1b eng by arcane - please help me out

Post by unudoitrei »

Code: Select all

####################################################
#       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 "aVote 1.1b eng"
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 vote by $vnick:"
				puthelp "NOTICE $nick :\"$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:"
			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>\""
			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 :\002Vote by $nick:"
		puthelp "PRIVMSG $vchan :\"$vtopic\""
		puthelp "PRIVMSG $vchan :possible answers: [join $vanswers " : "]"
		puthelp "PRIVMSG $vchan :Time: $time"
		puthelp "PRIVMSG $vchan :Vote with \"/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 by arcane - help"
	puthelp "NOTICE $nick :the syntax is \"!vote <time>|<topic>|<answers>\" (separated by \"|\")."
	puthelp "NOTICE $nick :The different possible answers are separeted by \":\"."
	puthelp "NOTICE $nick :The time is given in the following way:"
	puthelp "NOTICE $nick :xxm: xx minutes; xxh: xx hours. No mixing of minutes and hours."
	puthelp "NOTICE $nick :Other commands:"
	puthelp "NOTICE $nick :/msg $botnick vhelp: shows this help"
	puthelp "NOTICE $nick :!vote (without arguments): shows information about current / last vote"
	puthelp "NOTICE $nick :You vote with /msg $botnick vote <answer>"	
	puthelp "NOTICE $nick :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 :Vote by $vnick about $vtopic ended (time out)."
		} else {
			puthelp "PRIVMSG $vchan :Vote by $vnick about $vtopic ended by $nick."
		}
		puthelp "PRIVMSG $vchan :Result:"
		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"
I need to make some modification in the script file, maybe you can help me out.

- all the voting to be done by channel command and not by /msg command
- all the messages from the egg to be sent on the channel not via notice to user
- It's possible to change the code so I can vote like this: '!vote A or B 10 m' ?

Thank you !
Post Reply