|
|
@@ -0,0 +1,111 @@
|
|
|
+import fnmatch
|
|
|
+from irc.modes import parse_channel_modes
|
|
|
+from common.networkservices import ChanServ
|
|
|
+bold = "\x02"
|
|
|
+italic = "\x1D"
|
|
|
+underline = "\x1F"
|
|
|
+reverse = "\x16" # swap background and foreground colors ("reverse video")
|
|
|
+reset = "\x0F"
|
|
|
+blue = "\x0302"
|
|
|
+green = "\x0303"
|
|
|
+red = "\x0304"
|
|
|
+grey = "\x0314"
|
|
|
+
|
|
|
+def process_event(self, connection, event):
|
|
|
+ print(event)
|
|
|
+
|
|
|
+ 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.
|
|
|
+ modes = parse_channel_modes(" ".join(event.arguments))
|
|
|
+ for mode in 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])
|
|
|
+
|
|
|
+ # Track channel keys.
|
|
|
+ if mode[1] == "k": # Channel key changed.
|
|
|
+ if mode[0] == "+": # Key set.
|
|
|
+ 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 + "'")
|
|
|
+
|
|
|
+ # Do not revert the actions of retalliate upon one self.
|
|
|
+ if event.source.nick == connection.get_nickname():
|
|
|
+ return
|
|
|
+
|
|
|
+ # React.
|
|
|
+ behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")
|
|
|
+ for mode in modes:
|
|
|
+ if behaviour == "passive": # Passive behaviour.
|
|
|
+ if event.target == self.homechannel: # Home channel
|
|
|
+ if mode[1] == "b" and fnmatch.fnmatch(self.protectees[connection.get_nickname()]['ident'], mode[2]) and mode[0] == "+": # Bot banned.
|
|
|
+ ChanServ.unban(connection, event.target, connection.get_nickname())
|
|
|
+ connection.privmsg("ChanServ", "UNBAN")
|
|
|
+ connection.mode(event.target, "-b " + mode[2])
|
|
|
+ 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.
|
|
|
+ ChanServ.unban(connection, event.target, protectee)
|
|
|
+ connection.mode(event.target, "-b " + modes[1])
|
|
|
+ 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 == "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.
|
|
|
+ ChanServ.unban(connection, event.target, protectee)
|
|
|
+ connection.mode(event.target, "-b " + mode[2])
|
|
|
+ if protectee == connection.get_nickname(): # Bot banned.
|
|
|
+ ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = equal_retalliation.")
|
|
|
+ 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:
|
|
|
+ if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]): # Protectee.
|
|
|
+ ChanServ.unban(connection, event.target, protectee)
|
|
|
+ connection.mode(event.target, "-b " + mode[2])
|
|
|
+ if protectee == connection.get_nickname(): # Bot banned.
|
|
|
+ ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = battlebot.")
|
|
|
+ else:
|
|
|
+ ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = battlebot: " + protectee + " is an operator of " + connection.get_nickname() + ".")
|
|
|
+ connection.mode(event.target, "+b " + event.source)
|
|
|
+ connection.mode(event.target, "+e " + mode[2])
|
|
|
+ ChanServ.akick_add(connection, event.target, event.source.nick)
|
|
|
+ if protectee == connection.get_nickname(): # Bot banned.
|
|
|
+ ChanServ.kick(connection, event.target, event.source.nick, "Aggression channel function = battlebot.")
|
|
|
+ connection.kick(event.target, event.source.nick, "Aggression channel function = battlebot.")
|
|
|
+ else:
|
|
|
+ ChanServ.kick(connection, event.target, event.source.nick, "Aggression channel function = battlebot: " + protectee + " is an operator of " + connection.get_nickname() + ".")
|
|
|
+ connection.kick(event.target, event.source.nick, "Aggression channel function = battlebot: " + protectee + " is an operator of " + connection.get_nickname() + ".")
|
|
|
+ elif mode[1] == "e" and mode[0] == "-": # Removed exception.
|
|
|
+ for protectee in self.protectees:
|
|
|
+ if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]): # Protectee.
|
|
|
+ if protectee == connection.get_nickname(): # Bot.
|
|
|
+ ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = battlebot.")
|
|
|
+ else:
|
|
|
+ ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = battlebot: " + protectee + " is an operator of " + connection.get_nickname() + ".")
|
|
|
+ print(event.target, "+b " + event.source)
|
|
|
+ connection.mode(event.target, "+b " + event.source)
|
|
|
+ connection.mode(event.target, "+e " + modes[mode]['value'])
|
|
|
+ ChanServ.akick_add(connection, event.target, event.source.nick)
|
|
|
+ if protectee == connection.get_nickname(): # Bot.
|
|
|
+ ChanServ.kick(connection, event.target, event.source.nick, "Aggression channel function = battlebot..")
|
|
|
+ connection.kick(event.target, event.source.nick, "Aggression channel function = battlebot.")
|
|
|
+ else:
|
|
|
+ ChanServ.kick(connection, event.target, event.source.nick, "Aggression channel function = battlebot: " + protectee + " is an operator of " + connection.get_nickname() + ".")
|
|
|
+ connection.kick(event.target, event.source.nick, "Aggression channel function = battlebot: " + protectee + " is an operator of " + connection.get_nickname() + ".")
|