chat.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 [category.lower() for category in categories]:
  38. if cmdtype == 'help':
  39. connection.privmsg(replyto, 'Show a random %s' % command.split()[1])
  40. else:
  41. connection.privmsg(replyto, str(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 definitions.')
  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 [category.lower() for category 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].lower()))
  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 [category.lower() for category in categories]:
  75. if command.split()[2] == 'add':
  76. if cmdtype == 'help':
  77. connection.privmsg(replyto, 'Adds %s as %s' % (command.split()[3:][0], command.split()[1]))
  78. else:
  79. item = queries.get_vocabulary_item(self, command.split()[1].lower(), command.split()[3:][0])
  80. if item:
  81. connection.privmsg(replyto, '%s already present as %s.' % (command.split()[3:][0], command.split()[1]))
  82. else:
  83. queries.add_vocabulary_item(self, command.split()[1].lower(), user.id, command.split()[3:][0])
  84. connection.privmsg(replyto, '%s added as %s' % (command.split()[3:][0], command.split()[1]))
  85. elif command.split()[2] == 'info':
  86. if cmdtype == 'help':
  87. connection.privmsg(replyto, 'Displays info on %s from %s.' % (command.split()[3:][0], command.split()[1]))
  88. else:
  89. item = queries.get_vocabulary_item(self, command.split()[1].lower(), command.split()[3:][0])
  90. if not item:
  91. connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:][0])
  92. else:
  93. if item.irc_user_id:
  94. item_user = item.irc_user_id
  95. else:
  96. item_user = item.web_user_id
  97. if item.banned:
  98. if item.banned_by_irc_user_id:
  99. item_ban_user = queries.get_user_name(self, item.banned_by_irc_user_id)
  100. else:
  101. item_ban_user = item.banned_by_web_user_id
  102. connection.privmsg(replyto, 'Created by %s on %s. Banned by %s on %s.' % (item_user, item.created, item_ban_user, item.ban_created))
  103. else:
  104. connection.privmsg(replyto, 'Created by %s on %s.' % (item_user, item.created))
  105. elif command.split()[2] == 'ban':
  106. if cmdtype == 'help':
  107. connection.privmsg(replyto, 'Bans bot from uttering %s from %s' % (command.split()[3:][0], command.split()[1]))
  108. else:
  109. item = queries.get_vocabulary_item(self, command.split()[1].lower(), command.split()[3:][0])
  110. if not item:
  111. connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:][0])
  112. else:
  113. if item.banned:
  114. connection.privmsg(replyto, '%s already banned as %s.' % (command.split()[3:][0], command.split()[1]))
  115. else:
  116. queries.ban_vocabulary_item(self, command.split()[1].lower(), user.id, item.id)
  117. connection.privmsg(replyto, '%s banned as %s.' % (command.split()[3:][0], command.split()[1]))
  118. else:
  119. connection.privmsg(replyto, 'Invalid option. Options are: list info ban')
  120. else:
  121. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  122. # elif one == 'curse':
  123. # curse = queries.random_curse(self)
  124. # if command.split() == 1: # Command without arguments
  125. # if cmdtype == 'help':
  126. # if curse:
  127. # 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))
  128. # else:
  129. # 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))
  130. # connection.privmsg(replyto, '%sUsage:%s %s%s%s %sword' % (font.grey, font.blue, self.network.command_character, one, font.reset, font.italic))
  131. # else: # Actual command without arguments.
  132. # curseword = queries.random_curseword(self)
  133. # connection.privmsg(replyto, curseword)
  134. # elif command.split() == 2: # Command with one argument.
  135. # if cmdtype == 'help':
  136. # if swear:
  137. # connection.privmsg(replyto, 'Look up a %s swear word: %s%s' % (swear, font.italic, command.split()[1]))
  138. # else:
  139. # connection.privmsg(replyto, 'Look up swear word: %s%s' % (font.italic, command.split()[1]))
  140. # else: # Actual command with one argument.
  141. # curseword = quiries.get_curseword(self, command.split()[1])
  142. # if curseword.banned:
  143. # if curse:
  144. # connection.privmsg(replyto, 'Sorry, %s this word is banned!' % curse)
  145. # else:
  146. # connection.privmsg(replyto, 'Sorry, this word is banned.')
  147. # elif curseword.irc_user:
  148. # user_name = quiries.get_user_name(self, curseword.irc_user.id)
  149. # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, user_name, font.reset))
  150. # elif curseword.web_user:
  151. # #user_name = quiries.get_user_name(self, curseword.irc_user.id)
  152. # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, 'a web user', font.reset))
  153. # elif command.split() == 3: # Command with two arguments.
  154. # if command.split()[1] == 'add': # Add a curse word.
  155. # if cmdtype == 'help':
  156. # connection.privmsg(replyto, 'Adds curse word %s to my vocabulary.' % (command.split()[2]))
  157. # else: # Actual command.
  158. # if command.split()[2] == 'adj':
  159. # curse = queries.random_curse(self)
  160. # if curse:
  161. # connection.privmsg(replyto, '%sAdj%s is not a %s swearword!' % (font.italic, font.reset, curse))
  162. # else:
  163. # connection.privmsg(replyto, '%sAdj%s is not a swearword.' % (font.italic, font.reset))
  164. # return
  165. # queries.add_curseword(self, command.split()[2], user.id)
  166. # if curse:
  167. # connection.privmsg(replyto, '%s!' % curse)
  168. # elif command.split()[1] == 'adj': # Add an adjective.
  169. # if cmdtype == 'help':
  170. # connection.privmsg(replyto, 'Adds adjective %s to my vocabulary.' % (command.split()[2]))
  171. # else: # Actual command.
  172. # queries.add_adjective(self, command.split()[2], user.id)
  173. # if curse:
  174. # connection.privmsg(replyto, '%s!'curse)
  175. # else: # Syntax error.
  176. # if curse:
  177. # connection.privmsg(replyto, 'Invalid syntax, for %s help type: %s%s%s' % (curse, font.blue, self.network.command_character, one))
  178. # else:
  179. # connection.privmsg(replyto, 'Invalid syntax, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
  180. # elif command.split() >= 4: # Too many arguments.
  181. # connection.privmsg(replyto, 'Too many arguments, for help type: %s%s%s' % (font.blue, self.network.command_character, one))