on_kick.py 6.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #from common.networkservices import ChanServ
  2. from common import log, queries #userstatus, do_everything_to, log, font, queries
  3. #from events.common import Aggressiveness, Lastact
  4. def process_event(self, connection, event):
  5. log.info(event) # Log to console
  6. # Get and update resources.
  7. reason = event.arguments[1]
  8. kicker = queries.create_or_get_and_update_last_event(self, 'user', 'ck', channel_name=event.target, user_name=event.source.nick, extra_content=reason, event_subject_name=event.arguments[0])
  9. channel = queries.create_or_get_and_update_last_event(self, 'channel', 'ck', channel_name=event.target, user_name=event.source.nick, extra_content=reason, event_subject_name=event.arguments[0])
  10. kicked = queries.create_or_get_and_update_last_event(self, 'user','ck', channel_name=event.target, user_name=event.arguments[0], extra_content=reason, event_subject_name=event.source.nick)
  11. # Record kick event in database.
  12. 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.
  13. 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.
  14. else:
  15. 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.
  16. # # Update protectees if needed.
  17. # if channel == self.homechannel: # Kicked from home channel
  18. # if event.source.nick in self.protectees: # Protectee kicked.
  19. # del self.protectees[event.source.nick] # Remove old nick from list.
  20. #
  21. # # Do nothing more when user is not protected.
  22. # if not userstatus.atleast_halfop(self, kicked, self.homechannel) and not kicked == connection.get_nickname():
  23. # return
  24. #
  25. # # Report.
  26. # if not channel == self.homechannel: # Not kicked from homechannel.
  27. # if reason:
  28. # connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ": " + green + reason)
  29. # else:
  30. # connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ".")
  31. #
  32. # # React.
  33. # print("Reacting to kick")
  34. # behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
  35. # if behaviour == "passive": # Passive behaviour.
  36. # if kicked == connection.get_nickname() and channel == self.homechannel: # Bot was kicked from it's home channel.
  37. # ChanServ.unban(connection, channel, kicked)
  38. # ChanServ.akick_del(connection, channel, kicked)
  39. # connection.privmsg("ChanServ", "UNBAN " + channel)
  40. # do_everything_to.join(self, connection, self.homechannel)
  41. # elif behaviour == "defense_only": # Defensive behaviour.
  42. # ChanServ.unban(connection, channel, kicked)
  43. # ChanServ.akick_del(connection, channel, kicked)
  44. # if kicked == connection.get_nickname(): # Bot was kicked.
  45. # connection.privmsg("ChanServ", "UNBAN " + channel)
  46. # do_everything_to.join(self, connection, channel)
  47. # elif behaviour == "equal_retalliation": # Equal retalitory behaviour.
  48. # ChanServ.akick_del(connection, channel, kicked)
  49. #
  50. # # Rejoin if bot was kicked.
  51. # if kicked == connection.get_nickname():
  52. # connection.privmsg("ChanServ", "UNBAN " + channel)
  53. # do_everything_to.join(self, connection, self.homechannel)
  54. #
  55. # if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
  56. # return # Stop if offender is bot or owner.
  57. # if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
  58. # return # Stop if offended is not atleast halfop and is not the bot itself.
  59. # if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
  60. # return # Stop if offender is at least halfop in the home channel and the offended is not owner.
  61. #
  62. # # Kick.
  63. # do_everything_to.kick(connection, channel, kicker, Aggressiveness.retalliation_reason(self, connection, kicked, behaviour))
  64. #
  65. # # Battlebot behaviour.
  66. # elif behaviour == "battlebot":
  67. # ChanServ.akick_del(connection, channel, kicked)
  68. #
  69. # # Rejoin if bot was kicked.
  70. # if kicked == connection.get_nickname():
  71. # print("Rejoining " + channel)
  72. # do_everything_to.join(self, connection, channel)
  73. #
  74. # if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
  75. # print("Stop if offender is bot or owner")
  76. # return # Stop if offender is bot or owner.
  77. # if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
  78. # print("Stop if offended is not atleast halfop and is not the bot itself")
  79. # return # Stop if offended is not atleast halfop and is not the bot itself.
  80. # if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
  81. # print("Stop if offender is at least halfop in the home channel and the offended is not owner")
  82. # return # Stop if offender is at least halfop in the home channel and the offended is not owner.
  83. # print("Kickbanning")
  84. #
  85. # ChanServ.tempban(connection, channel, kicker, "1h", "Aggression channel function = equal_retalliation: " + kicked)
  86. # connection.mode(channel, "+e " + kicked) # Excempt operator.
  87. # ChanServ.akick_add(connection, channel, kicker) # Add kicker to ChanServs autokick.
  88. # do_everything_to.bankick(connection, channel, kicker, event.source, "Aggression channel function = equal_retalliation: " + kicked)