Advertisement
Guest User

Untitled

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