1
0

chat.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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', 'nickreply']
  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%slist categories%s List options: %s%s%slist options' % (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' % (font.blue, self.network.command_character, one, font.reset, font.blue, self.network.command_character, one))
  37. elif command.split()[1] 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. else:
  57. connection.privmsg(replyto, 'Unkown list, options are %scategories%s and %soptions%s.' % (font.blue, font.reset,font.blue, font.reset))
  58. elif command.split()[1] in catagories:
  59. if command.split()[2] in ['add', 'info', 'ban']:
  60. if cmdtype == 'help':
  61. connection.privmsg(replyto, 'Without specifiying add, display or ban, this displays a random %s' % command,split()[1])
  62. else:
  63. connection.privmsg(replyto, queries.random_vocabulary_item(self, commands.spit()[1]))
  64. else:
  65. connection.privmsg(replyto, 'Invalid option. Options are: add info ban')
  66. else:
  67. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  68. elif len(command.split()) >= 4: # Command with three or more arguments.
  69. if command.split()[1] in catagories:
  70. if command.split()[2] == 'add':
  71. if cmdtype == 'help':
  72. connection.privmsg(replyto, 'Adds %s to %s' % (command.split()[3:], command.split()[1]))
  73. else:
  74. queries.add_vocabulary_item(self, table_suffix, user.id, command.split()[3:])
  75. connection.privmsg(replyto, '%s added to %s' % (command.split()[3:]), commands.split()[1])
  76. elif command.split()[2] == 'info':
  77. if cmdtype == 'help':
  78. connection.privmsg(replyto, 'Displays info on %s from %s' % (command.split()[3:], command.split()[1]))
  79. else:
  80. item = queries.get_vocabulary_item(self, command.split()[1], command.split()[3:])
  81. if not item:
  82. connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:])
  83. else:
  84. if item.irc_user:
  85. item_user = item.irc_user
  86. else:
  87. item_user = item.web_user
  88. if item.banned:
  89. if item.banned_by_irc_user:
  90. item_ban_user = queries.get_user_name(self, item.banned_by_irc_user)
  91. else:
  92. item_ban_user = item.banned_by_web_user
  93. connection.privmsg(replyto, 'Created by %s on %s. Banned by %s on %s.' % (item_user, item.created, item_ban_user, item.ban_created))
  94. elif command.split()[1] == 'ban':
  95. if cmdtype == 'help':
  96. connection.privmsg(replyto, 'Bans bot from uttering %s from %s' % (command.split()[3:], command.split()[1]))
  97. else:
  98. item = queries.get_vocabulary_item(self, table_suffix, command.split()[3:])
  99. if not item:
  100. connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:])
  101. else:
  102. queries.ban_vocabulary_item(self, command.split()[1], user.id, item.id)
  103. connection.privmsg(replyto, '%s banned from %s' % (command.split()[3:]), commands.split()[1])
  104. else:
  105. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  106. else:
  107. connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
  108. # elif one == 'curse':
  109. # curse = queries.random_curse(self)
  110. # if command.split() == 1: # Command without arguments
  111. # if cmdtype == 'help':
  112. # if curse:
  113. # 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))
  114. # else:
  115. # 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))
  116. # connection.privmsg(replyto, '%sUsage:%s %s%s%s %sword' % (font.grey, font.blue, self.network.command_character, one, font.reset, font.italic))
  117. # else: # Actual command without arguments.
  118. # curseword = queries.random_curseword(self)
  119. # connection.privmsg(replyto, curseword)
  120. # elif command.split() == 2: # Command with one argument.
  121. # if cmdtype == 'help':
  122. # if swear:
  123. # connection.privmsg(replyto, 'Look up a %s swear word: %s%s' % (swear, font.italic, command.split()[1]))
  124. # else:
  125. # connection.privmsg(replyto, 'Look up swear word: %s%s' % (font.italic, command.split()[1]))
  126. # else: # Actual command with one argument.
  127. # curseword = quiries.get_curseword(self, command.split()[1])
  128. # if curseword.banned:
  129. # if curse:
  130. # connection.privmsg(replyto, 'Sorry, %s this word is banned!' % curse)
  131. # else:
  132. # connection.privmsg(replyto, 'Sorry, this word is banned.')
  133. # elif curseword.irc_user:
  134. # user_name = quiries.get_user_name(self, curseword.irc_user.id)
  135. # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, user_name, font.reset))
  136. # elif curseword.web_user:
  137. # #user_name = quiries.get_user_name(self, curseword.irc_user.id)
  138. # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, 'a web user', font.reset))
  139. # elif command.split() == 3: # Command with two arguments.
  140. # if command.split()[1] == 'add': # Add a curse word.
  141. # if cmdtype == 'help':
  142. # connection.privmsg(replyto, 'Adds curse word %s to my vocabulary.' % (command.split()[2]))
  143. # else: # Actual command.
  144. # if command.split()[2] == 'adj':
  145. # curse = queries.random_curse(self)
  146. # if curse:
  147. # connection.privmsg(replyto, '%sAdj%s is not a %s swearword!' % (font.italic, font.reset, curse))
  148. # else:
  149. # connection.privmsg(replyto, '%sAdj%s is not a swearword.' % (font.italic, font.reset))
  150. # return
  151. # queries.add_curseword(self, command.split()[2], user.id)
  152. # if curse:
  153. # connection.privmsg(replyto, '%s!' % curse)
  154. # elif command.split()[1] == 'adj': # Add an adjective.
  155. # if cmdtype == 'help':
  156. # connection.privmsg(replyto, 'Adds adjective %s to my vocabulary.' % (command.split()[2]))
  157. # else: # Actual command.
  158. # queries.add_adjective(self, command.split()[2], user.id)
  159. # if curse:
  160. # connection.privmsg(replyto, '%s!'curse)
  161. # else: # Syntax error.
  162. # if curse:
  163. # connection.privmsg(replyto, 'Invalid syntax, for %s help type: %s%s%s' % (curse, font.blue, self.network.command_character, one))
  164. # else:
  165. # connection.privmsg(replyto, 'Invalid syntax, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
  166. # elif command.split() >= 4: # Too many arguments.
  167. # connection.privmsg(replyto, 'Too many arguments, for help type: %s%s%s' % (font.blue, self.network.command_character, one))