tBKwtWS 7 жил өмнө
parent
commit
11bd48cc16

+ 2 - 2
common/do_everything_to.py

@@ -18,11 +18,11 @@ def join(self, connection, channel, key=False):
 
 def unban(connection, channel, user, mask):
     ChanServ.unban(connection, channel, user)
-    connection.mode(connection, "-b " + mask)
+    connection.mode(channel, "-b " + mask)
 
 def ban(connection, channel, user, mask, reason):
     ChanServ.ban(connection, channel, user, reason)
-    connection.mode(connection, "+b " + mask)
+    connection.mode(channel, "+b " + mask)
 
 def kick(connection, channel, user, reason):
     ChanServ.kick(connection, channel, user, reason)

+ 14 - 24
events/on_kick.py

@@ -1,5 +1,6 @@
 from common.networkservices import ChanServ
 from common import userstatus, do_everything_to
+from events.common import Aggressiveness
 
 bold = "\x02"
 italic = "\x1D"
@@ -72,22 +73,16 @@ def process_event(self, connection, event):
             connection.privmsg("ChanServ", "UNBAN " + channel)
             do_everything_to.join(self, connection, self.homechannel)
         
-        # Stop if offender is bot.
-        if event.source.nick == connection.get_nickname():
-            print("stop")
-            return
         
-        # Only continue if offended is owner and offender is not also owner.
-        if userstatus.atleast_halfop(self, kicker, self.homechannel):   # Offender is bot operator.
-            if self.channels[self.homechannel].is_owner(kicked) and not self.channels[self.homechannel].is_owner(kicker):   # Offended is owner and offender is not also owner.
-                pass
-            else:
-                print("STOP")
-                return
+        if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
+            return  # Stop if offender is bot or owner.
+        if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
+            return  # Stop if offended is not atleast halfop and is not the bot itself.
+        if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
+            return  # Stop if offender is at least halfop in the home channel and the offended is not owner.
         
         # Kick.
-        ChanServ.kick(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
-        connection.kick(channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
+        do_everything_to.kick(connection, channel, kicker, Aggressiveness.retalliation_reason(self, connection, kicked, behaviour))
     
     # Battlebot behaviour.
     elif behaviour == "battlebot":
@@ -99,18 +94,13 @@ def process_event(self, connection, event):
             connection.privmsg("ChanServ", "UNBAN " + channel)
             do_everything_to.join(self, connection, self.homechannel)
         
-        # Stop if offender is bot.
-        if event.source.nick == connection.get_nickname():
-            print("stop")
-            return
         
-        # Only continue if offended is owner and offender is not also owner.
-        if userstatus.atleast_halfop(self, kicker, self.homechannel):   # Offender is bot operator.
-            if self.channels[self.homechannel].is_owner(kicked) and not self.channels[self.homechannel].is_owner(kicker):   # Offended is owner and offender is not also owner.
-                pass
-            else:
-                print("STOP")
-                return
+        if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
+            return  # Stop if offender is bot or owner.
+        if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
+            return  # Stop if offended is not atleast halfop and is not the bot itself.
+        if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
+            return  # Stop if offender is at least halfop in the home channel and the offended is not owner.
 
         # Ban.
         ChanServ.tempban(connection, channel, kicker, "1h", "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")

+ 39 - 32
events/on_mode.py

@@ -1,7 +1,7 @@
 import fnmatch
 from irc.modes import parse_channel_modes
 from common.networkservices import ChanServ
-from common import do_everything_to
+from common import do_everything_to, userstatus
 from events.common import Aggressiveness
 
 bold = "\x02"
@@ -17,19 +17,24 @@ grey = "\x0314"
 def process_event(self, connection, event):
     print(event)
     
+    # Update protectees.
     if event.target == self.homechannel:    # Home channel
         if any(mode in event.arguments[0][-1:] for mode in ("q", "a", "o", "h")):  # Atleast halfop.
             connection.who(event.arguments[1])  # Get whorepy to update protectees.
+    
+    # React.
     modes = parse_channel_modes(" ".join(event.arguments))
-    for mode in modes:
+    behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")
+    for idx, mode in enumerate(modes):
         
         # Report.
         if not event.target == self.homechannel:    # Not in home channel.
             for protectee in self.protectees:
                 if mode[1] == "b" and fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]) and mode[0] == "+":   # Protectee banned.
                     connection.privmsg(self.homechannel, red + protectee + reset + " banned from " + red + event.target + reset + " by " + red + event.source.nick + reset + ": " + green + mode[2])
-                if mode[1] == "e" and fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]) and mode[0] == "-":   # Protectee's exception removed.
-                    connection.privmsg(self.homechannel, red + protectee + reset + " has had their exception removed from " + red + event.target + reset + " by " + red + event.source.nick + reset + ": " + green + mode[2])
+
+                if mode[1] == "e" and fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]) and mode[0] == "-":   # Protectee's exception removed.
+                    connection.privmsg(self.homechannel, red + protectee + reset + " has had their exception removed from " + red + event.target + reset + " by " + red + event.source.nick + reset + ": " + green + event.arguments[idx + 1])
     
         # Track channel keys.
         if mode[1] == "k":  # Channel key changed.
@@ -37,10 +42,6 @@ def process_event(self, connection, event):
                 self.db.run("UPDATE channels SET key='" + mode[2] + "' WHERE name='" + event.target + "' AND network='" + self.network + "'")
             else:   # Key removed.
                 self.db.run("UPDATE channels SET key=NULL WHERE name='" + event.target + "' AND network='" + self.network + "'")
-
-    # React.
-    behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")
-    for mode in modes:
         
         # Unban if bot is banned from home channel
         if mode[1] == "b" and fnmatch.fnmatch(self.protectees[connection.get_nickname()]['ident'], mode[2]) and mode[0] == "+" and event.target == self.homechannel:
@@ -48,24 +49,30 @@ def process_event(self, connection, event):
             do_everything_to.unban(connection, event.target, connection.get_nickname(), mode[2])
             connection.mode(event.target, "-b " + mode[2])
         
-        # Do not revert the actions of retalliate upon one self.
-        if event.source.nick == connection.get_nickname():
+        # Stop if offender is bot or bot owner.
+        if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(event.source.nick):
             return
         
-        if behaviour == "passive":    # Passive behaviour.
-            return
-        elif behaviour == "defense_only":   # Defensive only behaviour.
-            if mode[1] == "b" and mode[0] == "+":  # Ban.
-                for protectee in self.protectees:
+        for protectee in self.protectees:
+            
+            # Stop if offender is atleast halfop in the home channel and offended is not owner.
+            if userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not self.channels[self.homechannel].is_owner(protectee):
+                return
+            
+            if behaviour == "passive":    # Passive behaviour.
+                return
+            elif behaviour == "defense_only":   # Defensive only behaviour.
+                if mode[1] == "b" and mode[0] == "+":  # Ban.
+                    #for protectee in self.protectees:
                     if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
                         do_everything_to.unban(connection, event.target, protectee, mode[2])
-            elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
-                for protectee in self.protectees:
-                    if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
+                elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
+                    #for protectee in self.protectees:
+                    if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]):  # Protectee.
                         connection.mode(event.target, "+e " + mode[2])
-        elif behaviour == "equal_retalliation":   # Equal retaliatory behaviour.
-            if modes[1] == "b" and mode[0] == "+":  # Ban.
-                for protectee in self.protectees:
+            elif behaviour == "equal_retalliation":   # Equal retaliatory behaviour.
+                if modes[1] == "b" and mode[0] == "+":  # Ban.
+                    #for protectee in self.protectees:
                     if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
                         do_everything_to.unban(connection, event.target, protectee, mode[2])
                         if protectee == connection.get_nickname():  # Bot banned.
@@ -73,23 +80,23 @@ def process_event(self, connection, event):
                         else:
                             ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = equal_retalliation: " + protectee + " is an operator of " + connection.get_nickname() + ".")
                         connection.mode(event.target, "+b " + event.source)
-            elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
-                for protectee in self.protectees:
-                    if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
-                        connection.mode(event.target, "+e " + mode[2])
-        elif behaviour == "battlebot":  # Battlebot behaviour.
-            if mode[1] == "b" and mode[0] == "+":  # Ban.
-                for protectee in self.protectees:
+                elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
+                    #for protectee in self.protectees:
+                    if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]):  # Protectee.
+                        connection.mode(event.target, "+e " + event.arguments[idx + 1])
+            elif behaviour == "battlebot":  # Battlebot behaviour.
+                if mode[1] == "b" and mode[0] == "+":  # Ban.
+                    #for protectee in self.protectees:
                     if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
                         do_everything_to.unban(connection, event.target, protectee, mode[2])
                         do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
                         connection.mode(event.target, "+e " + mode[2])
                         ChanServ.akick_add(connection, event.target, event.source.nick)
                         do_everything_to.kick(connection, event.target, event.source.nick, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
-            elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
-                for protectee in self.protectees:
-                    if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]):  # Protectee.
+                elif mode[1] == "e" and mode[0] == "-":  # Removed exception.
+                    #for protectee in self.protectees:
+                    if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]):  # Protectee.
                         do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
-                        connection.mode(event.target, "+e " + modes[mode]['value'])
+                        connection.mode(event.target, "+e " + event.arguments[idx + 1])
                         ChanServ.akick_add(connection, event.target, event.source.nick)
                         do_everything_to.kick(connection, event.target, event.source.nick, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))