on_action.py 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from common import userstatus
  2. from events.common import Replyto, Lastact
  3. bold = "\x02"
  4. italic = "\x1D"
  5. underline = "\x1F"
  6. reverse = "\x16" # swap background and foreground colors ("reverse video")
  7. reset = "\x0F"
  8. blue = "\x0302"
  9. green = "\x0303"
  10. red = "\x0304"
  11. grey = "\x0314"
  12. def process_event(self, connection, event):
  13. # Update last act.
  14. Lastact.update(self, event.source.nick, "action", channel=event.target, lastact=event.arguments[0])
  15. # Save statistic to database.
  16. if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"): # Not on record.
  17. self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')") # Create record.
  18. self.db.run("UPDATE \"users\" SET actions=actions+1, actions_words=actions_words+" + str(len(event.arguments[0].split())) + ", actions_characters=actions_characters+" + str(len(event.arguments[0])) + " WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
  19. # Stop if channelfunction chat if off.
  20. if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  21. return
  22. # Slap guard.
  23. if event.arguments[0].lower().startswith("slaps ") and not event.target == connection.get_nickname(): # Channel action that stats with "slaps ".
  24. # Stop if chat channel function is off.
  25. if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  26. return
  27. # Only protect the worty.
  28. if not userstatus.atleast_voiced(self, event.arguments[0].split(" ")[1], self.homechannel) and not userstatus.atleast_oper(self, event.arguments[0].split(" ")[1], self.homechannel): # Insufficient rights.
  29. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  30. Replyto.name(connection, event)
  31. return
  32. if userstatus.atleast_voiced(self, event.source.nick, self.homechannel): # Slapper has atleast voice in home channel.
  33. if not self.channels[self.homechannel].is_owner(event.arguments[0].split(" ")[1]): # Slappee is not owner.
  34. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  35. Replyto.name(connection, event)
  36. return
  37. if self.channels[self.homechannel].is_owner(event.source.nick) and self.channels[self.homechannel].is_owner(event.arguments[0].split(" ")[1]): # Slapper and slappee are owner.
  38. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  39. Replyto.name(connection, event)
  40. return
  41. # Respond.
  42. if " with a " in event.arguments[0]:
  43. if event.arguments[0].split(" with a ", maxsplit=1)[1]:
  44. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  45. connection.action(event.target, "Takes the " + event.arguments[0].split(" with a ", maxsplit=1)[1] + " like a robot.")
  46. else:
  47. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the " + event.arguments[0].split(" with a ", maxsplit=1)[1])
  48. elif event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  49. connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
  50. else:
  51. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
  52. elif len(event.arguments[0].split(" ")) > 1:
  53. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  54. connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
  55. else:
  56. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
  57. # Respond to own name.
  58. elif 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.
  59. Replyto.name(connection, event)