|
|
@@ -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))
|