public.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # Bot crashes once in a while when a user joins a channel, with "IndexError: list index out of range" on "command.split()[0] == "joins"".
  14. try:
  15. command.split()[0]
  16. except:
  17. return # Stop, there is no command.
  18. # The actual commands:
  19. if command == "test":
  20. if cmdtype == "help": #Display help text.
  21. connection.privmsg(replyto, "Strictly for testing purposes only!")
  22. elif cmdtype == "cmd":
  23. connection.privmsg(replyto, event)
  24. elif command == "cmd" or command == "commands":
  25. if cmdtype == "help": #Display help text.
  26. connection.privmsg(replyto, "Displays a list of commands.")
  27. elif cmdtype == "cmd":
  28. connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help") + CH.ccc(self, "joins") + CH.ccc(self, "stopgreet")[:-2] + ".")
  29. elif command == "help":
  30. if cmdtype == "help": #Display help text.
  31. connection.privmsg(replyto, "Explains how to get help on any specific command and hints the user to the commandlist.")
  32. elif cmdtype == "cmd":
  33. 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")
  34. connection.privmsg(replyto, grey + "Example: " + reset + blue + self.helpchar + "help")
  35. elif command.split()[0] == "joins":
  36. if cmdtype == "help": #Display help text.
  37. connection.privmsg(replyto, "Display amount of joins of user and or channel. Channel and user optional.")
  38. connection.privmsg(replyto, grey + "Usage: " + blue + "!joins " + reset + italic + "channel user")
  39. elif cmdtype == "cmd":
  40. # Parse user input
  41. if len(command.split()) < 2: # Command contains only !joins.
  42. user = event.source.nick
  43. if connection.get_nickname() is not event.target:
  44. channel = event.target
  45. elif len(command.split()) < 3: # Command has one argument.
  46. if command.split()[1] in self.channels:
  47. channel = command.split()[1]
  48. else:
  49. user = command.split()[1]
  50. elif len(command.split()) < 4: # Command has two arguments.
  51. if not command.split()[1] in self.channels: # Bot does not inhabit requested channel.
  52. if not command.split()[2] in self.channels: # User did not revert channel and user in command syntax.
  53. connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ".")
  54. return
  55. else: # User reverted user and channel in command syntax.
  56. user = command.split()[1]
  57. channel = command.split()[2]
  58. else: # Bot does inhabit requested channel.
  59. user = command.split()[2]
  60. channel = command.split()[1]
  61. elif len(command.split()) < 5: # To many arguments
  62. connection.privmsg(replyto, "To many arguments. For help type " + blue + self.helpchar + "joins" + reset + ".")
  63. return
  64. try:
  65. if user and channel:
  66. userjoins = str(self.db.one("SELECT joins FROM joins WHERE channel_network='" + self.network + "' AND \"user\"='" + user + "' AND user_network='" + self.network + "'"))
  67. 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 + "'"))
  68. channeljoins = str(sum(self.db.all("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND user_network='" + self.network + "'")))
  69. 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.")
  70. return
  71. except:
  72. pass
  73. try:
  74. if user:
  75. 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 + "'"))
  76. connection.privmsg(replyto, red + user + reset + " has " + green + userjoins + reset + " joins in channels I monitor.")
  77. return
  78. except:
  79. pass
  80. try:
  81. if channel:
  82. channeljoins = str(sum(self.db.all("SELECT joins FROM joins WHERE channel='" + channel + "' AND channel_network='" + self.network + "' AND user_network='" + self.network + "'")))
  83. connection.privmsg(replyto, red + channel + reset + " has been joined " + green + channeljoins + reset + " times.")
  84. return
  85. except:
  86. pass
  87. connection.privmsg(replyto, "tBKwtWS Was wondering if this programming was sloppy. When you see this message, it was.")
  88. elif command.split()[0] == "stopgreet":
  89. if cmdtype == "help": #Display help text.
  90. connection.privmsg(replyto, "Stops the bot from greeting you or a specific user. Channel and user optional.")
  91. connection.privmsg(replyto, grey + "Usage: " + blue + "!stopgreet " + red + italic + "channel user")
  92. elif cmdtype == "cmd":
  93. if len(command.splt()) == 1: # No arguments.
  94. if self.db.one("SELECT id FROM")
  95. if len(command.splt()) == 2: # One argument.
  96. if len(command.splt()) == 3: # Two arguments.
  97. if len(command.splt()) < 3: # Too many arguments.