示例#1
0
async def get_response(command, options, arguments, arguments_blocks, raw_parameters, server_id, channel_id, voice_channel_id, user_id, is_admin, is_private):
    """Responds to the basic commands that are always available."""
    
    to_return = ''
    
    # Base commands (sans admin)
    if command == 'ping':
        to_return += "Pong!\nOptions: {options}\nArguments: {arguments}\nArguments blocks: {arguments_blocks}".format(
            options = str(options),
            arguments = str(arguments),
            arguments_blocks = str(arguments_blocks))
    elif command == 'help':
        if len(arguments) > 1:
            raise bot_exception(BASE_EXCEPT_TYPE, "You can only get help on one command")
        to_return += help(arguments[0] if len(arguments) == 1 else '')
    
    # Admin commands
    elif command == 'admin' and len(options) == 1 and not is_private:
        if not is_admin:
            raise bot_exception(BASE_EXCEPT_TYPE, "You must be an admin or the bot owner for these commands")
        if len(arguments) == 1 and not is_private:
            if options[0] in ['ban', 'unban']: # All checks here are explicit to enforce strict syntax
                to_return += servermanager.add_ban(server_id, usermanager.get_user_id(server_id, arguments[0]), add=(options[0] == 'ban'))
            elif options[0] in ['add', 'remove']:
                if not servermanager.is_owner(user_id):
                    raise bot_exception(BASE_EXCEPT_TYPE, "You must be the bot owner for this command")
                to_return += servermanager.add_admin(server_id, usermanager.get_user_id(server_id, arguments[0]), add=(options[0] == 'add'))
            elif options[0] in ['mute', 'unmute']:
                to_mute = options[0] == 'mute'
                if arguments[0] in ['channel', 'voicechannel']:
                    to_return += servermanager.mute_channel(server_id, channel_id if arguments[0] == 'channel' else voice_channel_id, mute=to_mute)
                elif arguments[0] == 'server':
                    to_return += servermanager.mute_server(server_id, mute=to_mute)
            elif options[0] == 'info':
                if arguments[0] in ['channel', 'voicechannel']:
                    to_return += servermanager.get_channel_info(server_id, channel_id if arguments[0] == 'channel' else voice_channel_id)
                elif arguments[0] == 'server':
                    to_return += servermanager.get_server_info(server_id)
        elif len(arguments) == 0:
            if options[0] == 'version':
                to_return += '**`{version}`** ({date})'.format(version=botmanager.BOT_VERSION, date=botmanager.BOT_DATE)
            elif options[0] == 'ip':
                s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                s.connect(('8.8.8.8', 80)) # Thanks Google, you da real MVP
                ret = s.getsockname()[0]
                s.close()
                to_return += "Local IP: " + ret
            elif options[0] == 'halt':
                if not servermanager.is_owner(user_id):
                    raise bot_exception(BASE_EXCEPT_TYPE, "You must be the bot owner for this command")
                print("Halting execution...")
                if not is_private:
                    await botmanager.interrupt_broadcast(server_id, channel_id, "Going down...")
                await botmanager.disconnect_bot()
                await asyncio.sleep(2)
                sys.exit()
            elif options[0] == 'source':
                to_return += random.choice([
                    "It's shit. I'm sorry.", "You want to see what the Matrix is like?",
                    "Script kiddie level stuff in here.", "Beware the lack of PEP 8 guidelines inside!",
                    "Snarky comments inside and out.", "The last codebender. And he's shit at it.",
                    "Years down the road, this will all just be a really embarrassing but funny joke.",
                    "Made with ~~love~~ pure hatred.", "At least he's using version control."])
                to_return += "\nhttps://github.com/TheJsh/JshBot"
            elif options[0] == 'clear':
                to_return += '```\n'
                for i in range(0, 80):
                    to_return += '.\n'
                to_return += random.choice([
                    "Think twice before scrolling up.", "clear ver {}".format(botmanager.BOT_VERSION),
                    "Can you find the one comma?", "Are people watching? If so, best not to scroll up.",
                    "Don't worry, just censorship doing its thing.", "This is why we can't have nice things.",
                    "The only one who can spam is ME.", "That made me feel a bit queasy...",
                    "We need a better content filter. 18+ checks, maybe?", "You ANIMALS. At least I'm not one.",
                    "Scroll up if you want to be on a list.", "I'll bet the NSA will have a fun time scrolling up.",
                    "So much wasted space...", "This is pretty annoying, huh? Well TOO BAD.",
                    "No time to delete!"])
                to_return += '```\n'
            elif options[0] == 'ca':
                await botmanager.change_avatar()
                to_return += "Avatar changed"
            elif options[0] == 'cs':
                await botmanager.change_status()
                to_return += "Status changed"
            elif options[0] == 'uptime':
                uptime_total_seconds = int(time.time()) - botmanager.bot_turned_on_precise
                uptime_struct = time.gmtime(uptime_total_seconds)
                days = int(uptime_total_seconds / 86400)
                hours = uptime_struct.tm_hour
                minutes = uptime_struct.tm_min
                seconds = uptime_struct.tm_sec
                return "The bot has been on since **{initial}**\n{days} days\n{hours} hours\n{minutes} minutes\n{seconds} seconds".format(
                        initial=botmanager.bot_turned_on_date, days=days, hours=hours, minutes=minutes, seconds=seconds)
                
            
    if to_return:
        return to_return
    else: # Invalid command
        raise bot_exception(BASE_EXCEPT_TYPE, "Invalid syntax")
        
    return to_return
示例#2
0
async def get_response(command, options, arguments, arguments_blocks, raw_parameters, server_id, channel_id, voice_channel_id, user_id, is_admin, is_private):
    """Gets a response from the command and parameters."""
    
    to_return = ''
    num_options = len(options)
    num_arguments = len(arguments)
    using_shortcut = command in commands_dictionary['shortcut_commands']

    # Play sounds
    if (not using_shortcut and num_options == 0 and num_arguments >= 1):
        try: # For convenience, try with both raw parameters and single argument
            if num_arguments == 1:
                await play_sound_tag(server_id, voice_channel_id, arguments[0].lower().replace(' ', ''), user_id)
                return None;
        except bot_exception:
            pass
        await play_sound_tag(server_id, voice_channel_id, arguments_blocks[0].lower().replace(' ', ''), user_id)
        return None;

    # Create sound tag
    elif (num_arguments == 2 and ((command in ['stc'] and num_options == 0) or
            (not using_shortcut and (num_options == 1 or (num_options == 2 and options[1] in ['p', 'private'])) and
            options[0] in ['c', 'create']))):
        use_private = num_options == 2 and options[1] in ['p', 'private'] # Private tag
        return update_sound_tag(server_id, sound_tag_name=arguments[0].lower(), url=arguments[1], author_id=user_id, private=use_private)

    # Remove sound tag
    elif (num_arguments >= 1 and ((command in ['str'] and num_options == 0) or
            (not using_shortcut and num_options == 1 and options[0] in ['r', 'remove']))):
        sound_tag_name = (arguments[0].lower() if num_arguments == 1 else arguments_blocks[0].lower()).replace(' ', '')
        return remove_sound_tag(server_id, sound_tag_name, user_id)
    
    # List sound tags
    elif ((command in ['stl'] and num_options == 0) or
            (not using_shortcut and num_options == 1 and num_arguments <= 1 and options[0] in ['l', 'list'])):
        return list_sound_tags(server_id, user_id=usermanager.get_user_id(server_id, arguments[0]) if num_arguments == 1 else '')
    
    # Search sound tags
    elif (num_arguments >= 1 and ((command in ['sts'] and num_options == 0) or
            (not using_shortcut and num_options == 1 and options[0] in ['s', 'search']))):
        sound_tag_name = (arguments[0].lower() if num_arguments == 1 else arguments_blocks[0].lower()).replace(' ', '')
        return search_sound_tags(server_id, sound_tag_name)
        
    # Sound tag info
    elif not using_shortcut and num_options == 1 and num_arguments >= 1 and options[0] in ['i', 'info']:
        sound_tag_name = (arguments[0].lower() if num_arguments == 1 else arguments_blocks[0].lower()).replace(' ', '')
        return get_sound_info(server_id, sound_tag_name)
    
    # Edit sound tag
    elif not using_shortcut and (num_options in range(1,3)) and num_arguments <= 2 and options[0] in ['e', 'edit']:
        if num_options == 2 and num_arguments == 1: # Set private or public
            if options[1] == 'setpublic': # Explicit to follow a strict syntax
                return update_sound_tag(server_id, sound_tag_name=arguments[0].lower(), user_id=user_id, private=False)
            elif options[1] == 'setprivate':
                return update_sound_tag(server_id, sound_tag_name=arguments[0].lower(), user_id=user_id, private=True)
        elif num_options == 1 and num_arguments == 2: # Modify sound tag url
            return update_sound_tag(server_id, sound_tag_name=arguments[0].lower(), user_id=user_id, url=arguments[1], private=False)
    
    # Stop sounds
    elif ((command in ['stfu'] and num_arguments == 0 and num_options == 0) or
            (not using_shortcut and num_options == 1 and num_arguments == 0 and options[0] in ['stop', 'silence', 'silent', 'fu'])):
        return await stop_sounds(server_id)
    

    # Invalid command
    raise bot_exception(EXCEPT_TYPE, "Invalid syntax", get_formatted_usage_string())
示例#3
0
async def get_response(command, options, arguments, arguments_blocks,
                       raw_parameters, server_id, channel_id, voice_channel_id,
                       user_id, is_admin, is_private):
    """Gets a response from the command and parameters."""

    to_return = ''
    num_options = len(options)
    num_arguments = len(arguments)
    using_shortcut = command in commands_dictionary['shortcut_commands']

    # Play sounds
    if (not using_shortcut and num_options == 0 and num_arguments >= 1):
        try:  # For convenience, try with both raw parameters and single argument
            if num_arguments == 1:
                await play_sound_tag(server_id, voice_channel_id,
                                     arguments[0].lower().replace(' ',
                                                                  ''), user_id)
                return None
        except bot_exception:
            pass
        await play_sound_tag(server_id, voice_channel_id,
                             arguments_blocks[0].lower().replace(' ',
                                                                 ''), user_id)
        return None

    # Create sound tag
    elif (num_arguments == 2
          and ((command in ['stc'] and num_options == 0) or
               (not using_shortcut and
                (num_options == 1 or
                 (num_options == 2 and options[1] in ['p', 'private']))
                and options[0] in ['c', 'create']))):
        use_private = num_options == 2 and options[1] in ['p', 'private'
                                                          ]  # Private tag
        return update_sound_tag(server_id,
                                sound_tag_name=arguments[0].lower(),
                                url=arguments[1],
                                author_id=user_id,
                                private=use_private)

    # Remove sound tag
    elif (num_arguments >= 1 and ((command in ['str'] and num_options == 0) or
                                  (not using_shortcut and num_options == 1
                                   and options[0] in ['r', 'remove']))):
        sound_tag_name = (arguments[0].lower() if num_arguments == 1 else
                          arguments_blocks[0].lower()).replace(' ', '')
        return remove_sound_tag(server_id, sound_tag_name, user_id)

    # List sound tags
    elif ((command in ['stl'] and num_options == 0)
          or (not using_shortcut and num_options == 1 and num_arguments <= 1
              and options[0] in ['l', 'list'])):
        return list_sound_tags(
            server_id,
            user_id=usermanager.get_user_id(server_id, arguments[0])
            if num_arguments == 1 else '')

    # Search sound tags
    elif (num_arguments >= 1 and ((command in ['sts'] and num_options == 0) or
                                  (not using_shortcut and num_options == 1
                                   and options[0] in ['s', 'search']))):
        sound_tag_name = (arguments[0].lower() if num_arguments == 1 else
                          arguments_blocks[0].lower()).replace(' ', '')
        return search_sound_tags(server_id, sound_tag_name)

    # Sound tag info
    elif not using_shortcut and num_options == 1 and num_arguments >= 1 and options[
            0] in ['i', 'info']:
        sound_tag_name = (arguments[0].lower() if num_arguments == 1 else
                          arguments_blocks[0].lower()).replace(' ', '')
        return get_sound_info(server_id, sound_tag_name)

    # Edit sound tag
    elif not using_shortcut and (num_options in range(
            1, 3)) and num_arguments <= 2 and options[0] in ['e', 'edit']:
        if num_options == 2 and num_arguments == 1:  # Set private or public
            if options[1] == 'setpublic':  # Explicit to follow a strict syntax
                return update_sound_tag(server_id,
                                        sound_tag_name=arguments[0].lower(),
                                        user_id=user_id,
                                        private=False)
            elif options[1] == 'setprivate':
                return update_sound_tag(server_id,
                                        sound_tag_name=arguments[0].lower(),
                                        user_id=user_id,
                                        private=True)
        elif num_options == 1 and num_arguments == 2:  # Modify sound tag url
            return update_sound_tag(server_id,
                                    sound_tag_name=arguments[0].lower(),
                                    user_id=user_id,
                                    url=arguments[1],
                                    private=False)

    # Stop sounds
    elif ((command in ['stfu'] and num_arguments == 0 and num_options == 0)
          or (not using_shortcut and num_options == 1 and num_arguments == 0
              and options[0] in ['stop', 'silence', 'silent', 'fu'])):
        return await stop_sounds(server_id)

    # Invalid command
    raise bot_exception(EXCEPT_TYPE, "Invalid syntax",
                        get_formatted_usage_string())