on_pubmsg.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import datetime, pytz
  2. import commands.public, commands.admin, commands.games, commands.statistics
  3. from common import log, queries
  4. def process_event(self, connection, event):
  5. # Let's not log all public messages to the console.
  6. # Get and update resources.
  7. channel = queries.create_or_get_and_update_last_event(self, 'channel', 'cm', channel_name=event.target, user_name=event.source.nick)
  8. user = queries.create_or_get_and_update_last_event(self, 'user', 'cm', channel_name=event.target, user_name=event.source.nick)
  9. queries.update_message_statistics(self, 'message', channel.id, user.id) # Update message statistics
  10. commands.public.do_command(self, connection, event, user, channel)
  11. commands.admin.do_command(self, connection, event, user, channel)
  12. commands.statistics.do_command(self, connection, event, user, channel)
  13. commands.games.do_command(self, connection, event, user, channel)
  14. # Stop if channelfunction chat if off.
  15. if not queries.get_channel_setting_chat(self, channel.id):
  16. return
  17. # if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned
  18. # if event.arguments[0].startswith(self.cmdchar):
  19. # return # Stop if it's a command.
  20. # Replyto.name(connection, event)
  21. # Character lame.
  22. elif event.arguments[0] == len(event.arguments[0]) * event.arguments[0][0]: # Trigger exclusively same character.
  23. # Stop if lamed recently.
  24. timeout = 10 # Timeout in minutes.
  25. chan_lastlame = queries.get_channel_last_lame(self, channel.id)
  26. user_lastlame = queries.get_user_last_lame(self, user.id)
  27. cet = pytz.timezone('Europe/Amsterdam')
  28. if chan_lastlame and chan_lastlame > cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout) or user_lastlame and user_lastlame > cet.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout): # Lamed channel or user recently.
  29. return
  30. # Do not say KKK.
  31. if event.arguments[0] == "kk":
  32. return
  33. connection.privmsg(event.target, event.arguments[0] + event.arguments[0][:1])
  34. # Update lastlame.
  35. queries.update_channel_last_lame(self, channel_id)
  36. queries.update_user_last_lame(self, user_id)