Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. # Author: tomekk
  2. # e-mail: tomekk/@/oswiecim/./eu/./org
  3. # home page: http://tomekk.oswiecim.eu.org/
  4. #
  5. # Version 0.1
  6. #
  7. # This file is Copyrighted under the GNU Public License.
  8. # http://www.gnu.org/copyleft/gpl.html
  9. #
  10. # if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)
  11. # .chanset #channel_name +vote
  12. # and later .save
  13.  
  14. # ban after X yes votes
  15. set vote_limit 5
  16.  
  17. # dir with users data
  18. set users_dir "users"
  19.  
  20. # kick msg
  21. set kick_msg "bye!"
  22.  
  23. ###############################################################################################
  24. bind pub -|- !vote vote_proc
  25.  
  26. setudef flag vote
  27.  
  28. if {![file exists $users_dir]} {
  29. file mkdir $users_dir
  30. }
  31.  
  32. proc put_host { user_host voter_host chan } {
  33. global users_dir
  34.  
  35. set put_vote [open $users_dir/$chan/$user_host a]
  36. puts $put_vote $voter_host
  37. close $put_vote
  38. }
  39.  
  40. proc get_hosts { user_host chan } {
  41. global users_dir
  42.  
  43. set get_hosts [open $users_dir/$chan/$user_host r]
  44. set get_all [split [read $get_hosts] "\n"]
  45. close $get_hosts
  46.  
  47. return $get_all
  48. }
  49.  
  50. proc del_host { user_host voter_host chan } {
  51. global users_dir
  52.  
  53. set old_votes [get_hosts $user_host $chan]
  54.  
  55. set new_votes [open $users_dir/$chan/$user_host w]
  56. foreach host $old_votes {
  57. if {$host != ""} {
  58. if {$host != $voter_host} {
  59. puts $new_votes $host
  60. }
  61. }
  62. }
  63. close $new_votes
  64. }
  65.  
  66. proc check_host { user_host voter_host chan } {
  67. set host_exists 0
  68.  
  69. foreach host [get_hosts $user_host $chan] {
  70. if {$host != ""} {
  71. if {$host == $voter_host} {
  72. set host_exists 1
  73. break
  74. }
  75. }
  76. }
  77.  
  78. return $host_exists
  79. }
  80.  
  81. proc vote_proc { nick uhost hand chan arg } {
  82. global users_dir vote_limit botnick kick_msg
  83.  
  84. set args [split $arg]
  85. set user [lindex $args 0]
  86. set yes_or_no [lindex $args 1]
  87.  
  88. if {![channel get $chan vote]} {
  89. return
  90. }
  91.  
  92. if {[isbotnick $user]} {
  93. return
  94. }
  95.  
  96. if {[file exists $users_dir/$chan/$uhost]} {
  97. return
  98. }
  99.  
  100. if {![file exists $users_dir/$chan]} {
  101. file mkdir $users_dir/$chan
  102. }
  103.  
  104. if {$user != ""} {
  105. if {($yes_or_no == "yes") || ($yes_or_no == "no")} {
  106. if {[onchan $user $chan]} {
  107. set user_host [getchanhost $user $chan]
  108.  
  109. if {$yes_or_no == "yes"} {
  110. if {![file exists $users_dir/$chan/$user_host]} {
  111. set touch_user [open $users_dir/$chan/$user_host w]
  112. close $touch_user
  113. }
  114.  
  115. set user_host_counter [llength [get_hosts $user_host $chan]]
  116. if {$user_host_counter < $vote_limit} {
  117. if {[check_host $user_host [getchanhost $nick $chan] $chan] == 0} {
  118. put_host $user_host [getchanhost $nick $chan] $chan
  119.  
  120. if {$user_host_counter == 0} {
  121. putquick "PRIVMSG $chan :$nick voted $user Yes. (1) Votes."
  122. } {
  123. putquick "PRIVMSG $chan :$nick voted $user Yes. ($user_host_counter) Votes."
  124. }
  125. } {
  126. putquick "PRIVMSG $nick :sorry, you can't vote yes twice on the same user"
  127. }
  128. } {
  129. putquick "PRIVMSG $chan :$nick voted $user Yes. ($vote_limit) Votes."
  130. putquick "MODE $chan +b *!*$user_host"
  131.  
  132. putkick $chan $user $kick_msg
  133.  
  134. file delete $users_dir/$chan/$user_host
  135. }
  136. }
  137.  
  138. if {$yes_or_no == "no"} {
  139. if {![file exists $users_dir/$chan/$user_host]} {
  140. putquick "PRIVMSG $nick :sorry, no one voted on this user before"
  141. }
  142.  
  143. set user_host_counter [llength [get_hosts $user_host $chan]]
  144.  
  145. if {$user_host_counter > 0} {
  146. set user_host_counter [expr $user_host_counter - 1]
  147. }
  148.  
  149. if {$user_host_counter == 1} {
  150. putquick "PRIVMSG $chan :$nick voted $user No. (0) Votes."
  151. file delete $users_dir/$chan/$user_host
  152. } {
  153. if {[check_host $user_host [getchanhost $nick $chan] $chan] == 1} {
  154. del_host $user_host [getchanhost $nick $chan] $chan
  155. putquick "PRIVMSG $chan :$nick voted $user No. ([expr $user_host_counter - 1]) Votes."
  156. } {
  157. putquick "PRIVMSG $nick :sorry, you didn't vote for this user"
  158. }
  159. }
  160. }
  161. } {
  162. putquick "PRIVMSG $nick :wrong user name"
  163. }
  164. } {
  165. putquick "PRIVMSG $nick :use: !vote <user> <yes/no>"
  166. }
  167. } {
  168. putquick "PRIVMSG $nick :use: !vote <user> <yes/no>"
  169. }
  170. }
  171.  
  172. putlog "simple-vote.tcl ver 0.1 by tomekk loaded"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement