on_mode.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # import fnmatch
  2. # from irc.modes import parse_channel_modes
  3. # from common.networkservices import ChanServ
  4. from common import log #do_everything_to, userstatus, log, font
  5. # from events.common import Aggressiveness, Lastact
  6. def process_event(self, connection, event):
  7. log.info(event)
  8. # # Update protectees.
  9. # if event.target == self.homechannel: # Home channel
  10. # if any(mode in event.arguments[0][-1:] for mode in ("q", "a", "o", "h")): # Atleast halfop.
  11. # connection.who(event.arguments[1]) # Get whorepy to update protectees.
  12. #
  13. # # Update last act.
  14. # Lastact.update(self, event.source.nick, "mode", lastact=event.target)
  15. #
  16. # # React.
  17. # modes = parse_channel_modes(" ".join(event.arguments))
  18. # behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")
  19. # for idx, mode in enumerate(modes):
  20. #
  21. # # Report.
  22. # if not event.target == self.homechannel: # Not in home channel.
  23. # for protectee in self.protectees:
  24. # if mode[1] == "b" and fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]) and mode[0] == "+": # Protectee banned.
  25. # connection.privmsg(self.homechannel, font.red + protectee + font.reset + " banned from " + font.red + event.target + font.reset + " by " + font.red + event.source.nick + font.reset + ": " + font.green + mode[2])
  26. #
  27. # if mode[1] == "e" and fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]) and mode[0] == "-": # Protectee's exception removed.
  28. # connection.privmsg(self.homechannel, font.red + protectee + font.reset + " has had their exception removed from " + font.red + event.target + font.reset + " by " + font.red + event.source.nick + font.reset + ": " + font.green + event.arguments[idx + 1])
  29. #
  30. # # Track channel keys.
  31. # if mode[1] == "k": # Channel key changed.
  32. # if mode[0] == "+": # Key set.
  33. # self.db.run("UPDATE channels SET key='" + mode[2] + "' WHERE name='" + event.target + "' AND network='" + self.network + "'")
  34. # else: # Key removed.
  35. # self.db.run("UPDATE channels SET key=NULL WHERE name='" + event.target + "' AND network='" + self.network + "'")
  36. #
  37. # # Unban if bot is banned from home channel
  38. # try:
  39. # if mode[1] == "b" and fnmatch.fnmatch(self.protectees[connection.get_nickname()]['ident'], mode[2]) and mode[0] == "+" and event.target == self.homechannel:
  40. # connection.privmsg("ChanServ", "UNBAN")
  41. # do_everything_to.unban(connection, event.target, connection.get_nickname(), mode[2])
  42. # connection.mode(event.target, "-b " + mode[2])
  43. # except:
  44. # pass
  45. #
  46. # # Stop if not present in home channel.
  47. # if not self.homechannel in self.channels:
  48. # return
  49. #
  50. # # Stop if offender is bot or bot owner
  51. # if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(event.source.nick):
  52. # return
  53. #
  54. # for protectee in self.protectees:
  55. #
  56. # # Stop if offender is atleast halfop in the home channel and offended is not owner.
  57. # if userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not self.channels[self.homechannel].is_owner(protectee):
  58. # return
  59. #
  60. # try: # Had "IndexError: list index out of range" on "if modes[1] == "b" and mode[0] == "+": # Ban.".
  61. # if behaviour == "passive": # Passive behaviour.
  62. # return
  63. # elif behaviour == "defense_only": # Defensive only behaviour.
  64. # if mode[1] == "b" and mode[0] == "+": # Ban.
  65. # if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]): # Protectee.
  66. # do_everything_to.unban(connection, event.target, protectee, mode[2])
  67. # elif mode[1] == "e" and mode[0] == "-": # Removed exception.
  68. # if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]): # Protectee.
  69. # connection.mode(event.target, "+e " + mode[2])
  70. # elif mode[0] == "-" and mode[1] in ["q", "a", "o", "h", "v"]: # Channel right taken.
  71. # ChanServ.give_mode(connection, event.target, mode[2], mode[1])
  72. # connection.mode(event.target, mode[0] + mode[1] + " " + mode[2])
  73. # elif behaviour == "equal_retalliation": # Equal retaliatory behaviour.
  74. # if modes[1] == "b" and mode[0] == "+": # Ban.
  75. # if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]): # Protectee.
  76. # do_everything_to.unban(connection, event.target, protectee, mode[2])
  77. # if protectee == connection.get_nickname(): # Bot banned.
  78. # ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = equal_retalliation.")
  79. # else:
  80. # ChanServ.ban(connection, event.target, event.source.nick, "Aggression channel function = equal_retalliation: " + protectee + " is an operator of " + connection.get_nickname() + ".")
  81. # connection.mode(event.target, "+b " + event.source)
  82. # elif mode[1] == "e" and mode[0] == "-": # Removed exception.
  83. # if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]): # Protectee.
  84. # connection.mode(event.target, "+e " + event.arguments[idx + 1])
  85. # elif mode[0] == "-" and mode[1] in ["q", "a", "o", "h", "v"]: # Channel right taken.
  86. # ChanServ.give_mode(connection, event.target, mode[2], mode[1])
  87. # connection.mode(event.target, mode[0] + mode[1] + " " + mode[2])
  88. # ChanServ.take_all_modes(connection, event.target, mode[2])
  89. # connection.mode(event.target, "-vhoaq " + mode[2] + " " + mode[2]+ " " + mode[2]+ " " + mode[2]+ " " + mode[2])
  90. # elif behaviour == "battlebot": # Battlebot behaviour.
  91. # if mode[0] == "-" and mode[1] in ["q", "a", "o", "h", "v"]: # Channel right taken.
  92. # ChanServ.give_mode(connection, event.target, mode[2], mode[1])
  93. # connection.mode(event.target, mode[0] + mode[1] + " " + mode[2])
  94. # do_everything_to.unban(connection, event.target, protectee, mode[2])
  95. # do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
  96. # connection.mode(event.target, "+e " + mode[2])
  97. # ChanServ.akick_add(connection, event.target, event.source.nick)
  98. # do_everything_to.kick(connection, event.target, event.source.nick, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
  99. # if mode[1] == "b" and mode[0] == "+": # Ban.
  100. # if fnmatch.fnmatch(self.protectees[protectee]['ident'], mode[2]): # Protectee.
  101. # do_everything_to.unban(connection, event.target, protectee, mode[2])
  102. # do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
  103. # connection.mode(event.target, "+e " + mode[2])
  104. # ChanServ.akick_add(connection, event.target, event.source.nick)
  105. # do_everything_to.kick(connection, event.target, event.source.nick, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
  106. # elif mode[1] == "e" and mode[0] == "-": # Removed exception.
  107. # #for protectee in self.protectees:
  108. # if fnmatch.fnmatch(self.protectees[protectee]['ident'], event.arguments[idx + 1]): # Protectee.
  109. # do_everything_to.ban(connection, event.target, event.source.nick, event.source, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
  110. # connection.mode(event.target, "+e " + event.arguments[idx + 1])
  111. # ChanServ.akick_add(connection, event.target, event.source.nick)
  112. # do_everything_to.kick(connection, event.target, event.source.nick, Aggressiveness.retalliation_reason(self, connection, protectee, behaviour))
  113. # except:
  114. # pass