on_pubmsg.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import datetime, pytz
  2. import commands.public, commands.admin, commands.games, commands.statistics, commands.chat
  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. # Respond to commands.
  11. commands.public.do_command(self, connection, event, user, channel)
  12. commands.games.do_command(self, connection, event, user, channel)
  13. commands.statistics.do_command(self, connection, event, user, channel)
  14. commands.chat.do_command(self, connection, event, user, channel)
  15. commands.admin.do_command(self, connection, event, user, channel)
  16. # Stop if channelfunction chat if off.
  17. if not queries.get_channel_setting_chat(self, channel.id):
  18. return
  19. # if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned
  20. # if event.arguments[0].startswith(self.cmdchar):
  21. # return # Stop if it's a command.
  22. # Replyto.name(connection, event)
  23. # Character lame.
  24. elif event.arguments[0] == len(event.arguments[0]) * event.arguments[0][0]: # Trigger exclusively same character.
  25. # Stop if lamed recently.
  26. timeout = 10 # Timeout in minutes.
  27. chan_lastlame = queries.get_channel_last_lame(self, channel.id)
  28. user_lastlame = queries.get_user_last_lame(self, user.id)
  29. cet = pytz.timezone('Europe/Amsterdam')
  30. 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.
  31. return
  32. # Do not say KKK.
  33. if event.arguments[0] == "kk":
  34. return
  35. connection.privmsg(event.target, event.arguments[0] + event.arguments[0][:1])
  36. # Update lastlame.
  37. queries.update_channel_last_lame(self, channel.id)
  38. queries.update_user_last_lame(self, user.id)