on_action.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from common import userstatus
  2. from events.common import Replyto
  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. if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned
  14. # Stop if channelfunction chat if off.
  15. if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  16. return
  17. # Stop if it's a slap.
  18. if event.arguemnts[0].startswith() == "slaps ":
  19. return
  20. Replyto.name(connection, event)
  21. # Save statistic to database.
  22. if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"): # Not on record.
  23. self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')") # Create record.
  24. self.db.run("UPDATE \"users\" SET actions=actions+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
  25. # Slap guard.
  26. if event.arguments[0].lower().startswith("slaps ") and not event.target == connection.get_nickname(): # Channel action that stats with "slaps ".
  27. # Stop if chat channel function is off.
  28. if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  29. return
  30. # Only protect the worty.
  31. 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.
  32. return
  33. if userstatus.atleast_voiced(self, event.source.nick, self.homechannel): # Slapper has atleast voice in home channel.
  34. if not self.channels[self.homechannel].is_owner(event.arguments[0].split(" ")[1]): # Slappee is not owner.
  35. return
  36. 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.
  37. return
  38. # Respond.
  39. if " with a " in event.arguments[0]:
  40. if event.arguments[0].split(" with a ", maxsplit=1)[1]:
  41. if event.arguments[0].split(" ")[1].lower() == self.get_nickname(): # Bot slapped
  42. connection.action(event.target, "Takes the " + event.arguments[0].split(" with a ", maxsplit=1)[1] + " like a robot.")
  43. else:
  44. 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])
  45. elif event.arguments[0].split(" ")[1].lower() == self.get_nickname(): # Bot slapped
  46. connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
  47. else:
  48. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
  49. elif len(event.arguments[0].split(" ")) > 1:
  50. if event.arguments[0].split(" ")[1].lower() == self.get_nickname(): # Bot slapped
  51. connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
  52. else:
  53. connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")