on_kick.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from common.networkservices import ChanServ
  2. from common import userstatus, do_everything_to
  3. bold = "\x02"
  4. italic = "\x1D"
  5. underline = "\x1F"
  6. reverse = "\x16" # swap background and foreground colors ("reverse video")
  7. reset = "\x0F"
  8. blue = "\x0302"
  9. green = "\x0303"
  10. red = "\x0304"
  11. grey = "\x0314"
  12. def process_event(self, connection, event):
  13. kicker = event.source.nick
  14. channel = event.target
  15. kicked = event.arguments[0]
  16. reason = event.arguments[1]
  17. # Create user records if they don't exist.
  18. if not self.db.one("SELECT id FROM users WHERE name='" + kicker + "' AND network='" + self.network + "'"): # Kicker does not have a user record.
  19. self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + kicker + "', '" + self.network + "')") # Create user record.
  20. if not self.db.one("SELECT id FROM users WHERE name='" + kicked + "' AND network='" + self.network + "'"): # Kicked does not have a user record.
  21. self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + kicked + "', '" + self.network + "')") # Create user record.
  22. # Create kick records if they don't exist.
  23. if not self.db.one("SELECT id FROM kicks WHERE channel='" + channel + "'AND channel_network='" + self.network + "' AND \"user\"='" + kicker + "' AND user_network='" + self.network + "'"): # No records for kicker channel combination.
  24. self.db.run("INSERT INTO kicks (channel, channel_network, \"user\", user_network) VALUES ('" + channel + "', '" + self.network + "', '" + kicker + "', '" + self.network + "')")
  25. if not self.db.one("SELECT id FROM kicks WHERE channel='" + channel + "'AND channel_network='" + self.network + "' AND \"user\"='" + kicked + "' AND user_network='" + self.network + "'"): # No records for kicked channel combination.
  26. self.db.run("INSERT INTO kicks (channel, channel_network, \"user\", user_network) VALUES ('" + channel + "', '" + self.network + "', '" + kicked + "', '" + self.network + "')")
  27. # Save statistic.
  28. self.db.run("UPDATE kicks SET given = given + 1 WHERE channel='" + channel + "'AND channel_network='" + self.network + "' AND \"user\"='" + kicker + "' AND user_network='" + self.network + "'")
  29. self.db.run("UPDATE kicks SET received = received + 1 WHERE channel='" + channel + "'AND channel_network='" + self.network + "' AND \"user\"='" + kicked + "' AND user_network='" + self.network + "'")
  30. # Update protectees if needed.
  31. if channel == self.homechannel: # Kicked from home channel
  32. if event.source.nick in self.protectees: # Protectee kicked.
  33. del self.protectees[event.source.nick] # Remove old nick from list.
  34. # Do nothing more when user is not protected.
  35. if not userstatus.atleast_halfop(self, kicked, self.homechannel) and not kicked == connection.get_nickname():
  36. return
  37. # Report.
  38. if not channel == self.homechannel: # Not kicked from homechannel.
  39. if not userstatus.atleast_halfop(self, kicked, self.homechannel):
  40. if reason:
  41. connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ": " + green + reason)
  42. else:
  43. connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ".")
  44. # React.
  45. behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
  46. if behaviour == "passive": # Passive behaviour.
  47. if kicked == connection.get_nickname() and channel == self.homechannel: # Bot was kicked from it's home channel.
  48. ChanServ.unban(connection, channel, kicked)
  49. ChanServ.akick_del(connection, channel, kicked)
  50. connection.privmsg("ChanServ", "UNBAN " + channel)
  51. do_everything_to.join(self, connection, self.homechannel)
  52. elif behaviour == "defense_only": # Defensive behaviour.
  53. ChanServ.unban(connection, channel, kicked)
  54. ChanServ.akick_del(connection, channel, kicked)
  55. if kicked == connection.get_nickname(): # Bot was kicked.
  56. connection.privmsg("ChanServ", "UNBAN " + channel)
  57. do_everything_to.join(self, connection, channel)
  58. elif behaviour == "equal_retalliation": # Equal retalitory behaviour.
  59. ChanServ.unban(connection, channel, kicked)
  60. ChanServ.akick_del(connection, channel, kicked)
  61. # Rejoin if bot was kicked from it's home channel.
  62. if kicked == connection.get_nickname() and channel == self.homechannel:
  63. connection.privmsg("ChanServ", "UNBAN " + channel)
  64. do_everything_to.join(self, connection, self.homechannel)
  65. # Stop if the offender is a bot operator and the offended is not the bot owner or if the 2 parties are both bot owner or if the offender is the bot.
  66. if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].isowner(kicked) or self.channels[self.homechannel].isowner(kicked) == self.channels[self.homechannel].isowner(kicker) or event.source.nick == connection.get_nickname():
  67. return
  68. # Kick.
  69. ChanServ.kick(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
  70. connection.kick(channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
  71. # Battlebot behaviour.
  72. elif behaviour == "battlebot":
  73. ChanServ.unban(connection, channel, kicked)
  74. ChanServ.akick_del(connection, channel, kicked)
  75. # Rejoin if bot was kicked from it's home channel.
  76. if kicked == connection.get_nickname() and channel == self.homechannel:
  77. connection.privmsg("ChanServ", "UNBAN " + channel)
  78. do_everything_to.join(self, connection, self.homechannel)
  79. # Stop if the offender is a bot operator and the offended is not the bot owner or if the 2 parties are both bot owner or if the offender is the bot.
  80. if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked) or self.channels[self.homechannel].is_owner(kicked) == self.channels[self.homechannel].is_owner(kicker) or event.source.nick == connection.get_nickname():
  81. return
  82. # Ban.
  83. ChanServ.tempban(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
  84. connection.mode(channel, "+b " + event.source)
  85. connection.mode(channel, "+e " + event.source) # Excempt operator.
  86. ChanServ.akick_add(connection, channel, kicker) # Add kicker to ChanServs autokick.
  87. # Kick.
  88. ChanServ.kick(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
  89. connection.kick(channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")