BT.Alias.tcl 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ############################ ALIAS TCL ##############################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. #########################################################################
  16. ###
  17. proc alias:process {nick host hand chan chan1 type arg} {
  18. global botnick black username
  19. set cmd_status [btcmd:status $chan $hand "alias" 0]
  20. if {$cmd_status == "1"} {
  21. return
  22. }
  23. if {[matchattr $hand q]} { blacktools:tell_v2 $nick $host $hand $chan $chan1 gl.glsuspend none
  24. return
  25. }
  26. if {[matchattr $hand -|q $chan]} { blacktools:tell_v2 $nick $host $hand $chan $chan1 gl.suspend none
  27. return
  28. }
  29. set what [lindex $arg 0]
  30. set cmd [lindex $arg 1]
  31. set cmd_used [lindex $arg 2]
  32. set text [lindex $arg 3]
  33. set text2 [join [lrange $arg 2 3]]
  34. switch [string tolower $what] {
  35. add {
  36. if {$cmd == ""} {
  37. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.1 none
  38. return
  39. }
  40. if {$cmd_used == ""} {
  41. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.1 none
  42. return
  43. }
  44. set valid [blacktools:alias_valid $hand $cmd_used $chan]
  45. if {$valid == 1} {
  46. set exists [blacktools:alias_check $hand $cmd]
  47. if {$exists != 0} {
  48. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.3 [list $cmd $exists]
  49. return
  50. } else {
  51. if {$text == ""} {
  52. set text $cmd_used
  53. } else {
  54. set text $text2
  55. }
  56. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.4 [list $cmd $text]
  57. blacktools:alias_add $hand $cmd $text
  58. }
  59. } else {
  60. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.2 [list $cmd_used]
  61. }
  62. }
  63. del {
  64. set exists [blacktools:alias_check $hand $cmd]
  65. if {$exists == 0} {
  66. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.5 [list $cmd]
  67. return
  68. }
  69. blacktools:alias_del $hand $cmd
  70. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.6 [list $cmd]
  71. }
  72. default {
  73. if {$type == "0"} {
  74. blacktools:tell_v2 $nick $host $hand $chan $chan1 gl.instr [list "alias"]
  75. }
  76. if {$type == "1"} {
  77. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick [list "alias"]
  78. }
  79. if {$type == "2"} {
  80. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv [list "alias"]
  81. }
  82. }
  83. }
  84. }
  85. ###
  86. proc blacktools:alias_check {hand command} {
  87. global black
  88. set file [open $black(alias_file) r]
  89. set data [read -nonewline $file]
  90. close $file
  91. set found ""
  92. set split_data [split $data "\n"]
  93. foreach line $split_data {
  94. set read_hand [lindex [split $line] 0]
  95. set read_cmd [lindex [split $line] 1]
  96. if {[string equal -nocase $read_cmd $command] && [string equal -nocase $read_hand $hand]} {
  97. set found [lrange [split $line] 2 end]
  98. break
  99. }
  100. }
  101. if {$found == ""} {return 0} else {
  102. return $found
  103. }
  104. }
  105. ###
  106. proc blacktools:alias_get {hand chan} {
  107. global black
  108. set file [open $black(alias_file) r]
  109. set data [read -nonewline $file]
  110. close $file
  111. set split_data [split $data "\n"]
  112. set output ""
  113. foreach line $split_data {
  114. set read_hand [lindex [split $line] 0]
  115. if {[string equal -nocase $hand $read_hand]} {
  116. set cmd [lindex [split $line] 1]
  117. set cmd_used [lindex [split $line] 2]
  118. set rest [lrange [split $line] 2 end]
  119. set check_valid [blacktools:alias_valid $hand $cmd_used $chan]
  120. if {$check_valid == 0} {continue}
  121. lappend output "[black:color 1 $hand $cmd] \[[black:color 6 $hand $rest]\]"
  122. }
  123. }
  124. if {$output == ""} {return 0} else {
  125. return [join $output " ; "]
  126. }
  127. }
  128. ###
  129. proc blacktools:alias_valid {hand cmd chan} {
  130. set cmds_op "alias note q troll vr dr bot n id spam bw mb b ub sb banlist r man h version seen info userlist mode cycle ho o t k w ungag gag clonescan myset i next helped noidle skip"
  131. set cmds_admin "alias note q troll vr dr bot n id spam bw mb black bl b ub sb banlist r man auto h ignore version stats seen us s info userlist delhost delacc add omsg mode cycle say v ho o t k w ungag gag clonescan topwords myset i next helped noidle skip"
  132. set cmds_manager "alias exempt anunt note q enable disable securemode troll guestnick badhost antispam badrealname badquitpart badident badnick badword unset greet leave topic vr dr n id spam bw mb black bl b stick ub sb banlist r man auto antipub private h ignore idle version stats seen limit badchan us s info userlist chuser delhost addhost del delacc add omsg set mode cycle purge act say v ho o t k w ungag gag show clonescan topwords myset i badword next helped noidle skip"
  133. set cmds_master "alias exempt anunt anunt note q enable disable securemode troll guestnick badhost antispam badrealname badquitpart badident badnick badword unset greet leave topic vr dr n id spam bw mb black bl b stick ub sb banlist r man auto antipub private h ignore idle version stats seen limit badchan us s info channels userlist chuser delhost addhost del delacc add unsuspend suspend delchan addchan msg omsg set mode cycle act say v ho o uptime status t k w gag show clonescan topwords myset i badword next helped noidle skip"
  134. set cmds_owner "alias exempt login anunt link note q enable disable securemode cp troll guestnick badhost antispam badrealname badquitpart badident badnick badword unset greet leave topic vr dr n id spam bw mb black bl b stick ub sb banlist r man auto antipub private h ignore idle version stats chat seen limit bt badchan us s info channels userlist chuser delhost addhost del delacc add unsuspend suspend delchan addchan die jump save restart rehash nick msg omsg set mode cycle broadcast act say v ho o uptime status t k w ungag gag show clonescan topwords myset timer i badword next helped noidle skip"
  135. set cmds_boss "alias exempt login anunt link note q enable disable securemode cp troll guestnick badhost antispam badrealname badquitpart badident badnick badword unset greet leave topic vr dr n id spam bw mb black bl b stick ub sb banlist r man auto antipub private tcl h ignore idle version stats chat seen limit bt badchan us s info channels userlist chuser delhost addhost del delacc add unsuspend suspend delchan addchan die jump save restart rehash update nick msg omsg set mode cycle broadcast act say v ho o uptime status t k w ungag gag show clonescan topwords myset timer i badword next helped noidle skip"
  136. if {[matchattr $hand n]} {
  137. if {[lsearch -nocase $cmds_boss $cmd] > -1} {
  138. return 1
  139. } else {return 0}
  140. } elseif {[matchattr $hand m]} {
  141. if {[lsearch -nocase $cmds_owner $cmd] > -1} {
  142. return 1
  143. } else {return 0}
  144. } elseif {[matchattr $hand o]} {
  145. if {[lsearch -nocase $cmds_master $cmd] > -1} {
  146. return 1
  147. } else {return 0}
  148. } elseif {[matchattr $hand -|M $chan]} {
  149. if {[lsearch -nocase $cmds_manager $cmd] > -1} {
  150. return 1
  151. } else {return 0}
  152. } elseif {[matchattr $hand -|A $chan]} {
  153. if {[lsearch -nocase $cmds_admin $cmd] > -1} {
  154. return 1
  155. } else {return 0}
  156. } elseif {[matchattr $hand -|O $chan]} {
  157. if {[lsearch -nocase $cmds_op $cmd] > -1} {
  158. return 1
  159. } else {return 0}
  160. }
  161. }
  162. ###
  163. proc blacktools:alias_add {hand command text} {
  164. global black
  165. set file [open $black(alias_file) a]
  166. puts $file "$hand $command $text"
  167. close $file
  168. return 1
  169. }
  170. ###
  171. proc blacktools:alias_del {hand command} {
  172. global black
  173. set file [open $black(alias_file) "r"]
  174. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  175. set temp "$black(tempdir)/notes_temp.$timestamp"
  176. set tempwrite [open $temp w]
  177. while {[gets $file line] != -1} {
  178. set read_hand [lindex [split $line] 0]
  179. set read_cmd [lindex [split $line] 1]
  180. if {[string equal -nocase $read_hand $hand] && [string equal -nocase $read_cmd $command]} {
  181. continue
  182. } else {
  183. puts $tempwrite $line
  184. }
  185. }
  186. close $tempwrite
  187. close $file
  188. file rename -force $temp $black(alias_file)
  189. return 1
  190. }