Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. # autoReinvite by Artix <loyauflorian@gmail.com>
  2. # Version: 1.0 #boulets - 30/10/2010
  3. #
  4. # Compatibility: Requires eggdrop 1.6 (1.8 should work too), Tcl8.5/8.6
  5. # and the channels, server and irc modules.
  6. #
  7. # Since the script uses the watch list, you'll need to be on an unrealIRCd server
  8. # that supports it. I haven't heard of other server type that support it so far.
  9. #
  10. # Note that using other scripts that count on the watchlist at same time is a bad idea.
  11. #
  12. # Contact me by mail at loyauflorian@gmail.com
  13. # or on IRC, irc.epiknet.org, channel #eggdrop
  14. #
  15. #
  16. #
  17. # Script description:
  18. #
  19. # Auto-reinvites (yeah, seriously!) people on a chan under
  20. # specific events.
  21. #
  22. # Features:
  23. # - Auto-reinvite on part or kick
  24. # - Add to watch list when quitting (or netsplit loss)
  25. # - Auto-invite when reconnecting while in watch list
  26. # - The watch list is saved in a database file
  27. # - Automatic trimming of the database
  28. # - Invites done only if the guy is not banned on channel
  29. # - Fully (but lightly) commented code
  30. #
  31. # Branched at 1.1 as 1.0 #boulets
  32. #
  33. # Version 1.0 #boulets:
  34. # - Local watch database saving and channel kick reinvite were removed
  35. # - Users are now added to the database when quitting only if the quit has
  36. # "Ping timeout" or "Connection reset by peer" message EXACTLY.
  37. # - Added watchs are now removed after an amount of time set within the
  38. # unsetafter variable
  39. #
  40. # Version 1.1:
  41. # - Bindings uninstalling now properly working, thanks to MenzAgitat
  42. # - Same for bindings that would trigger on EVERY channel. Thanks once more.
  43. # - When the watchlist is full, oldest entries are now removed - instead of
  44. # removing a random entry from the list.
  45. #
  46. #
  47. # Note that the database isn't supposed to be modified or
  48. # read. Let the script do the stuff, and delete the file
  49. # if you want to erase the database.
  50. #
  51. # The database is saved at hourly-updates time set in
  52. # the config file, once every hour.
  53. # You can change this at the end of the file if needed.
  54. #
  55. # YOU HAVE TO set the chan below in the configuration
  56. # for the script to work.
  57. #
  58. # Thanks to thommey of eggheads for fixing
  59. # my poor database writing code ._.'
  60.  
  61.  
  62.  
  63. # If the file was sourced already, better get rid of everything
  64. # before reloading it.
  65. if {[info procs ::autoReinvite::uninstall] ne ""} { ::autoReinvite::uninstall }
  66.  
  67. namespace eval ::autoReinvite {
  68.  
  69. #===================
  70. ## CONFIG START ##
  71. #===================
  72.  
  73. # UNIQUE chan the script will work on
  74. variable bindedchan "#access0"
  75.  
  76. # Toggles invites
  77. variable enabled 1
  78.  
  79. # Unset watchs after how many seconds?
  80. variable unsetafter 600
  81.  
  82. # Maximum entries in the database
  83. # Technical notes: previous entries will be replaced,
  84. # the script won't delete any entry while running.
  85. # The watch list is only trimmmed when saving.
  86. variable maxwatch 50
  87.  
  88. ## CONFIG END ##
  89.  
  90.  
  91.  
  92. # Watch List initialisation
  93. variable watchlist {}
  94.  
  95. # Either add or remove the whole watchlist at once
  96. # + to add, - to remove all
  97. proc modwatch {symbol} {
  98. variable watchlist
  99.  
  100. # Add every nick to watch one by one
  101. foreach entry $watchlist {
  102. lappend output "$symbol[lindex $entry 0]"
  103. }
  104.  
  105. # Send 'em to the server.
  106. if {![info exists output]} return
  107. putquick "WATCH [join $output]"
  108. }
  109.  
  110. # Clear watches and bindings, save DB, delete the namespace
  111. proc uninstall {args} {
  112. modwatch -
  113. foreach bind [binds ::autoReinvite::*] {
  114. catch { unbind [lindex $bind 0] [lindex $bind 1] [lindex $bind 2] [lindex $bind 4] }
  115. }
  116. foreach timer [lsearch -inline -all -index 1 [utimers] "::autoReinvite::*"] {
  117. catch { killutimer [lindex $timer 2] }
  118. }
  119. namespace delete ::autoReinvite
  120. return }
  121.  
  122. # If a watch get detected, invite the guy.
  123. proc watchDetection {from keyword data} {
  124. set data [split $data]
  125. ::autoReinvite::invite [lindex $data 1] [lindex $data 2]@[lindex $data 3] }
  126.  
  127. # In case of a part, we reinvite the guy!
  128. proc partDetection {nick uhost hand chan reason} { ::autoReinvite::invite $nick $uhost 1 }
  129.  
  130. # Invite someone.. if he's not banned!
  131. proc invite {nick uhost {override_onchan_check 0}} {
  132. # NOTE: We need an argument to override the onchan check
  133. # because the bot will say someone that triggered a part
  134. # or kick bind is still on channel.
  135.  
  136. variable enabled
  137. variable bindedchan
  138.  
  139. # If the guy's already here, or the script disabled, don't bother
  140. if {([onchan $nick $bindedchan] && !$override_onchan_check) || !$enabled} return
  141.  
  142. # Check every chan ban for a match
  143. foreach line [chanbans $bindedchan] {
  144. if {[string match -nocase [string map "\[ \\\[ \] \\\]" [lindex $line 0]] $nick!$uhost]} return
  145. }
  146.  
  147. # In case everything's ok, we just invite him.
  148. putquick "INVITE $nick $bindedchan"
  149. }
  150.  
  151. # Add someone to the watchlist and start
  152. # watching him.
  153. proc addWatch {nick uhost hand chan reason} {
  154. variable bindedchan
  155. variable watchlist
  156. variable maxwatch
  157.  
  158. # Cancel if it's the wrong chan or reason
  159. if {$chan ne $bindedchan || (($reason ne "Ping timeout") && ($reason ne "Connection reset by peer"))} return
  160.  
  161. # Clear previous matching watches
  162. if {![clearWatch $nick $uhost $hand 1]} {
  163. # Start watching the guy on IRC
  164. putquick "WATCH +$nick"
  165. }
  166. # Add a fresh watch in the list
  167. lappend watchlist [list $nick $uhost $hand]
  168. # If the watchlist grows too big, we delete the first entry in the list
  169. if {([llength $watchlist] - 1) > $maxwatch} {
  170. clearWatch {*}[lindex $watchlist 0]
  171. putlog clear
  172. }
  173. utimer $::autoReinvite::unsetafter [list ::autoReinvite::clearWatch {*}[lindex $watchlist 0]]
  174. }
  175.  
  176. # Deletes a current watch (on channel join)
  177. proc delWatch {nick uhost hand chan args} {
  178. variable bindedchan
  179. # Just laugh loud if it's the bot joining or wrong chan
  180. if {$nick eq $::nick || $chan ne $bindedchan} return
  181. # Else remove the watch
  182. clearWatch $nick $uhost $hand
  183. # Pretty simple eh?
  184. return
  185. }
  186.  
  187. # Clears a watch from the watchlist
  188. # Based on nick/uhost/handle
  189. # Stuff matching either one will get removed
  190. # Corresponding IRC watchs get removed as well
  191. proc clearWatch {nick uhost hand {nowatch 0}} {
  192. variable watchlist
  193.  
  194. # If the list is empty, just gtfo! Might cause errors otherwise.
  195. if {![llength $watchlist]} { return 0 }
  196.  
  197. # If the nick matchs an existing watch, remove it
  198. if {[set nickIndex [lsearch -exact -index 0 $watchlist $nick]] != -1} { removeEntry $nickIndex
  199. # Same for userhost...
  200. } elseif {[set uhostIndex [lsearch -exact -index 1 $watchlist $uhost]] != -1} { removeEntry $uhostIndex
  201. # ...and handle.
  202. } elseif {$hand ne "*" && [set handIndex [lsearch -exact -index 2 $watchlist $hand]] != -1} { removeEntry $handIndex
  203.  
  204. # If a match was found, we remove the watch on IRC too
  205. } else { return 0 }
  206.  
  207. if {!$nowatch} { putquick "WATCH -$nick" }
  208. return 1
  209. }
  210.  
  211. # Deletes an entry from the watchlist in a conveninent way
  212. proc removeEntry {index} {
  213. variable watchlist
  214. set watchlist [lreplace $watchlist $index $index]
  215. }
  216.  
  217. # Bind on 'logged in' watch message
  218. bind raw - 600 ::autoReinvite::watchDetection
  219. # Bind on someone parting to reinvite him asap
  220. bind part - "$::autoReinvite::bindedchan *" ::autoReinvite::partDetection
  221. # Bind on someone quitting to add the watch
  222. bind sign - "$::autoReinvite::bindedchan *" ::autoReinvite::addWatch
  223. # Bind on someone rejoining to remove the watch
  224. bind join - "$::autoReinvite::bindedchan *" ::autoReinvite::delWatch
  225. # rehash script uninstall binding
  226. bind evnt - prerehash ::autoReinvite::uninstall
  227.  
  228. putlog "autoReinvite by Artix <loyauflorian@gmail.com> loaded succesfully."
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement