# revengebot.tcl v1.0 (2 January 2002) for eggdrop 1.6.x
# copyright (c) 2002 by gregul <gregul@irc.pl>
#
# protects other bots with global flags from being kicked, deopped or banned,
# should be load on all bots from botnet
# recommended settings: -revenge -revengebot
# 
# if you have an idea how to detect a masskick of global bots done by owners
# or other bots from botnet (or guys with same host and domain as one of our bots) mail to
# gregul@irc.pl - useful when someone hacks owner or shell pass
#
# bug reports or ideas are welcome
#
# gregul@IRCnet
#

bind kick - * prot_kick
bind mode - "* -o" prot_deop
bind mode - "* +b" prot_ban

proc prot_kick {nick uhost hand chan victim reason} {
global botnick
 if {![botisop $chan] || [isbotnick $nick] || [isbotnick $victim] || [matchattr $hand n|n $chan] || ([matchattr $hand b] && [matchattr $hand o])} {return}
  set vict "[nick2hand $victim $chan]"
  if {[matchattr $vict b] && [matchattr $vict o]} { 
   putquick "KICK $chan $nick :\002iZ revengiN\002" -next
  } 
 }

proc prot_deop {nick uhost hand chan mc victim} {
global botnick
 if {![botisop $chan] || [isbotnick $nick] || [matchattr $hand n|n $chan] || ([matchattr $hand b] && [matchattr $hand o])} {return}
  set vict "[nick2hand $victim $chan]"
  if {[matchattr $vict b] && [matchattr $vict o]} { 
   putquick "KICK $chan $nick :\002iZ revengiN\002" -next
  } 
 }

proc prot_ban {nick uhost hand chan mc ban} {
global botnick botname
 if {![botisop $chan] || [isbotnick $nick] || [matchattr $hand n|n $chan] || ([matchattr $hand b] && [matchattr $hand o])} {return}
 if {[string match "$ban" "$botname"]} {
  putquick "KICK $chan $nick :\002iZ revengiN\002" -next
  pushmode $chan -b $ban
 } else {
  set pnicks "" 
  foreach user [chanlist $chan b] {
   if {[matchattr [nick2hand $user $chan] o]} {lappend pnicks $user}
  }
  foreach pnick $pnicks {
   if {[string match "$ban" "$pnick![getchanhost $pnick $chan]"]} {
    putquick "KICK $chan $nick :\002iZ revengiN\002" -next
    pushmode $chan -b $ban
   }
  }
 }
}

putlog "revengebot.tcl v1.0 by gregul loaded"