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.

Voting script (very needed)

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

oke, please try this script - its unfinished but counting should work:

Code: Select all

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
#
# if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)                 
# .chanset #channel_name +vote
# and later .save   

# ban after X yes votes
set vote_limit 5

# dir with users data
set users_file "users.db"

# kick messages
set kick_msgs {
	"message 1"
	"message 2"
	"message 3"
	"message N"
}

# punish method
# 0 - just kick
# 1 - kick & ban
set punish 0

###############################################################################################
bind pub -|- !vote vote_proc

setudef flag vote

if {![file exists $users_file]} {                                                                             
	set file_handle [open $users_file w]
	close $file_handle
}

proc get_hosts { } { 
	global users_file

	set get_hosts [open $users_file r] 
	set get_all [split [read $get_hosts] "\n"] 
	close $get_hosts 

	return $get_all 
}

proc put_host { user_host voter_host } {
	global users_file

	set put_host [open $users_file a] 
	puts $put_host "$user_host $voter_host" 
	close $put_host
}

proc del_host { user_host } {
	global users_file

	set old_hosts [get_hosts]

	set del_hosts [open $users_file w]
	foreach del_host $old_hosts {
		if {$del_host != ""} {
			set del_rows [split $del_host " "]
			set del_user_host [lindex $del_rows 0]
			set del_user_voters [lindex $del_rows 1]
			
			if {$del_user_host != $user_host} {
				puts $del_hosts "$del_user_host $del_user_voters"
			}
		}
	}
	close $del_hosts
}

proc add_voter { user_host voter_host } {
	global users_file

	set old_db [get_hosts]

	set add_voter [open $users_file w]
	foreach old_host $old_db {
		if {$old_host != ""} {
			set old_rows [split $old_host " "]
			set old_user_host [lindex $old_rows 0]
			set old_user_voters [lindex $old_rows 1]

			if {$old_user_host == $user_host} {
				puts $add_voter "$old_user_host $old_user_voters\,$voter_host"
			} {
				puts $add_voter "$old_user_host $old_user_voters"
			}
		}
	}
	close $add_voter
}

proc count_voters { user_host } {
	set voters_count 0

	foreach db_host [get_hosts] {
		if {$db_host != ""} {
			set db_rows [split $db_host " "]
			set db_user_host [lindex $db_host 0]
			set db_user_voters [lindex $db_host 1]

			if {$db_user_host == $user_host} {
				set voters_split [split $db_user_voters ","]
				set voters_count [llength $voters_split]
				break
			}
		}
	}

	return $voters_count
}

proc check_user_host { user_host } {
	set host_exists "no"

	foreach host [get_hosts] { 
		if {$host != ""} { 
			set rows [split $host " "]
			set file_user_host [lindex $rows 0]

			if {$file_user_host == $user_host} {
				set host_exists "yes"
				break
			}
		}
	}

	return $host_exists
}

proc check_voter_host { user_host voter_host } {
	set voter_exists "no"

	foreach voter [get_hosts] {
		if {$voter != ""} {
			set voter_rows [split $voter " "]
			set voter_user_host [lindex $voter_rows 0]
			set voter_voters [lindex $voter_rows 1]

			if {$voter_user_host == $user_host} {
				set host_votes [split $voter_voters ","]

				foreach vote $host_votes {
					if {$vote != ""} {
						if {$vote == $voter_host} {
							set voter_exists "yes"
							break
						}
					}
				}
			}
		}
	}
	
	return $voter_exists
}

proc vote_proc { nick uhost hand chan arg } {
	global users_file vote_limit kick_msgs punish
		
	set args [split $arg] 
	set user [lindex $args 0] 
	set yes_or_no [lindex $args 1]

	if {[isbotnick $user]} { 
		return 
	}

	if {$user != ""} {
		if {($yes_or_no == "yes") || ($yes_or_no == "no")} { 
			if {[onchan $user $chan]} { 
				set user_host [getchanhost $user $chan]

				if {[check_user_host $user_host] == "yes"} {
					if {[check_voter_host $user_host $uhost] == "no"} {
						set user_votes_counter [count_voters $user_host]

						if {[expr $user_votes_counter + 1] == $vote_limit} {
							putquick "PRIVMSG $chan :$nick voted $user Yes. ($vote_limit) Votes."

							if {$punish == 1} {
								putquick "MODE $chan +b *!*$user_host" 
							}
						
							putkick $chan $user [lindex $kick_msgs [expr {int(rand() * [llength $kick_msgs])}]]
							del_host $user_host
						} {
							putquick "PRIVMSG $chan :$nick voted $user Yes. ([expr $user_votes_counter + 1]) Votes."
							add_voter $user_host $uhost
						}
					}
				} {
					put_host $user_host $uhost
					putquick "PRIVMSG $chan :$nick voted $user Yes. (1) Votes."
				}
			}
		}
	}
}

putlog "simple-vote.tcl ver 0.1 by tomekk loaded"
multichannel support, various messages later, "no" will be later..
you can vote only for YES atm, I just want to try the counting on your channel

cheers
s
samhain
Halfop
Posts: 77
Joined: Wed Jan 03, 2007 5:19 am

Post by samhain »

<@Hawk> !vote Ompahpah yes
<@BallotBox> Hawk voted Ompahpah Yes. (1) Votes.
<@Hawk> !vote Ompahpah yes
<@Hawk> !vote Ompahpah yes
-> [Flubber] CHAT
<@Flubber> !vote Ompahpah yes
<@BallotBox> Flubber voted Ompahpah Yes. (2) Votes.
<@Flubber> !vote Ompahpah yes
-> [Ompahpah] CHAT
* timur` (fu@cpe-72-229-42-81.nyc.res.rr.com) has joined #BotHelp
<@Hawk> timur` type !vote Ompahpah yes
<timur`> salam
<@Hawk> ws
<timur`> !vote Ompahpah yes
<@BallotBox> timur` voted Ompahpah Yes. (3) Votes.
* Ompahpah was kicked by BallotBox (message N)
* Ompahpah (usa@chick-mag.net) has joined #BotHelp
<@Hawk> good
<@Hawk> !vote timur` yes
<@BallotBox> Hawk voted timur` Yes. (1) Votes.
<timur`> testing a new bot?
<@Hawk> yeah a new script
<timur`> cool
<@BallotBox> !vote timur` yes
<@Flubber> !vote timur` yes
<@BallotBox> Flubber voted timur` Yes. (2) Votes.
<@Hawk> timur` type !vote timur` yes
<timur`> you should make the vote-annoucements in a different color, like the rule8 bot
<timur`> does
<timur`> in AP
<timur`> that way it's noticeable in scroll
<@Hawk> yeah For the time being I am only testing the script counting
<@Hawk> timur` type !vote timur` yes
<timur`> !vote timur` yes
<@BallotBox> timur` voted timur` Yes. (3) Votes.
* timur` was kicked by BallotBox (message 2)
<@Hawk> hehe good


The script works good so far on Yes :) and I reduced the counting to 3, so it's good at the moment, Nice work tommek =)
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

not multichannel yet, but the rest should work OK, please try it:

Code: Select all

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
#
# if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)                 
# .chanset #channel_name +vote
# and later .save   

# ban after X yes votes
set vote_limit 3

# script messages
set vote_msg(is_bot) "Can't touch this!"
set vote_msg(is_op) "Can't touch this!"
set vote_msg(twice_on_same_user) "You can't vote twice on the same user!"
set vote_msg(not_on_chan) "Wrong user name!"
set vote_msg(help) "use: !vote <user> <yes/no>"
set vote_msg(noone_voted) "No one voted for this user before!"

# kick messages
set kick_msgs {
	"Come and get some!"
	"No pain, no pain!"
	"I'm your father Luke!"
	"Hail to the king baby!"
}

# punish method
# 0 - just kick
# 1 - kick & ban
set punish 1

# ban type 
# 1)  *!*@*.domain.com 
# 2)  *!*@some.domain.com 
# 3)  *nick*!*@some.domain.com 
# 4)  *!*ident*@some.domain.com
set bantype  4

# file with users data
set users_file "users.db"

###############################################################################################
bind pub -|- !vote vote_proc

setudef flag vote

if {![file exists $users_file]} {                                                                             
	set file_handle [open $users_file w]
	close $file_handle
}

proc get_hosts { } { 
	global users_file

	set get_hosts [open $users_file r] 
	set get_all [split [read $get_hosts] "\n"] 
	close $get_hosts 

	return $get_all 
}

proc put_host { user_host voter_host } {
	global users_file

	set put_host [open $users_file a] 
	puts $put_host "$user_host 1 $voter_host" 
	close $put_host
}

proc del_host { user_host } {
	global users_file

	set old_hosts [get_hosts]

	set del_hosts [open $users_file w]
	foreach del_host $old_hosts {
		if {$del_host != ""} {
			set del_rows [split $del_host " "]
			set del_user_host [lindex $del_rows 0]
			set del_user_counter [lindex $del_rows 1]
			set del_user_voters [lindex $del_rows 2]
			
			if {$del_user_host != $user_host} {
				puts $del_hosts "$del_user_host $del_user_counter $del_user_voters"
			}
		}
	}
	close $del_hosts
}

proc add_del_voter { user_host voter_host action } {
	global users_file

	set old_db [get_hosts]

	set add_voter [open $users_file w]
	foreach old_host $old_db {
		if {$old_host != ""} {
			set old_rows [split $old_host " "]
			set old_user_host [lindex $old_rows 0]
			set old_user_counter [lindex $old_rows 1]
			set old_user_voters [lindex $old_rows 2]

			if {$old_user_host == $user_host} {
				if {$action == "add"} {
					puts $add_voter "$old_user_host [expr $old_user_counter + 1] $old_user_voters\,$voter_host"
				} elseif {$action == "del"} {
					if {$old_user_counter > 1} {
						puts $add_voter "$old_user_host [expr $old_user_counter - 1] $old_user_voters\,$voter_host"
					}
				}
			} {
				puts $add_voter "$old_user_host $old_user_counter $old_user_voters"
			}
		}
	}
	close $add_voter
}

proc count_voters { user_host } {
	set voters_count 0

	foreach db_host [get_hosts] {
		if {$db_host != ""} {
			set db_rows [split $db_host " "]
			set db_user_host [lindex $db_host 0]
			set db_user_counter [lindex $db_host 1]

			if {$db_user_host == $user_host} {
				set voters_count $db_user_counter
				break
			}
		}
	}

	return $voters_count
}

proc check_user_host { user_host } {
	set host_exists "no"

	foreach host [get_hosts] { 
		if {$host != ""} { 
			set rows [split $host " "]
			set file_user_host [lindex $rows 0]

			if {$file_user_host == $user_host} {
				set host_exists "yes"
				break
			}
		}
	}

	return $host_exists
}

proc check_voter_host { user_host voter_host } {
	set voter_exists "no"

	foreach voter [get_hosts] {
		if {$voter != ""} {
			set voter_rows [split $voter " "]
			set voter_user_host [lindex $voter_rows 0]
			set voter_voters [lindex $voter_rows 2]

			if {$voter_user_host == $user_host} {
				set host_votes [split $voter_voters ","]

				foreach vote $host_votes {
					if {$vote != ""} {
						if {$vote == $voter_host} {
							set voter_exists "yes"
							break
						}
					}
				}
			}
		}
	}
	
	return $voter_exists
}

proc vote_proc { nick uhost hand chan arg } {
	global users_file vote_limit kick_msgs punish vote_msg
		
	set args [split $arg] 
	set user [lindex $args 0] 
	set yes_or_no [lindex $args 1]

	if {![channel get $chan vote]} { 
		return                                                                                          
	}

	if {$user != ""} {
		if {[isbotnick $user]} {
			putquick "PRIVMSG $nick :$vote_msg(is_bot)"
			return
		}

		if {[isop $user $chan]} {
			putquick "PRIVMSG $nick :$vote_msg(is_op)"
			return
		}

		if {![onchan $user $chan]} {
			putquick "PRIVMSG $nick :$vote_msg(not_on_chan)"
			return
		}

		if {($yes_or_no == "yes") || ($yes_or_no == "no")} { 
			set user_host [getchanhost $user $chan]
	
			if {$yes_or_no == "yes"} {
				if {[check_user_host $user_host] == "yes"} {
					if {[check_voter_host $user_host $uhost] == "no"} {
						set user_votes_counter [count_voters $user_host]

						if {[expr $user_votes_counter + 1] == $vote_limit} {
							putquick "PRIVMSG $chan :$nick voted $user Yes. ($vote_limit) Votes."
								
							del_host $user_host

							if {$punish == 1} {
								putquick "MODE $chan +b [ban_mask $uhost $nick]" 
							}
								
							putkick $chan $user [lindex $kick_msgs [expr {int(rand() * [llength $kick_msgs])}]]
						} {	
							putquick "PRIVMSG $chan :$nick voted $user Yes. ([expr $user_votes_counter + 1]) Votes."
							add_del_voter $user_host $uhost "add"
						}
					} {
						putquick "PRIVMSG $nick :$vote_msg(twice_on_same_user)"
					}
				} {
					putquick "PRIVMSG $chan :$nick voted $user Yes. (1) Votes."
					put_host $user_host $uhost
				}
			} elseif {$yes_or_no == "no"} {
				if {[check_user_host $user_host] == "yes"} {
					if {[check_voter_host $user_host $uhost] == "no"} {
						set user_votes_counter [count_voters $user_host]
						if {[expr $user_votes_counter - 1] == 0} {
							putquick "PRIVMSG $chan :$nick voted $user No. (0) Votes."
						} {
							putquick "PRIVMSG $chan :$nick voted $user No. ([expr $user_votes_counter - 1]) Votes."
						}
						add_del_voter $user_host $uhost "del"
					} {
						putquick "PRIVMSG $nick :$vote_msg(twice_on_same_user)"
					}
				} {
					putquick "PRIVMSG $nick :$vote_msg(noone_voted)"
				}
			}
		} {
			putquick "PRIVMSG $nick :$vote_msg(help)"
		}
	} {
		putquick "PRIVMSG $nick :$vote_msg(help)"
	}
}

proc ban_mask { host nick } {
	global bantype

	switch -- $bantype {
		1 {
			set bmask "*!*@[lindex [split [maskhost $host] "@"] 1]"
		}

		2 {
			set bmask "*!*@[lindex [split $host @] 1]"
		}

		3 {
			set bmask "*$nick*!*@[lindex [split $host "@"] 1]"
		}
														                4 {
			set bmask "*!*[lindex [split $host "@"] 0]*@[lindex [split $host "@"] 1]"
		}

		return $bmask
	}
}

putlog "simple-vote.tcl ver 0.1 by tomekk loaded"
s
samhain
Halfop
Posts: 77
Joined: Wed Jan 03, 2007 5:19 am

Post by samhain »

<Hawk375> !vote Hawk375 yes
<@BallotBox> Hawk375 voted Hawk375 Yes. (1) Votes.
<Hawk375> !vote Hawk375 yes
<Hawk375> !vote Hawk375 no
<@Flubber> !vote Hawk375 no
<@BallotBox> Flubber voted Hawk375 No. (0) Votes.
<@Flubber> !vote Hawk375 yes
<@BallotBox> Flubber voted Hawk375 Yes. (1) Votes.
<Hawk375> !vote Hawk375 yes
<@BallotBox> Hawk375 voted Hawk375 Yes. (2) Votes.
<Hawk375> !vote Hawk375 yes
<Hawk375> !vote Hawk375 yes
everything is fine, except Flubber votes twice, he says yes and no both. and same goes for me, after some time I was able to twice.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

this is proper situation because when user gets 0 votes, script removes its record from DB and when you voting again (from 0) it starts counting from the beginning

should I change it somehow for ya?
s
samhain
Halfop
Posts: 77
Joined: Wed Jan 03, 2007 5:19 am

Post by samhain »

can you make it as The voting when begins, It should last for 5 minutes, and in those 5 minutes a user can only vote once, Yes or No (one of them).
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

What after those 5 minutes? (when counter will be set to 0 and other than 0)
It is to make but it will complicate the whole script, why you didn't say this before?
s
samhain
Halfop
Posts: 77
Joined: Wed Jan 03, 2007 5:19 am

Post by samhain »

yes, after 5 minutes or a certain period of time, The counter should reset to 0, It's not necessary 5 minutes, but there should be a time for the counter to reset?
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Hey,

Sorry about the lag, I was at the hospital.
Ok, is script working OK?
Do you need this timer for reset users counters?
s
samhain
Halfop
Posts: 77
Joined: Wed Jan 03, 2007 5:19 am

Post by samhain »

Yes sir a timer would be good, the voting should last round about 10 minutes. and the voting should be reset.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

delete old users.db before use this version,
try it:

Code: Select all

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
#
# if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)                 
# .chanset #channel_name +vote
# and later .save   

# ban after X yes votes
set vote_limit 3

# delete user hosts older than X minutes plus +/- 1 minute for timer cycle
# timestamp from the first vote
set victim_interval 10

# script messages
set vote_msg(is_bot) "Can't touch this!"
set vote_msg(is_op) "Can't touch this!"
set vote_msg(twice_on_same_user) "You can't vote twice on the same user!"
set vote_msg(not_on_chan) "Wrong user name!"
set vote_msg(help) "use: !vote <user> <yes/no>"
set vote_msg(noone_voted) "No one voted for this user before!"

# kick messages
set kick_msgs {
	"Come and get some!"
	"No pain, no pain!"
	"I'm your father Luke!"
	"Hail to the king baby!"
}

# punish method
# 0 - just kick
# 1 - kick & ban
set punish 1

# ban type 
# 1)  *!*@*.domain.com 
# 2)  *!*@some.domain.com 
# 3)  *nick*!*@some.domain.com 
# 4)  *!*ident*@some.domain.com
set bantype  4

# file with users data
set users_file "users.db"

###############################################################################################
bind pub -|- !vote vote_proc

setudef flag vote

if {![file exists $users_file]} {                                                                             
	set file_handle [open $users_file w]
	close $file_handle
}

proc timestamp_timer { } {
	check_timestamps

	if {[string match *timestamp_timer* [utimers]] != 1} {
		utimer 60 timestamp_timer
	}
}

proc get_hosts { } { 
	global users_file

	set get_hosts [open $users_file r] 
	set get_all [split [read $get_hosts] "\n"] 
	close $get_hosts 

	return $get_all 
}

proc put_host { timestamp user_host voter_host } {
	global users_file

	set put_host [open $users_file a] 
	puts $put_host "$timestamp $user_host 1 $voter_host" 
	close $put_host
}

proc del_host { user_host } {
	global users_file

	set old_hosts [get_hosts]

	set del_hosts [open $users_file w]
	foreach del_host $old_hosts {
		if {$del_host != ""} {
			set del_rows [split $del_host " "]
			set del_user_timestamp [lindex $del_rows 0]
			set del_user_host [lindex $del_rows 1]
			set del_user_counter [lindex $del_rows 2]
			set del_user_voters [lindex $del_rows 3]
			
			if {$del_user_host != $user_host} {
				puts $del_hosts "$del_user_timestamp $del_user_host $del_user_counter $del_user_voters"
			}
		}
	}
	close $del_hosts
}

proc add_del_voter { user_host voter_host action } {
	global users_file

	set old_db [get_hosts]

	set add_voter [open $users_file w]
	foreach old_host $old_db {
		if {$old_host != ""} {
			set old_rows [split $old_host " "]
			set old_user_timestamp [lindex $old_rows 0]
			set old_user_host [lindex $old_rows 1]
			set old_user_counter [lindex $old_rows 2]
			set old_user_voters [lindex $old_rows 3]

			if {$old_user_host == $user_host} {
				if {$action == "add"} {
					puts $add_voter "$old_user_timestamp $old_user_host [expr $old_user_counter + 1] $old_user_voters\,$voter_host"
				} elseif {$action == "del"} {
					if {$old_user_counter > 1} {
						puts $add_voter "$old_user_timestamp $old_user_host [expr $old_user_counter - 1] $old_user_voters\,$voter_host"
					}
				}
			} {
				puts $add_voter "$old_user_timestamp $old_user_host $old_user_counter $old_user_voters"
			}
		}
	}
	close $add_voter
}

proc count_voters { user_host } {
	set voters_count 0

	foreach db_host [get_hosts] {
		if {$db_host != ""} {
			set db_rows [split $db_host " "]
			set db_user_host [lindex $db_host 1]
			set db_user_counter [lindex $db_host 2]

			if {$db_user_host == $user_host} {
				set voters_count $db_user_counter
				break
			}
		}
	}

	return $voters_count
}

proc check_user_host { user_host } {
	set host_exists "no"

	foreach host [get_hosts] { 
		if {$host != ""} { 
			set rows [split $host " "]
			set file_user_host [lindex $rows 1]

			if {$file_user_host == $user_host} {
				set host_exists "yes"
				break
			}
		}
	}

	return $host_exists
}

proc check_voter_host { user_host voter_host } {
	set voter_exists "no"

	foreach voter [get_hosts] {
		if {$voter != ""} {
			set voter_rows [split $voter " "]
			set voter_user_host [lindex $voter_rows 1]
			set voter_voters [lindex $voter_rows 3]

			if {$voter_user_host == $user_host} {
				set host_votes [split $voter_voters ","]

				foreach vote $host_votes {
					if {$vote != ""} {
						if {$vote == $voter_host} {
							set voter_exists "yes"
							break
						}
					}
				}
			}
		}
	}
	
	return $voter_exists
}

proc vote_proc { nick uhost hand chan arg } {
	global users_file vote_limit kick_msgs punish vote_msg
		
	set args [split $arg] 
	set user [lindex $args 0] 
	set yes_or_no [lindex $args 1]

	if {![channel get $chan vote]} { 
		return                                                                                          
	}

	if {$user != ""} {
		if {[isbotnick $user]} {
			putquick "PRIVMSG $nick :$vote_msg(is_bot)"
			return
		}

		if {[isop $user $chan]} {
			putquick "PRIVMSG $nick :$vote_msg(is_op)"
			return
		}

		if {![onchan $user $chan]} {
			putquick "PRIVMSG $nick :$vote_msg(not_on_chan)"
			return
		}

		if {($yes_or_no == "yes") || ($yes_or_no == "no")} { 
			set user_host [getchanhost $user $chan]
	
			if {$yes_or_no == "yes"} {
				if {[check_user_host $user_host] == "yes"} {
					if {[check_voter_host $user_host $uhost] == "no"} {
						set user_votes_counter [count_voters $user_host]

						if {[expr $user_votes_counter + 1] == $vote_limit} {
							putquick "PRIVMSG $chan :$nick voted $user Yes. ($vote_limit) Votes."
								
							del_host $user_host

							if {$punish == 1} {
								putquick "MODE $chan +b [ban_mask $uhost $nick]" 
							}
								
							putkick $chan $user [lindex $kick_msgs [expr {int(rand() * [llength $kick_msgs])}]]
						} {	
							putquick "PRIVMSG $chan :$nick voted $user Yes. ([expr $user_votes_counter + 1]) Votes."
							add_del_voter $user_host $uhost "add"
						}
					} {
						putquick "PRIVMSG $nick :$vote_msg(twice_on_same_user)"
					}
				} {
					putquick "PRIVMSG $chan :$nick voted $user Yes. (1) Votes."
					put_host [clock seconds] $user_host $uhost
				}
			} elseif {$yes_or_no == "no"} {
				if {[check_user_host $user_host] == "yes"} {
					if {[check_voter_host $user_host $uhost] == "no"} {
						set user_votes_counter [count_voters $user_host]
						if {[expr $user_votes_counter - 1] == 0} {
							putquick "PRIVMSG $chan :$nick voted $user No. (0) Votes."
						} {
							putquick "PRIVMSG $chan :$nick voted $user No. ([expr $user_votes_counter - 1]) Votes."
						}
						add_del_voter $user_host $uhost "del"
					} {
						putquick "PRIVMSG $nick :$vote_msg(twice_on_same_user)"
					}
				} {
					putquick "PRIVMSG $nick :$vote_msg(noone_voted)"
				}
			}
		} {
			putquick "PRIVMSG $nick :$vote_msg(help)"
		}
	} {
		putquick "PRIVMSG $nick :$vote_msg(help)"
	}
}

proc ban_mask { host nick } {
	global bantype

	switch -- $bantype {
		1 {
			set bmask "*!*@[lindex [split [maskhost $host] "@"] 1]"
		}

		2 {
			set bmask "*!*@[lindex [split $host @] 1]"
		}

		3 {
			set bmask "*$nick*!*@[lindex [split $host "@"] 1]"
		}
														                4 {
			set bmask "*!*[lindex [split $host "@"] 0]*@[lindex [split $host "@"] 1]"
		}

		return $bmask
	}
}

proc check_timestamps { } {
	global victim_interval users_file

	set current_timestamp [clock seconds]
	set calc_timestamp [expr $victim_interval * 60]

	set timestamps_file [get_hosts]

	set fresh_timestamp [open $users_file w]
	foreach each_timestamp $timestamps_file {
		if {$each_timestamp != ""} {
			set victim_data [split $each_timestamp " "]
			set victim_timestamp [lindex $victim_data 0]

			if {[expr $current_timestamp - $victim_timestamp] < $calc_timestamp} {
				puts $fresh_timestamp $each_timestamp
			}
		}
	}
	close $fresh_timestamp
}

if {[string match *timestamp_timer* [utimers]] != 1} {                                           
	utimer 60 timestamp_timer
}  
putlog "simple-vote.tcl ver 0.1 by tomekk loaded"
Post Reply