| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- from commands.common import CommandHelpers as CH
- from common import queries, font
- def do_command(self, connection, event, user, channel):
- cmdtype, trigger, command, replyto = CH.disect_command(self, event)
- # Do nothing if it's not a type of command.
- if not cmdtype:
- return
- # Do nothing if there is no command.
- if not command:
- return
- # The first word of the command sting with arguments, is just the command without arguments.
- try:
- one = command.split()[0] # Get raw command.
- except:
- return
- # Do noting if the games channel function is off and it's a channel message.
- if event.target != connection.get_nickname(): # Command issued to channel.
- if not queries.get_channel_setting_chat(self, channel.id): # Games are turned off in channel settigns.
- return # Do nothing.
- # Command list.
- if command == 'cmd' or command == 'cmds' or command == 'commands':
- if cmdtype == 'cmd':
- connection.privmsg(replyto, '%sChat: %s' % (font.grey, CH.ccc(self, "vocabulary")[:-2]))
- elif one == 'vocabulary' or one == 'vocab':
- curse = queries.random_curse(self)
- categories = ['curseWord', 'adjective', 'nickReplyAction', 'nickReplyMessage']
- if len(command.split()) == 1: # Command without arguments
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Add, display or ban a vocabulary item. Option and item are optional arguments.')
- connection.privmsg(replyto, '%sUsage:%s %s%s %scatagory option item' % (font.grey, font.blue, self.network.command_character, one, font.italic))
- 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))
- else: # Actual command without arguments.
- connection.privmsg(replyto, 'Insuficcient arguments. For help type: %s%s%s' % (font.blue, self.network.help_character, one))
- elif len(command.split()) == 2: # Command with one argument.
- if command.split()[1] == 'list':
- 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))
- elif command.split()[1].lower() in [category.lower() for category in categories]:
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Show a random %s' % command.split()[1])
- else:
- connection.privmsg(replyto, str(queries.random_vocabulary_item(self, command.split()[1].lower())))
- else:
- connection.privmsg(replyto, 'Invalid argument, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
- elif len(command.split()) == 3: # Command with two arguments.
- if command.split()[1] == 'list':
- if command.split()[2] == 'categories':
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Lists available categories.')
- else: # List categories
- connection.privmsg(replyto, ', '.join(categories))
- elif command.split()[2] == 'options':
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Lists available options.')
- else:
- connection.privmsg(replyto, 'add, info, ban')
- elif command.split()[2] == 'definitions':
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Lists definitions of definitions.')
- else:
- 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.')
- else:
- connection.privmsg(replyto, 'Unkown list, options are %scategories%s and %soptions%s.' % (font.blue, font.reset,font.blue, font.reset))
- elif command.split()[1].lower() in [category.lower() for category in categories]:
- if command.split()[2] in ['add', 'info', 'ban']:
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Without specifiying add, display or ban, this displays a random %s' % command.split()[1])
- else:
- connection.privmsg(replyto, queries.random_vocabulary_item(self, commands.spit()[1].lower()))
- else:
- connection.privmsg(replyto, 'Invalid option. Options are: add info ban')
- else:
- connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
- elif len(command.split()) >= 4: # Command with three or more arguments.
- if command.split()[1].lower() in [category.lower() for category in categories]:
- if command.split()[2] == 'add':
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Adds %s as %s' % (command.split()[3:][0], command.split()[1]))
- else:
- item = queries.get_vocabulary_item(self, command.split()[1].lower(), command.split()[3:][0])
- if item:
- connection.privmsg(replyto, '%s already present as %s.' % (command.split()[3:][0], command.split()[1]))
- else:
- queries.add_vocabulary_item(self, command.split()[1].lower(), user.id, command.split()[3:][0])
- connection.privmsg(replyto, '%s added as %s' % (command.split()[3:][0], command.split()[1]))
- elif command.split()[2] == 'info':
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Displays info on %s from %s.' % (command.split()[3:][0], command.split()[1]))
- else:
- item = queries.get_vocabulary_item(self, command.split()[1].lower(), command.split()[3:][0])
- if not item:
- connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:][0])
- else:
- if item.irc_user_id:
- item_user = item.irc_user_id
- else:
- item_user = item.web_user_id
- if item.banned:
- if item.banned_by_irc_user_id:
- item_ban_user = queries.get_user_name(self, item.banned_by_irc_user_id)
- else:
- item_ban_user = item.banned_by_web_user_id
- connection.privmsg(replyto, 'Created by %s on %s. Banned by %s on %s.' % (item_user, item.created, item_ban_user, item.ban_created))
- else:
- connection.privmsg(replyto, 'Created by %s on %s.' % (item_user, item.created))
- elif command.split()[2] == 'ban':
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Bans bot from uttering %s from %s' % (command.split()[3:][0], command.split()[1]))
- else:
- item = queries.get_vocabulary_item(self, command.split()[1].lower(), command.split()[3:][0])
- if not item:
- connection.privmsg(replyto, '%s is not in my vocabulary.' % command.split()[3:][0])
- else:
- if item.banned:
- connection.privmsg(replyto, '%s already banned as %s.' % (command.split()[3:][0], command.split()[1]))
- else:
- queries.ban_vocabulary_item(self, command.split()[1].lower(), user.id, item.id)
- connection.privmsg(replyto, '%s banned as %s.' % (command.split()[3:][0], command.split()[1]))
- else:
- connection.privmsg(replyto, 'Invalid option. Options are: list info ban')
- else:
- connection.privmsg(replyto, 'Invalid catagory. To list valid categories use: %s%s%s list categories' % (font.blue, self.network.command_character, one))
- # elif one == 'curse':
- # curse = queries.random_curse(self)
- # if command.split() == 1: # Command without arguments
- # if cmdtype == 'help':
- # if curse:
- # 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))
- # else:
- # 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))
- # connection.privmsg(replyto, '%sUsage:%s %s%s%s %sword' % (font.grey, font.blue, self.network.command_character, one, font.reset, font.italic))
- # else: # Actual command without arguments.
- # curseword = queries.random_curseword(self)
- # connection.privmsg(replyto, curseword)
- # elif command.split() == 2: # Command with one argument.
- # if cmdtype == 'help':
- # if swear:
- # connection.privmsg(replyto, 'Look up a %s swear word: %s%s' % (swear, font.italic, command.split()[1]))
- # else:
- # connection.privmsg(replyto, 'Look up swear word: %s%s' % (font.italic, command.split()[1]))
- # else: # Actual command with one argument.
- # curseword = quiries.get_curseword(self, command.split()[1])
- # if curseword.banned:
- # if curse:
- # connection.privmsg(replyto, 'Sorry, %s this word is banned!' % curse)
- # else:
- # connection.privmsg(replyto, 'Sorry, this word is banned.')
- # elif curseword.irc_user:
- # user_name = quiries.get_user_name(self, curseword.irc_user.id)
- # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, user_name, font.reset))
- # elif curseword.web_user:
- # #user_name = quiries.get_user_name(self, curseword.irc_user.id)
- # connection.privmsg(replyto, 'Added %s by %s%s%s.' % (curseword.created, font.red, 'a web user', font.reset))
- # elif command.split() == 3: # Command with two arguments.
- # if command.split()[1] == 'add': # Add a curse word.
- # if cmdtype == 'help':
- # connection.privmsg(replyto, 'Adds curse word %s to my vocabulary.' % (command.split()[2]))
- # else: # Actual command.
- # if command.split()[2] == 'adj':
- # curse = queries.random_curse(self)
- # if curse:
- # connection.privmsg(replyto, '%sAdj%s is not a %s swearword!' % (font.italic, font.reset, curse))
- # else:
- # connection.privmsg(replyto, '%sAdj%s is not a swearword.' % (font.italic, font.reset))
- # return
- # queries.add_curseword(self, command.split()[2], user.id)
- # if curse:
- # connection.privmsg(replyto, '%s!' % curse)
- # elif command.split()[1] == 'adj': # Add an adjective.
- # if cmdtype == 'help':
- # connection.privmsg(replyto, 'Adds adjective %s to my vocabulary.' % (command.split()[2]))
- # else: # Actual command.
- # queries.add_adjective(self, command.split()[2], user.id)
- # if curse:
- # connection.privmsg(replyto, '%s!'curse)
- # else: # Syntax error.
- # if curse:
- # connection.privmsg(replyto, 'Invalid syntax, for %s help type: %s%s%s' % (curse, font.blue, self.network.command_character, one))
- # else:
- # connection.privmsg(replyto, 'Invalid syntax, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
- # elif command.split() >= 4: # Too many arguments.
- # connection.privmsg(replyto, 'Too many arguments, for help type: %s%s%s' % (font.blue, self.network.command_character, one))
|