BT.GuestNick.tcl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################### GUESTNICK TCL ###########################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. #########################################################################
  15. proc guestnickpublic {nick host hand chan arg} {
  16. global black lastbind
  17. set who [lindex [split $arg] 0]
  18. set modul "guestnick"
  19. set type 0
  20. set chan1 $chan
  21. set gnick [join [lrange [split $arg] 1 end]]
  22. set number [lindex [split $arg] 1]
  23. if {[regexp {^[&#]} $who] && [matchattr $hand nmo|M $who]} {
  24. set who [lindex [split $arg] 1]
  25. set gnick [join [lrange [split $arg] 2 end]]
  26. set number [lindex [split $arg] 2]
  27. }
  28. set return [blacktools:mychar $lastbind $hand]
  29. if {$return == "0"} {
  30. return
  31. }
  32. guestnick:process $nick $host $hand $chan $chan1 $who $gnick $type $number $modul
  33. }
  34. proc guestnick:process {nick host hand chan chan1 who gnick type number modul} {
  35. global black
  36. set num 0
  37. set temp_num 0
  38. set cmd_status [btcmd:status $chan $hand "guestnick" 0]
  39. if {$cmd_status == "1"} {
  40. return
  41. }
  42. if {[matchattr $hand q]} {
  43. blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  44. return
  45. }
  46. if {[matchattr $hand -|q $chan]} {
  47. blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  48. return
  49. }
  50. if {![validchan $chan]} {
  51. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  52. return
  53. }
  54. switch $who {
  55. on {
  56. setting:set $chan +guestnick ""
  57. blacktools:tell $nick $host $hand $chan $chan1 guestnick.1 none
  58. }
  59. off {
  60. setting:set $chan -guestnick ""
  61. blacktools:tell $nick $host $hand $chan $chan1 guestnick.2 none
  62. }
  63. add {
  64. if {$gnick == ""} {
  65. switch $type {
  66. 0 {
  67. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "guestnick"
  68. }
  69. 1 {
  70. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "guestnick"
  71. }
  72. 2 {
  73. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "guestnick"
  74. }
  75. }
  76. return
  77. }
  78. set findword [prot:findword $chan "GUESTNICK" $gnick]
  79. if {$findword == "1"} {
  80. blacktools:tell $nick $host $hand $chan $chan1 gl.wordexists $gnick
  81. return
  82. }
  83. while {$temp_num == 0} {
  84. set get [find:num $num $chan "GUESTNICK"]
  85. if {$get == "$num"} {
  86. set num [expr $num + 1]
  87. } else { set temp_num 1 }
  88. }
  89. set file [open $black(add_file) a]
  90. set enc_chan [encoding convertto utf-8 $chan]
  91. puts $file "$enc_chan GUESTNICK $num $gnick"
  92. close $file
  93. blacktools:tell $nick $host $hand $chan $chan1 guestnick.3 "$gnick $num"
  94. }
  95. del {
  96. if {![regexp {^[0-9]} $number]} {
  97. switch $type {
  98. 0 {
  99. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "guestnick"
  100. }
  101. 1 {
  102. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "guestnick"
  103. }
  104. 2 {
  105. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "guestnick"
  106. }
  107. }
  108. return
  109. }
  110. set ret [find:num $number $chan "GUESTNICK"]
  111. if {$ret == 0} {
  112. blacktools:tell $nick $host $hand $chan $chan1 guestnick.5 $number
  113. return
  114. }
  115. set file [open $black(add_file) "r"]
  116. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  117. set temp "$black(tempdir)/bt_temp.$timestamp"
  118. set tempwrite [open $temp w]
  119. while {[gets $file line] != -1} {
  120. set read_num [lindex [split $line] 2]
  121. set read_type [lindex [split $line] 1]
  122. set read_chan [lindex [split $line] 0]
  123. set enc_chan [encoding convertfrom utf-8 $read_chan]
  124. if {[string equal $number $read_num] && [string equal $read_type "GUESTNICK"] && [string equal $enc_chan $chan]} {
  125. continue
  126. } else {
  127. puts $tempwrite $line
  128. }
  129. }
  130. close $tempwrite
  131. close $file
  132. file rename -force $temp $black(add_file)
  133. blacktools:tell $nick $host $hand $chan $chan1 guestnick.4 $number
  134. }
  135. list {
  136. array set nicklist [list]
  137. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  138. set temp "$black(tempdir)/nick_temp.$timestamp"
  139. set file [open $black(add_file) "r"]
  140. set w [read -nonewline $file]
  141. close $file
  142. set data [split $w "\n"]
  143. foreach line $data {
  144. set read_chan [lindex [split $line] 0]
  145. set enc_chan [encoding convertfrom utf-8 $read_chan]
  146. set read_type [lindex [split $line] 1]
  147. if {[string match -nocase $enc_chan $chan] && [string match -nocase $read_type "GUESTNICK"]} {
  148. set msg_num [lindex [split $line] 2]
  149. set message [lrange [split $line] 3 end]
  150. lappend nicklist($msg_num) $message
  151. }
  152. }
  153. set tempwrite [open $temp w]
  154. foreach msg [lsort -integer -increasing [array names nicklist]] {
  155. puts $tempwrite "$msg [join $nicklist($msg)]"
  156. }
  157. close $tempwrite
  158. set file [open $temp "r"]
  159. set w [read -nonewline $file]
  160. close $file
  161. set data [split $w "\n"]
  162. file delete $temp
  163. module:getinfo $nick $host $hand $chan $chan1 $type $data "guestnick" "0" $number
  164. }
  165. default {
  166. switch $type {
  167. 0 {
  168. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "guestnick"
  169. }
  170. 1 {
  171. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "guestnick"
  172. }
  173. 2 {
  174. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "guestnick"
  175. }
  176. }
  177. }
  178. }
  179. }
  180. proc guestnick:module {nick host hand chan} {
  181. global black
  182. if {![validchan $chan]} {
  183. return
  184. }
  185. if {[setting:get $chan guestnick]} {
  186. if {[info exists black(turnOnFlood:$chan)]} {
  187. return
  188. }
  189. set getlang [string tolower [setting:get $chan lang]]
  190. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  191. set method [setting:get $chan guestnick-msgmethod]
  192. if {$method == ""} {
  193. set method $black(guestnick:msgmethod)
  194. }
  195. set file [open $black(add_file) r]
  196. while {[gets $file line] != -1} {
  197. set read_chan [lindex [split $line] 0]
  198. set read_type [lindex [split $line] 1]
  199. set read_msg [lrange [split $line] 3 end]
  200. if {[string equal -nocase $read_chan $chan] && [string equal -nocase $read_type "GUESTNICK"] && [string match -nocase $read_msg $nick]} {
  201. set replace(%nick%) $nick
  202. set replace(%chan%) $chan
  203. set message [setting:get $chan guestnick-message]
  204. if {$message == ""} {
  205. set message $black(say.$getlang.guestnick.10)
  206. }
  207. set message [string map [array get replace] $message]
  208. switch [string tolower $method] {
  209. chan {
  210. putserv "PRIVMSG $chan :$message"
  211. }
  212. privmsg {
  213. putserv "PRIVMSG $nick :$message"
  214. }
  215. notice {
  216. putserv "NOTICE $nick :$message"
  217. }
  218. }
  219. }
  220. }
  221. close $file
  222. }
  223. }
  224. ##############
  225. #########################################################################
  226. ## END ##
  227. #########################################################################