Example #1
0
async def update_color(server_id, user_id):
    """Refreshes the color role so that it is on top."""
    if not botmanager.has_role_permissions(server_id):
        raise bot_exception(EXCEPT_TYPE, "Bot must be able to manage permissions in order to change role colors.")
    color = servermanager.servers_data[server_id]['users'][user_id]['color']
    if color:
        converted = int(color[1:], 16)
        await botmanager.update_color_role(server_id, user_id, converted)
    else:
        raise bot_exception(EXCEPT_TYPE, "You currently don't have a custom color!")
    return "Color successfully refreshed!"
Example #2
0
async def set_color(server_id, user_id, color):
    """Gives the user the given color as a role."""
    if not botmanager.has_role_permissions(server_id): # Check bot permissions first
        raise bot_exception(EXCEPT_TYPE, "Bot must be able to manage permissions in order to change role colors.")
    if color is None:
        servermanager.servers_data[server_id]['users'][user_id]['color'] = ''
        write_data()
        await botmanager.update_color_role(server_id, user_id, None)
        return "Color successfully cleared!"
    if color.startswith('#'): # Just in case people just copy values over
        color = color[1:]
    try: # Make sure we're given a valid hex value here
        converted = int(color, 16)
    except ValueError:
        raise bot_exception(EXCEPT_TYPE, "'{}' does not appear to be a valid hex color.".format(color))
    await botmanager.update_color_role(server_id, user_id, converted)
    servermanager.servers_data[server_id]['users'][user_id]['color'] = '#{}'.format(color.upper())
    write_data()    
    return "Color successfully set!"