chat.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 games channel function 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(self, channel.id): # Games are turned off in channel settigns.
  19. return # Do nothing.
  20. # Command list.
  21. if command == 'cmd' or command == 'cmds' or command == 'commands':
  22. if cmdtype == 'cmd':
  23. connection.privmsg(replyto, '%sChat: %s' % (font.grey, CH.ccc(self, "vocabulary")[:-2]))
  24. elif one == 'vocabulary' or one == 'vocab':
  25. curse = queries.random_curse(self)
  26. categories = ['curseWord', 'adjective', 'nickReplyAction', 'nickReplyMessage']
  27. if len(command.split()) == 1: # Command without arguments
  28. if cmdtype == 'help':
  29. connection.privmsg(replyto, 'Add, display or ban a vocabulary item. Option and item are optional arguments.')
  30. connection.privmsg(replyto, '%sUsage:%s %s%s %scatagory option item' % (font.grey, font.blue, self.network.command_character, one, font.italic))
  31. connection.privmsg(replyto, 'List categories: %s%s%s list categories%s List options: %s%s%s list options%s List definitions: %s%s%s list definitions' % (font.blue, self.network.command_character, one, font.reset, font.blue, self.network.command_character, one, font.reset, font.blue, self.network.command_character, one))
  32. else: # Actual command without arguments.
  33. connection.privmsg(replyto, 'Insuficcient arguments. For help type: %s%s%s' % (font.blue, self.network.help_character, one))
  34. elif len(command.split()) == 2: # Command with one argument.
  35. if command.split()[1] == 'list':
  36. connection.privmsg(replyto, 'List categories: %s%s%s list categories%s List options: %s%s%slist options%s List definitions: %s%s%s list definitions' % (font.blue, self.network.command_character, one, font.reset, font.blue, self.network.command_character, one, font.reset, font.blue, self.network.command_character, one))
  37. elif command.split()[1].lower() in categories:
  38. if cmdtype == 'help':
  39. connection.privmsg(replyto, 'Show a random %s' % command.split()[1])
  40. else:
  41. connection.privmsg(replyto, queries.random_vocabulary_item(self, command.split()[1].lower()))
  42. else:
  43. connection.privmsg(replyto, 'Invalid argument, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
  44. elif len(command.split()) == 3: # Command with two arguments.
  45. if command.split()[1] == 'list':
  46. if command.split()[2] == 'categories':
  47. if cmdtype == 'help':
  48. connection.privmsg(replyto, 'Lists available categories.')
  49. else: # List categories
  50. connection.privmsg(replyto, ' ,'.join(categories))
  51. elif command.split()[2] == 'options':
  52. if cmdtype == 'help':
  53. connection.privmsg(replyto, 'Lists available options.')
  54. else:
  55. connection.privmsg(replyto, 'add, info, ban')
  56. elif command.split()[2] == 'definitions':
  57. if cmdtype == 'help':
  58. connection.privmsg(replyto, 'Lists definitions of categories.')
  59. else:
  60. connection.privmsg(replyto, 'CurseWord: A not to harsh swear word, let\'s keep it funny, not vulgar. Adjective: Something you would put in front of a curse word. NickReplyMessage: A response to when my name is mentioned. NickReplyAction: An action (Also know as emote or /me) in responce to when my name is mentioned.')
  61. else:
  62. connection.privmsg(replyto, 'Unkown list, options are %scategories%s and %soptions%s.' % (font.blue, font.reset,font.blue, font.reset))
  63. elif command.split()[1].lower() in categories:
  64. if command.split()[2] in ['add', 'info', 'ban']:
  65. if cmdtype == 'help':
  66. connection.privmsg(replyto, 'Without specifiying add, display or ban, this displays a random %s' % command,split()[1])
  67. else:
  68. connection.privmsg(replyto, queries.random_vocabulary_item(self, commands.spit()[1]))
  69. else:
  70. connection.privmsg(replyto, 'Invalid option. Options are: add info ban')
  71. else:
  72. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  73. elif len(command.split()) >= 4: # Command with three or more arguments.
  74. if command.split()[1].lower() in categories:
  75. if command.split()[2] == 'add':
  76. if cmdtype == 'help':
  77. connection.privmsg(replyto, 'Adds %s to %s' % (command.split()[3:], command.split()[1]))
  78. else:
  79. queries.add_vocabulary_item(self, table_suffix, user.id, command.split()[3:])
  80. connection.privmsg(replyto, '%s added to %s' % (command.split()[3:]), commands.split()[1])
  81. elif command.split()[2] == 'info':
  82. if cmdtype == 'help':
  83. connection.privmsg(replyto, 'Displays info on %s from %s' % (command.split()[3:], command.split()[1]))
  84. else:
  85. item = queries.get_vocabulary_item(self, command.split()[1], command.split()[3:])
  86. if not item:
  87. connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:])
  88. else:
  89. if item.irc_user:
  90. item_user = item.irc_user
  91. else:
  92. item_user = item.web_user
  93. if item.banned:
  94. if item.banned_by_irc_user:
  95. item_ban_user = queries.get_user_name(self, item.banned_by_irc_user)
  96. else:
  97. item_ban_user = item.banned_by_web_user
  98. connection.privmsg(replyto, 'Created by %s on %s. Banned by %s on %s.' % (item_user, item.created, item_ban_user, item.ban_created))
  99. elif command.split()[1] == 'ban':
  100. if cmdtype == 'help':
  101. connection.privmsg(replyto, 'Bans bot from uttering %s from %s' % (command.split()[3:], command.split()[1]))
  102. else:
  103. item = queries.get_vocabulary_item(self, table_suffix, command.split()[3:])
  104. if not item:
  105. connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:])
  106. else:
  107. queries.ban_vocabulary_item(self, command.split()[1], user.id, item.id)
  108. connection.privmsg(replyto, '%s banned from %s' % (command.split()[3:]), commands.split()[1])
  109. else:
  110. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  111. else:
  112. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  113. # elif one == 'curse':
  114. # curse = queries.random_curse(self)
  115. # if command.split() == 1: # Command without arguments
  116. # if cmdtype == 'help':
  117. # if curse:
  118. # 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))
  119. # else:
  120. # 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))
  121. # connection.privmsg(replyto, '%sUsage:%s %s%s%s %sword' % (font.grey, font.blue, self.network.command_character, one, font.reset, font.italic))
  122. # else: # Actual command without arguments.
  123. # curseword = queries.random_curseword(self)
  124. # connection.privmsg(replyto, curseword)
  125. # elif command.split() == 2: # Command with one argument.
  126. # if cmdtype == 'help':
  127. # if swear:
  128. # connection.privmsg(replyto, 'Look up a %s swear word: %s%s' % (swear, font.italic, command.split()[1]))
  129. # else:
  130. # connection.privmsg(replyto, 'Look up swear word: %s%s' % (font.italic, command.split()[1]))
  131. # else: # Actual command with one argument.
  132. # curseword = quiries.get_curseword(self, command.split()[1])
  133. # if curseword.banned:
  134. # if curse:
  135. # connection.privmsg(replyto, 'Sorry, %s this word is banned!' % curse)
  136. # else:
  137. # connection.privmsg(replyto, 'Sorry, this word is banned.')
  138. # elif curseword.irc_user:
  139. # user_name = quiries.get_user_name(self, curseword.irc_user.id)
  140. # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, user_name, font.reset))
  141. # elif curseword.web_user:
  142. # #user_name = quiries.get_user_name(self, curseword.irc_user.id)
  143. # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, 'a web user', font.reset))
  144. # elif command.split() == 3: # Command with two arguments.
  145. # if command.split()[1] == 'add': # Add a curse word.
  146. # if cmdtype == 'help':
  147. # connection.privmsg(replyto, 'Adds curse word %s to my vocabulary.' % (command.split()[2]))
  148. # else: # Actual command.
  149. # if command.split()[2] == 'adj':
  150. # curse = queries.random_curse(self)
  151. # if curse:
  152. # connection.privmsg(replyto, '%sAdj%s is not a %s swearword!' % (font.italic, font.reset, curse))
  153. # else:
  154. # connection.privmsg(replyto, '%sAdj%s is not a swearword.' % (font.italic, font.reset))
  155. # return
  156. # queries.add_curseword(self, command.split()[2], user.id)
  157. # if curse:
  158. # connection.privmsg(replyto, '%s!' % curse)
  159. # elif command.split()[1] == 'adj': # Add an adjective.
  160. # if cmdtype == 'help':
  161. # connection.privmsg(replyto, 'Adds adjective %s to my vocabulary.' % (command.split()[2]))
  162. # else: # Actual command.
  163. # queries.add_adjective(self, command.split()[2], user.id)
  164. # if curse:
  165. # connection.privmsg(replyto, '%s!'curse)
  166. # else: # Syntax error.
  167. # if curse:
  168. # connection.privmsg(replyto, 'Invalid syntax, for %s help type: %s%s%s' % (curse, font.blue, self.network.command_character, one))
  169. # else:
  170. # connection.privmsg(replyto, 'Invalid syntax, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
  171. # elif command.split() >= 4: # Too many arguments.
  172. # connection.privmsg(replyto, 'Too many arguments, for help type: %s%s%s' % (font.blue, self.network.command_character, one))