on_kick.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from common.queries import create_ifnot_onrecord
  2. from common.networkservices import ChanServ
  3. from common import userstatus, do_everything_to, log, font
  4. from events.common import Aggressiveness, Lastact
  5. bold = "\x02"
  6. italic = "\x1D"
  7. underline = "\x1F"
  8. reverse = "\x16" # swap background and foreground colors ("reverse video")
  9. reset = "\x0F"
  10. blue = "\x0302"
  11. green = "\x0303"
  12. red = "\x0304"
  13. grey = "\x0314"
  14. def process_event(self, connection, event):
  15. log.info(event)
  16. kicker = create_ifnot_onrecord(self, 'user', event.source.nick)
  17. channel = create_ifnot_onrecord(self, 'channel', event.target)
  18. kicked = create_ifnot_onrecord(self, 'user', event.arguments[0])
  19. reason = event.arguments[1]
  20. # # Update last act.
  21. # if reason:
  22. # Lastact.update(self, kicker, "kick", channel=channel, lastact=kicked, auxiliary=reason)
  23. # Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicker, auxiliary=reason)
  24. # else:
  25. # Lastact.update(self, kicker, "kick", channel=channel, lastact=kicked)
  26. # Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicker)
  27. # Record kick event in database.
  28. if not self.db.one('SELECT id FROM rotbot_kick WHERE network_id=$(network_id)s AND channel_id=$(channel_id)s AND kicker_id=%(kicker_id)s AND kicked_id=%(kicked_id)s', network_id=self.network.id, channel_id=channel.id, kicker_id=kicker.id, kicked_id=kicked.id): # No records for kicker channel combination.
  29. self.db.run('INSERT INTO rotbot_kick (network_id, channel_id, kicker_id, kicked_id, amount) VALUES (%(network_id)s, %(channel_id)s, %(kicker_id)s, %(kicked_id)s), 1', network_id=self.network.id, channel_id=channel.id, kicker_id=kicker.id, kicked_id=kicked.id) # Create record.
  30. else:
  31. self.db.run('UPDATE rotbot_kick SET amount = amount + 1 WHERE network_id=$(network_id)s AND channel_id=$(channel_id)s AND kicker_id=%(kicker_id)s AND kicked_id=%(kicked_id)s', network_id=self.network.id, channel_id=channel.id, kicker_id=kicker.id, kicked_id=kicked.id) # Update record.
  32. # # Update protectees if needed.
  33. # if channel == self.homechannel: # Kicked from home channel
  34. # if event.source.nick in self.protectees: # Protectee kicked.
  35. # del self.protectees[event.source.nick] # Remove old nick from list.
  36. #
  37. # # Do nothing more when user is not protected.
  38. # if not userstatus.atleast_halfop(self, kicked, self.homechannel) and not kicked == connection.get_nickname():
  39. # return
  40. #
  41. # # Report.
  42. # if not channel == self.homechannel: # Not kicked from homechannel.
  43. # if reason:
  44. # connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ": " + green + reason)
  45. # else:
  46. # connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ".")
  47. #
  48. # # React.
  49. # print("Reacting to kick")
  50. # behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
  51. # if behaviour == "passive": # Passive behaviour.
  52. # if kicked == connection.get_nickname() and channel == self.homechannel: # Bot was kicked from it's home channel.
  53. # ChanServ.unban(connection, channel, kicked)
  54. # ChanServ.akick_del(connection, channel, kicked)
  55. # connection.privmsg("ChanServ", "UNBAN " + channel)
  56. # do_everything_to.join(self, connection, self.homechannel)
  57. # elif behaviour == "defense_only": # Defensive behaviour.
  58. # ChanServ.unban(connection, channel, kicked)
  59. # ChanServ.akick_del(connection, channel, kicked)
  60. # if kicked == connection.get_nickname(): # Bot was kicked.
  61. # connection.privmsg("ChanServ", "UNBAN " + channel)
  62. # do_everything_to.join(self, connection, channel)
  63. # elif behaviour == "equal_retalliation": # Equal retalitory behaviour.
  64. # ChanServ.akick_del(connection, channel, kicked)
  65. #
  66. # # Rejoin if bot was kicked.
  67. # if kicked == connection.get_nickname():
  68. # connection.privmsg("ChanServ", "UNBAN " + channel)
  69. # do_everything_to.join(self, connection, self.homechannel)
  70. #
  71. # if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
  72. # return # Stop if offender is bot or owner.
  73. # if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
  74. # return # Stop if offended is not atleast halfop and is not the bot itself.
  75. # if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
  76. # return # Stop if offender is at least halfop in the home channel and the offended is not owner.
  77. #
  78. # # Kick.
  79. # do_everything_to.kick(connection, channel, kicker, Aggressiveness.retalliation_reason(self, connection, kicked, behaviour))
  80. #
  81. # # Battlebot behaviour.
  82. # elif behaviour == "battlebot":
  83. # ChanServ.akick_del(connection, channel, kicked)
  84. #
  85. # # Rejoin if bot was kicked.
  86. # if kicked == connection.get_nickname():
  87. # print("Rejoining " + channel)
  88. # do_everything_to.join(self, connection, channel)
  89. #
  90. # if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
  91. # print("Stop if offender is bot or owner")
  92. # return # Stop if offender is bot or owner.
  93. # if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
  94. # print("Stop if offended is not atleast halfop and is not the bot itself")
  95. # return # Stop if offended is not atleast halfop and is not the bot itself.
  96. # if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
  97. # print("Stop if offender is at least halfop in the home channel and the offended is not owner")
  98. # return # Stop if offender is at least halfop in the home channel and the offended is not owner.
  99. # print("Kickbanning")
  100. #
  101. # ChanServ.tempban(connection, channel, kicker, "1h", "Aggression channel function = equal_retalliation: " + kicked)
  102. # connection.mode(channel, "+e " + kicked) # Excempt operator.
  103. # ChanServ.akick_add(connection, channel, kicker) # Add kicker to ChanServs autokick.
  104. # do_everything_to.bankick(connection, channel, kicker, event.source, "Aggression channel function = equal_retalliation: " + kicked)