Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.08 KB | None | 0 0
  1. # autoReinvite by Artix <loyauflorian@gmail.com>
  2. # Version: 1.1 - 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. # - Hourly saving of the database
  29. # - Invites done only if the guy is not banned on channel
  30. # - Fully (but lightly) commented code
  31. #
  32. # Version 1.1:
  33. # - Bindings uninstalling now properly working, thanks to MenzAgitat
  34. # - Same for bindings that would trigger on EVERY channel. Thanks once more.
  35. # - When the watchlist is full, oldest entries are now removed - instead of
  36. # removing a random entry from the list.
  37. #
  38. #
  39. # Note that the database isn't supposed to be modified or
  40. # read. Let the script do the stuff, and delete the file
  41. # if you want to erase the database.
  42. #
  43. # The database is saved at hourly-updates time set in
  44. # the config file, once every hour.
  45. # You can change this at the end of the file if needed.
  46. #
  47. # YOU HAVE TO set the chan below in the configuration
  48. # for the script to work.
  49. #
  50. # Thanks to thommey of eggheads for fixing
  51. # my poor database writing code ._.'
  52.  
  53.  
  54.  
  55. # If the file was sourced already, better get rid of everything
  56. # before reloading it.
  57. if {[info procs ::autoReinvite::uninstall] ne ""} { ::autoReinvite::uninstall }
  58.  
  59. namespace eval ::autoReinvite {
  60.  
  61. #===================
  62. ## CONFIG START ##
  63. #===================
  64.  
  65. # UNIQUE chan the script will work on
  66. variable bindedchan "#insert-your-chan-here"
  67.  
  68. # Toggles invites
  69. variable enabled 1
  70.  
  71. # Path to the watch nick database
  72. variable watchdb "autoReinvite.db"
  73.  
  74. # Maximum entries in the database
  75. # Technical notes: previous entries will be replaced,
  76. # the script won't delete any entry while running.
  77. # The watch list is only trimmmed when saving.
  78. variable maxwatch 50
  79.  
  80. ## CONFIG END ##
  81.  
  82.  
  83.  
  84. # Watch List initialisation
  85. variable watchlist {}
  86.  
  87. # Either add or remove the whole watchlist at once
  88. # + to add, - to remove all
  89. proc modwatch {symbol} {
  90. variable watchlist
  91.  
  92. # Add every nick to watch one by one
  93. foreach entry $watchlist {
  94. lappend output "$symbol[lindex $entry 0]"
  95. }
  96.  
  97. # Send 'em to the server.
  98. if {![info exists output]} return
  99. putquick "WATCH [join $output]"
  100. }
  101.  
  102. # Loads the watch DB. Done automatically on startup.
  103. proc loadWatchDB {} {
  104. variable watchdb
  105. variable watchlist
  106.  
  107. # Get rid of ALL previous watches!
  108. modwatch -
  109. set watchlist {}
  110.  
  111. # Open the new file and load it
  112. if {![file exists $watchdb]} return
  113. set channelID [open $watchdb r]
  114. set watchlist [gets $channelID]
  115. close $channelID
  116.  
  117. # Add the new watches
  118. modwatch +
  119. }
  120. # Since we're loading the script, better load the DB too.
  121. loadWatchDB
  122.  
  123. # Save the watch db
  124. proc saveWatchDB {args} {
  125. variable watchdb
  126. variable watchlist
  127. variable maxwatch
  128.  
  129. # Eventually trim the database if it's too big
  130. if {[llength $watchlist] > $maxwatch} {
  131. set watchlist [lrange $watchlist 0 $maxwatch-1]
  132. }
  133.  
  134. # Open the file and write the watchlist into it
  135. set channelID [open $watchdb w+]
  136. puts -nonewline $channelID $watchlist
  137. close $channelID
  138. }
  139.  
  140. # Clear watches and bindings, save DB, delete the namespace
  141. proc uninstall {args} {
  142. saveWatchDB
  143. modwatch -
  144. foreach bind [binds ::autoReinvite::*] {
  145. catch { unbind [lindex $bind 0] [lindex $bind 1] [lindex $bind 2] [lindex $bind 4] }
  146. }
  147. namespace delete ::autoReinvite
  148. return }
  149.  
  150. # If a watch get detected, invite the guy.
  151. proc watchDetection {from keyword data} {
  152. set data [split $data]
  153. ::autoReinvite::invite [lindex $data 1] [lindex $data 2]@[lindex $data 3] }
  154.  
  155. # In case of a part, we reinvite the guy!
  156. proc partDetection {nick uhost hand chan reason} { ::autoReinvite::invite $nick $uhost 1 }
  157.  
  158. # In case of a kick, we reinvite the guy!
  159. proc kickDetection {nick uhost hand chan victim reason} { ::autoReinvite::invite $victim [getchanhost $victim $chan] 1 }
  160.  
  161. # Invite someone.. if he's not banned!
  162. proc invite {nick uhost {override_onchan_check 0}} {
  163. # NOTE: We need an argument to override the onchan check
  164. # because the bot will say someone that triggered a part
  165. # or kick bind is still on channel.
  166.  
  167. variable enabled
  168. variable bindedchan
  169.  
  170. # If the guy's already here, or the script disabled, don't bother
  171. if {([onchan $nick $bindedchan] && !$override_onchan_check) || !$enabled} return
  172.  
  173. # Check every chan ban for a match
  174. foreach line [chanbans $bindedchan] {
  175. if {[string match -nocase [string map "\[ \\\[ \] \\\]" [lindex $line 0]] $nick!$uhost]} return
  176. }
  177.  
  178. # In case everything's ok, we just invite him.
  179. putquick "INVITE $nick $bindedchan"
  180. }
  181.  
  182. # Add someone to the watchlist and start
  183. # watching him.
  184. proc addWatch {nick uhost hand chan reason} {
  185. variable bindedchan
  186. variable watchlist
  187. variable maxwatch
  188.  
  189. # Cancel if it's the wrong chan
  190. if {$chan ne $bindedchan} return
  191.  
  192. # Clear previous matching watches
  193. if {[clearWatch $nick $uhost $hand 1]} {
  194. # Start watching the guy on IRC
  195. putquick "WATCH +$nick"
  196. }
  197. # Add a fresh watch in the list
  198. lappend watchlist [list $nick $uhost $hand]
  199. # If the watchlist grows too big, we delete the first entry in the list
  200. if {([llength $watchlist] - 1) < $maxwatch} {
  201. clearWatch {*}[lindex $watchlist 0]
  202. }
  203. }
  204.  
  205. # Deletes a current watch (on channel join)
  206. proc delWatch {nick uhost hand chan args} {
  207. variable bindedchan
  208. # Just laugh loud if it's the bot joining or wrong chan
  209. if {$nick eq $::nick || $chan ne $bindedchan} return
  210. # Else remove the watch
  211. clearWatch $nick $uhost $hand
  212. # Pretty simple eh?
  213. return
  214. }
  215.  
  216. # Clears a watch from the watchlist
  217. # Based on nick/uhost/handle
  218. # Stuff matching either one will get removed
  219. # Corresponding IRC watchs get removed as well
  220. proc clearWatch {nick uhost hand {nowatch 0}} {
  221. variable watchlist
  222.  
  223. # If the list is empty, just gtfo! Might cause errors otherwise.
  224. if {![llength $watchlist]} { return 0 }
  225.  
  226. # If the nick matchs an existing watch, remove it
  227. if {[set nickIndex [lsearch -exact -index 0 $watchlist $nick]] != -1} { removeEntry $nickIndex
  228. # Same for userhost...
  229. } elseif {[set uhostIndex [lsearch -exact -index 1 $watchlist $uhost]] != -1} { removeEntry $uhostIndex
  230. # ...and handle.
  231. } elseif {$hand ne "*" && [set handIndex [lsearch -exact -index 2 $watchlist $hand]] != -1} { removeEntry $handIndex
  232.  
  233. # If a match was found, we remove the watch on IRC too
  234. } else { return 0 }
  235.  
  236. if {!$nowatch} { putquick "WATCH -$nick" }
  237. return 1
  238. }
  239.  
  240. # Deletes an entry from the watchlist in a conveninent way
  241. proc removeEntry {index} {
  242. variable watchlist
  243. set watchlist [lreplace $watchlist $index $index]
  244. }
  245.  
  246. # Bind on 'logged in' watch message
  247. bind raw - 600 ::autoReinvite::watchDetection
  248. # Bind on someone parting to reinvite him asap
  249. bind part - "$::autoReinvite::bindedchan *" ::autoReinvite::partDetection
  250. bind kick - "$::autoReinvite::bindedchan *" ::autoReinvite::kickDetection
  251. # Bind on someone quitting to add the watch
  252. bind sign - "$::autoReinvite::bindedchan *" ::autoReinvite::addWatch
  253. # Bind on someone rejoining to remove the watch
  254. bind join - "$::autoReinvite::bindedchan *" ::autoReinvite::delWatch
  255. # rehash script uninstall binding
  256. bind evnt - prerehash ::autoReinvite::uninstall
  257.  
  258. putlog "autoReinvite by Artix <loyauflorian@gmail.com> loaded succesfully."
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement