Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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_dir "users"
- # kick msg
- set kick_msg "bye!"
- ###############################################################################################
- bind pub -|- !vote vote_proc
- setudef flag vote
- if {![file exists $users_dir]} {
- file mkdir $users_dir
- }
- proc put_host { user_host voter_host chan } {
- global users_dir
- set put_vote [open $users_dir/$chan/$user_host a]
- puts $put_vote $voter_host
- close $put_vote
- }
- proc get_hosts { user_host chan } {
- global users_dir
- set get_hosts [open $users_dir/$chan/$user_host r]
- set get_all [split [read $get_hosts] "\n"]
- close $get_hosts
- return $get_all
- }
- proc del_host { user_host voter_host chan } {
- global users_dir
- set old_votes [get_hosts $user_host $chan]
- set new_votes [open $users_dir/$chan/$user_host w]
- foreach host $old_votes {
- if {$host != ""} {
- if {$host != $voter_host} {
- puts $new_votes $host
- }
- }
- }
- close $new_votes
- }
- proc check_host { user_host voter_host chan } {
- set host_exists 0
- foreach host [get_hosts $user_host $chan] {
- if {$host != ""} {
- if {$host == $voter_host} {
- set host_exists 1
- break
- }
- }
- }
- return $host_exists
- }
- proc vote_proc { nick uhost hand chan arg } {
- global users_dir vote_limit botnick kick_msg
- set args [split $arg]
- set user [lindex $args 0]
- set yes_or_no [lindex $args 1]
- if {![channel get $chan vote]} {
- return
- }
- if {[isbotnick $user]} {
- return
- }
- if {[file exists $users_dir/$chan/$uhost]} {
- return
- }
- if {![file exists $users_dir/$chan]} {
- file mkdir $users_dir/$chan
- }
- if {$user != ""} {
- if {($yes_or_no == "yes") || ($yes_or_no == "no")} {
- if {[onchan $user $chan]} {
- set user_host [getchanhost $user $chan]
- if {$yes_or_no == "yes"} {
- if {![file exists $users_dir/$chan/$user_host]} {
- set touch_user [open $users_dir/$chan/$user_host w]
- close $touch_user
- }
- set user_host_counter [llength [get_hosts $user_host $chan]]
- if {$user_host_counter < $vote_limit} {
- if {[check_host $user_host [getchanhost $nick $chan] $chan] == 0} {
- put_host $user_host [getchanhost $nick $chan] $chan
- if {$user_host_counter == 0} {
- putquick "PRIVMSG $chan :$nick voted $user Yes. (1) Votes."
- } {
- putquick "PRIVMSG $chan :$nick voted $user Yes. ($user_host_counter) Votes."
- }
- } {
- putquick "PRIVMSG $nick :sorry, you can't vote yes twice on the same user"
- }
- } {
- putquick "PRIVMSG $chan :$nick voted $user Yes. ($vote_limit) Votes."
- putkick $chan $user $kick_msg
- file delete $users_dir/$chan/$user_host
- }
- }
- if {$yes_or_no == "no"} {
- if {![file exists $users_dir/$chan/$user_host]} {
- putquick "PRIVMSG $nick :sorry, no one voted on this user before"
- }
- set user_host_counter [llength [get_hosts $user_host $chan]]
- if {$user_host_counter > 0} {
- set user_host_counter [expr $user_host_counter - 1]
- }
- if {$user_host_counter == 1} {
- putquick "PRIVMSG $chan :$nick voted $user No. (0) Votes."
- file delete $users_dir/$chan/$user_host
- } {
- if {[check_host $user_host [getchanhost $nick $chan] $chan] == 1} {
- del_host $user_host [getchanhost $nick $chan] $chan
- putquick "PRIVMSG $chan :$nick voted $user No. ([expr $user_host_counter - 1]) Votes."
- } {
- putquick "PRIVMSG $nick :sorry, you didn't vote for this user"
- }
- }
- }
- } {
- putquick "PRIVMSG $nick :wrong user name"
- }
- } {
- putquick "PRIVMSG $nick :use: !vote <user> <yes/no>"
- }
- } {
- putquick "PRIVMSG $nick :use: !vote <user> <yes/no>"
- }
- }
- putlog "simple-vote.tcl ver 0.1 by tomekk loaded"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement