public.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from commands.common import CommandHelpers as CH
  2. bold = "\x02"
  3. italic = "\x1D"
  4. underline = "\x1F"
  5. reverse = "\x16" # swap background and foreground colors ("reverse video")
  6. reset = "\x0F"
  7. blue = "\x0302"
  8. green = "\x0303"
  9. red = "\x0304"
  10. grey = "\x0314"
  11. def do_command(self, connection, event):
  12. cmdtype, trigger, command, replyto = CH.disect_command(self, event)
  13. # The actual commands:
  14. if command == "test":
  15. if cmdtype == "help": #Display help text.
  16. connection.privmsg(replyto, "Strictly for testing purposes only!")
  17. elif cmdtype == "cmd":
  18. connection.privmsg(replyto, event)
  19. elif command == "cmd" or command == "commands":
  20. if cmdtype == "help": #Display help text.
  21. connection.privmsg(replyto, "Displays a list of commands.")
  22. elif cmdtype == "cmd":
  23. connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help") + CH.ccc(self, "joins")[:-2] + ".")
  24. elif command == "help":
  25. if cmdtype == "help": #Display help text.
  26. connection.privmsg(replyto, "Explains how to get help on any specific command and hints the user to the commandlist.")
  27. elif cmdtype == "cmd":
  28. connection.privmsg(replyto, "Replace the " + italic + "! " + reset + "prefix of any comand with " + italic + self.helpchar + " " + reset + "for help with a specific command. Request the command list with: " + blue + "!cmd")
  29. connection.privmsg(replyto, grey + "Example: " + reset + blue + self.helpchar + "help")
  30. elif command.split()[0] == "joins":
  31. if cmdtype == "help": #Display help text.
  32. connection.privmsg(replyto, "Display amount of joins of user and or channel. Channel and user optional.")
  33. connection.privmsg(replyto, grey + "Usage: " + blue + "!joins " + reset + italic + "channel user")
  34. elif cmdtype == "cmd":
  35. # Parse user input
  36. if len(command.split()) < 2: # Command contains only !joins.
  37. user = event.source.nick
  38. if connection.get_nickname() is not event.target:
  39. channel = event.target
  40. elif len(command.split()) < 3: # Command has one argument.
  41. if command.split()[1] in self.channels:
  42. channel = command.split()[1]
  43. else:
  44. user = command.split()[1]
  45. elif len(command.split()) < 4: # Command has two arguments.
  46. if not command.split()[1] in self.channels: # Bot does not inhabit requested channel.
  47. if not command.split()[2] in self.channels: # User did not revert channel and user in command syntax.
  48. connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ".")
  49. return
  50. else: # User reverted user and channel in command syntax.
  51. user = command.split()[1]
  52. channel = command.split()[2]
  53. else: # Bot does inhabit requested channel.
  54. user = command.split()[2]
  55. channel = command.split()[1]
  56. elif len(command.split()) < 5: # To many arguments
  57. connection.privmsg(replyto, "To many arguments. For help type " + blue + self.helpchar + "joins" + reset + ".")
  58. return
  59. try:
  60. if user and channel:
  61. userjoins = str(self.db.one("SELECT joins FROM joins WHERE channel_network='" + self.network + "' AND \"user\"='" + user + "' AND user_network='" + self.network + "'"))
  62. userchanneljoins = str(self.db.one("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND \"user\"='" + user + "' AND user_network='" + self.network + "'"))
  63. channeljoins = str(sum(self.db.all("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND user_network='" + self.network + "'")))
  64. connection.privmsg(replyto, red + user + reset + " has " + green + userjoins + reset + " joins. Of which " + green + userchanneljoins + reset + " have been in " + red + channel + reset + ", that has " + green + channeljoins + reset + " joins" + reset + " in total.")
  65. return
  66. except:
  67. pass
  68. try:
  69. if user:
  70. userjoins = str(self.db.one("SELECT joins FROM joins WHERE channel='" + event.target + "' AND channel_network='" + self.network + "' AND \"user\"='" + event.source.nick + "' AND user_network='" + self.network + "'"))
  71. connection.privmsg(replyto, red + user + reset + " has " + green + userjoins + reset + " joins in channels I monitor.")
  72. return
  73. except:
  74. pass
  75. try:
  76. if channel:
  77. channeljoins = str(sum(self.db.all("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND user_network='" + self.network + "'")))
  78. connection.privmsg(replyto, red + channel + reset + " has been joined " + green + channeljoins + reset + " times.")
  79. return
  80. except:
  81. pass
  82. connection.privmsg(replyto, "tBKwtWS Was wondering if this programming was sloppy. When you see this message, it was.")