on_pubmsg.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Respond to own name.
  20. if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned, not by the bot itself.
  21. Replyto.name(self, connection, replyto)
  22. # Character lame.
  23. elif event.arguments[0] == len(event.arguments[0]) * event.arguments[0][0]: # Trigger exclusively same character.
  24. # Stop if it's short and not a dot or exclematin mark,
  25. if len(event.arguments[0]) < 3:
  26. if event.arguments[0][0] not in ['.', '!']:
  27. return
  28. # Stop if it's long.
  29. if len(event.arguments[0]) > 20:
  30. return
  31. # Stop if lamed recently.
  32. timeout = 10 # Timeout in minutes.
  33. chan_lastlame = queries.get_channel_last_lame(self, channel.id)
  34. user_lastlame = queries.get_user_last_lame(self, user.id)
  35. timezone = pytz.timezone('Europe/Amsterdam')
  36. if user_lastlame and user_lastlame > timezone.localize(datetime.datetime.now()) - datetime.timedelta(minutes=timeout): # Lamed user recently.
  37. return
  38. # Do not say KKK.
  39. if event.arguments[0] == "kk":
  40. return
  41. connection.privmsg(event.target, event.arguments[0] + event.arguments[0][:1])
  42. # Update lastlame.
  43. queries.update_channel_last_lame(self, channel.id)
  44. queries.update_user_last_lame(self, user.id)