chat.py 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from commands.common import CommandHelpers as CH
  2. from common import queries, font
  3. def do_command(self, connection, event, user, channel):
  4. cmdtype, trigger, command, replyto = CH.disect_command(self, event)
  5. # Do nothing if it's not a type of command.
  6. if not cmdtype:
  7. return
  8. # Do nothing if there is no command.
  9. if not command:
  10. return
  11. # The first word of the command sting with arguments, is just the command without arguments.
  12. try:
  13. one = command.split()[0] # Get raw command.
  14. except:
  15. return
  16. # Do noting if the chat channel setting is off and it's a channel message.
  17. if event.target != connection.get_nickname(): # Command issued to channel.
  18. if not queries.get_channel_setting_chat: # Games are turned off in channel settigns.
  19. return # Do nothing.
  20. if command == 'cmd' or command == 'cmds' or command == 'commands':
  21. if cmdtype == 'cmd':
  22. connection.privmsg(replyto, '%sChat: %s' % (font.grey, CH.ccc(self, "curse")[:-2]))
  23. elif one == 'curse':
  24. curse = queries.random_curse(self)
  25. if command.split() == 1: # Command without arguments
  26. if cmdtype == 'help':
  27. if curse:
  28. connection.privmsg(replyto, 'Add, lookup, or display a random %s curse word. The word argument is optional, to add a new word%s %s%s add%s %sword%s, or an adjective: %s%s%s adj' % (curse, font.blue, self.network.command_character, one, font.reset, font.italic, font.reset, font.blue, self.network.command_character, one))
  29. else:
  30. connection.privmsg(replyto, 'Add, lookup, or display random curse word. The word argument is optional, to add a new word%s %s%s add%s %sword%s, or an adjective: %s%s%s add adj' % (font.blue, self.network.command_character, one, font.reset, font.italic, font.reset, font.blue, self.network.command_character, one))
  31. connection.privmsg(replyto, '%sUsage:%s %s%s%s %sword' % (font.grey, font.blue, self.network.command_character, one, font.reset, font.italic))
  32. else: # Actual command without arguments.
  33. curseword = queries.random_curseword(self)
  34. connection.privmsg(replyto, curseword)
  35. elif command.split() == 2: # Command with one argument.
  36. if cmdtype == 'help':
  37. if swear:
  38. connection.privmsg(replyto, 'Look up a %s swear word: %s%s' % (swear, font.italic, command.split()[1]))
  39. else:
  40. connection.privmsg(replyto, 'Look up swear word: %s%s' % (font.italic, command.split()[1]))
  41. else: # Actual command with one argument.
  42. curseword = quiries.get_curseword(self, command.split()[1])
  43. if curseword.banned:
  44. if curse:
  45. connection.privmsg(replyto, 'Sorry, %s this word is banned!' % curse)
  46. else:
  47. connection.privmsg(replyto, 'Sorry, this word is banned.')
  48. elif curseword.irc_user:
  49. user_name = quiries.get_user_name(self, curseword.irc_user.id)
  50. connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, user_name, font.reset))
  51. elif curseword.web_user:
  52. #user_name = quiries.get_user_name(self, curseword.irc_user.id)
  53. connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, 'a web user', font.reset))
  54. elif command.split() == 3: # Command with two arguments.
  55. if command.split()[1] == 'add': # Add a curse word.
  56. if cmdtype == 'help':
  57. connection.privmsg(replyto, 'Adds curse word %s to my vocabulary.' % (command.split()[2]))
  58. else: # Actual command.
  59. if command.split()[2] == 'adj':
  60. curse = queries.random_curse(self)
  61. if curse:
  62. connection.privmsg(replyto, '%sAdj%s is not a %s swearword!' % (font.italic, font.reset, curse))
  63. else:
  64. connection.privmsg(replyto, '%sAdj%s is not a swearword.' % (font.italic, font.reset))
  65. return
  66. queries.add_curseword(self, command.split()[2], user.id)
  67. if curse:
  68. connection.privmsg(replyto, '%s!' % curse)
  69. elif command.split()[1] == 'adj': # Add an adjective.
  70. if cmdtype == 'help':
  71. connection.privmsg(replyto, 'Adds adjective %s to my vocabulary.' % (command.split()[2]))
  72. else: # Actual command.
  73. queries.add_adjective(self, command.split()[2], user.id)
  74. if curse:
  75. connection.privmsg(replyto, '%s!'curse)
  76. else: # Syntax error.
  77. if curse:
  78. connection.privmsg(replyto, 'Invalid syntax, for %s help type: %s%s%s' % (curse, font.blue, self.network.command_character, one))
  79. else:
  80. connection.privmsg(replyto, 'Invalid syntax, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
  81. elif command.split() >= 4: # Too many arguments.
  82. connection.privmsg(replyto, 'Too many arguments, for help type: %s%s%s' % (font.blue, self.network.command_character, one))