on_action.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from common import userstatus
  2. from events.common import Replyto, Lastact, MessageStatistics
  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. MessageStatistics.update(self, event, "action")
  17. # Stop if channelfunction chat if off.
  18. if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  19. return
  20. # Slap guard.
  21. if event.arguments[0].lower().startswith("slaps ") and not event.target == connection.get_nickname(): # Channel action that stats with "slaps ".
  22. # Stop if chat channel function is off.
  23. if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  24. return
  25. # Only protect the worty.
  26. 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.
  27. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  28. Replyto.name(connection, event)
  29. return
  30. if userstatus.atleast_voiced(self, event.source.nick, self.homechannel): # Slapper has atleast voice in home channel.
  31. if not self.channels[self.homechannel].is_owner(event.arguments[0].split(" ")[1]): # Slappee is not owner.
  32. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  33. Replyto.name(connection, event)
  34. return
  35. 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.
  36. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  37. Replyto.name(connection, event)
  38. return
  39. # Respond.
  40. if " with a " in event.arguments[0]:
  41. if event.arguments[0].split(" with a ", maxsplit=1)[1]:
  42. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname().lower(): # Bot slapped
  43. connection.action(event.target, "Takes the " + event.arguments[0].split(" with a ", maxsplit=1)[1] + " like a robot.")
  44. else:
  45. 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])
  46. elif event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  47. connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
  48. else:
  49. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
  50. elif len(event.arguments[0].split(" ")) > 1:
  51. if event.arguments[0].split(" ")[1].lower() == connection.get_nickname(): # Bot slapped
  52. connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
  53. else:
  54. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
  55. # Respond to own name.
  56. 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.
  57. Replyto.name(connection, event)