BT.Alias.tcl 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. set cmds [join [lrange $arg 2 end]]
  35. set split_cmds [wsplit $cmds "|"]
  36. set llength_cmd [llength $split_cmds]
  37. switch [string tolower $what] {
  38. add {
  39. if {$llength_cmd == 0} {
  40. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.1 none
  41. return
  42. }
  43. if {$cmd_used == ""} {
  44. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.1 none
  45. return
  46. }
  47. set invalidCmd 0
  48. for {set i 0} { $i < $llength_cmd} {incr i} {
  49. if {[concat [lindex $split_cmds $i]] == ""} {
  50. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.2 "N/A"
  51. set invalidCmd 1
  52. break
  53. }
  54. set valid [blacktools:alias_valid $hand [lindex [lindex $split_cmds $i] 0] $chan]
  55. if {$valid == 0} {
  56. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.2 [lindex [lindex $split_cmds $i] 0]
  57. set invalidCmd 1
  58. break
  59. }
  60. }
  61. if {$invalidCmd == 1} {
  62. return
  63. }
  64. set exists [blacktools:alias_check $hand $cmd]
  65. if {$exists != 0} {
  66. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.3 [list $cmd $exists]
  67. return
  68. } else {
  69. if {$text == ""} {
  70. set text $cmd_used
  71. } else {
  72. set text $text2
  73. }
  74. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.4 [list $cmd $text]
  75. blacktools:alias_add $hand $cmd $text
  76. }
  77. }
  78. del {
  79. set exists [blacktools:alias_check $hand $cmd]
  80. if {$exists == 0} {
  81. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.5 [list $cmd]
  82. return
  83. }
  84. blacktools:alias_del $hand $cmd
  85. blacktools:tell_v2 $nick $host $hand $chan $chan1 alias.6 [list $cmd]
  86. }
  87. default {
  88. if {$type == "0"} {
  89. blacktools:tell_v2 $nick $host $hand $chan $chan1 gl.instr [list "alias"]
  90. }
  91. if {$type == "1"} {
  92. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick [list "alias"]
  93. }
  94. if {$type == "2"} {
  95. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv [list "alias"]
  96. }
  97. }
  98. }
  99. }
  100. ###
  101. proc blacktools:alias_check {hand command} {
  102. global black
  103. set file [open $black(alias_file) r]
  104. set data [read -nonewline $file]
  105. close $file
  106. set found ""
  107. set split_data [split $data "\n"]
  108. foreach line $split_data {
  109. set read_hand [lindex [split $line] 0]
  110. set read_cmd [lindex [split $line] 1]
  111. if {[string equal -nocase $read_cmd $command] && [string equal -nocase $read_hand $hand]} {
  112. set found [lrange [split $line] 2 end]
  113. break
  114. }
  115. }
  116. if {$found == ""} {return 0} else {
  117. return $found
  118. }
  119. }
  120. ###
  121. proc blacktools:alias_get {hand chan} {
  122. global black
  123. set file [open $black(alias_file) r]
  124. set data [read -nonewline $file]
  125. close $file
  126. set split_data [split $data "\n"]
  127. set output ""
  128. foreach line $split_data {
  129. set read_hand [lindex [split $line] 0]
  130. if {[string equal -nocase $hand $read_hand]} {
  131. set cmd [lindex [split $line] 1]
  132. set cmd_used [lindex [split $line] 2]
  133. set rest [lrange [split $line] 2 end]
  134. set check_valid [blacktools:alias_valid $hand $cmd_used $chan]
  135. if {$check_valid == 0} {continue}
  136. lappend output "[black:color 1 $hand $cmd] \[[black:color 6 $hand $rest]\]"
  137. }
  138. }
  139. if {$output == ""} {return 0} else {
  140. return [join $output " ; "]
  141. }
  142. }
  143. ###
  144. proc blacktools:alias_valid {hand cmd chan} {
  145. 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"
  146. 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"
  147. 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"
  148. 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"
  149. 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"
  150. 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"
  151. if {[matchattr $hand n]} {
  152. if {[lsearch -nocase $cmds_boss $cmd] > -1} {
  153. return 1
  154. } else {return 0}
  155. } elseif {[matchattr $hand m]} {
  156. if {[lsearch -nocase $cmds_owner $cmd] > -1} {
  157. return 1
  158. } else {return 0}
  159. } elseif {[matchattr $hand o]} {
  160. if {[lsearch -nocase $cmds_master $cmd] > -1} {
  161. return 1
  162. } else {return 0}
  163. } elseif {[matchattr $hand -|M $chan]} {
  164. if {[lsearch -nocase $cmds_manager $cmd] > -1} {
  165. return 1
  166. } else {return 0}
  167. } elseif {[matchattr $hand -|A $chan]} {
  168. if {[lsearch -nocase $cmds_admin $cmd] > -1} {
  169. return 1
  170. } else {return 0}
  171. } elseif {[matchattr $hand -|O $chan]} {
  172. if {[lsearch -nocase $cmds_op $cmd] > -1} {
  173. return 1
  174. } else {return 0}
  175. }
  176. }
  177. ###
  178. proc blacktools:alias_add {hand command text} {
  179. global black
  180. set file [open $black(alias_file) a]
  181. puts $file "$hand $command $text"
  182. close $file
  183. return 1
  184. }
  185. ###
  186. proc blacktools:alias_del {hand command} {
  187. global black
  188. set file [open $black(alias_file) "r"]
  189. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  190. set temp "$black(tempdir)/notes_temp.$timestamp"
  191. set tempwrite [open $temp w]
  192. while {[gets $file line] != -1} {
  193. set read_hand [lindex [split $line] 0]
  194. set read_cmd [lindex [split $line] 1]
  195. if {[string equal -nocase $read_hand $hand] && [string equal -nocase $read_cmd $command]} {
  196. continue
  197. } else {
  198. puts $tempwrite $line
  199. }
  200. }
  201. close $tempwrite
  202. close $file
  203. file rename -force $temp $black(alias_file)
  204. return 1
  205. }