示例#1
0
def get_info(server_id, user_id):
    """Builds a string listing known user information of given user."""
    user_data = servermanager.servers_data[server_id]['users'][user_id]
    config = configmanager.config
    permissions_text = ''
    if servermanager.is_owner(user_id): # Order important here
        permissions_text = "Bot owner"
    elif servermanager.is_bot(user_id):
        permissions_text = "Literally the bot"
    elif servermanager.is_admin(server_id, user_id):
        permissions_text = "Bot admin"
    elif servermanager.is_banned(server_id, user_id):
        permissions_text = "Banned from interaction"
    else:
        permissions_text = "Standard user"
    to_return = """User information for {user_data[name]}:
```
ID: {user_id}
Name: {user_data[name]}
Nickname: {user_data[nickname]}
Discriminator: {user_data[discriminator]}
Aliases: {user_data[aliases]}
Permissions: {permissions_text}
Joined: {user_data[joined]}
Last seen: {user_data[last_seen]}
Last played game: {user_data[last_game]}
Color: {user_data[color]}
Status: {user_data[status]}
Avatar: {user_data[avatar]}
```""".format(user_id=user_id, user_data=user_data, permissions_text=permissions_text)
    return to_return # Placeholder if this will be modified later
示例#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):
    """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