1
0

on_pubmsg.py 2.2 KB

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