Exemplo n.º 1
0
Arquivo: web.py Projeto: skillor/Spark
async def rarity_image(
        module: 'InventoryModule',
        guild: discord.Guild,
        member: discord.Member,
        preview: Union[str, None] = Body(default=None, embed=True),
):
    rarity = {
        'id':
        '-1',
        'name':
        'Legendary',
        'foreground_color':
        make_linear_gradient('(255,255,255)'),
        'background_color':
        make_linear_gradient(
            'LinearGradientColor((241, 110, 24),(255, 222, 7),1)'),
    }

    if preview is None:
        img = await module.create_rarity_image(guild.id, rarity)
        return BytesFileResponse(img.fp,
                                 filename=img.filename,
                                 media_type='image/png')

    try:
        preview = module.bot.module_manager.settings.preview(
            guild.id, 'RARITY_IMAGE', preview)
    except:
        raise WrongInputException(detail='setting preview not correct')

    img = await module.create_rarity_image_by_template(rarity, preview)
    return BytesFileResponse(img.fp,
                             filename=img.filename,
                             media_type='image/png')
Exemplo n.º 2
0
async def get_store(module: 'StoreModule', guild: discord.Guild,
                    member: discord.Member):
    store = []
    for offer in module.bot.db.get_store(guild.id):
        from_foreground_color = make_linear_gradient(offer[2].foreground_color)
        from_background_color = make_linear_gradient(offer[2].background_color)
        to_foreground_color = make_linear_gradient(offer[4].foreground_color)
        to_background_color = make_linear_gradient(offer[4].background_color)
        store.append({
            'id':
            offer[0].id,
            'from_item_amount':
            offer[0].from_item_amount,
            'to_item_amount':
            offer[0].to_item_amount,
            'from_item_id':
            offer[1].id,
            'from_item_type':
            offer[1],
            'to_item_id':
            offer[3].id,
            'to_item_type':
            offer[3],
            'from_foreground_color_html':
            html_color(from_foreground_color[0], from_foreground_color[1]),
            'from_background_color_html':
            html_color(from_background_color[0], from_background_color[1]),
            'to_foreground_color_html':
            html_color(to_foreground_color[0], to_foreground_color[1]),
            'to_background_color_html':
            html_color(to_background_color[0], to_background_color[1]),
        })
    return {'msg': 'success', 'store': store}
Exemplo n.º 3
0
Arquivo: web.py Projeto: skillor/Spark
async def get_wheelspin(module: 'WheelspinModule', guild: discord.Guild,
                        member: discord.Member):
    wheelspin = []
    for x in module.bot.db.get_wheelspin(guild.id):
        foreground_color_id = 'fgcolor{}'.format(x.WheelspinProbability.id)
        foreground_color = make_linear_gradient(
            x.InventoryRarity.foreground_color)
        background_color_id = 'bgcolor{}'.format(x.WheelspinProbability.id)
        background_color = make_linear_gradient(
            x.InventoryRarity.background_color)
        wheelspin.append({
            'id':
            x.WheelspinProbability.id,
            'name':
            x.InventoryItemType.name,
            'foreground_color_id':
            foreground_color_id,
            'foreground_color_svg':
            svg_color_definition_with_id(foreground_color[0],
                                         foreground_color[1],
                                         foreground_color_id),
            'foreground_color_html':
            html_color(foreground_color[0], foreground_color[1]),
            'background_color_id':
            background_color_id,
            'background_color_svg':
            svg_color_definition_with_id(background_color[0],
                                         background_color[1],
                                         background_color_id),
            'background_color_html':
            html_color(background_color[0], background_color[1]),
            'sound':
            x.WheelspinProbability.sound
        })
    return {'msg': 'success', 'wheelspin': wheelspin}
Exemplo n.º 4
0
    async def edit_rarity(self, guild: discord.Guild, rarity):
        try:
            if len(rarity['name']) > 20:
                raise WrongInputException(
                    detail='name can only be 20 characters long')

            try:
                make_linear_gradient(rarity['foreground_color'])
                make_linear_gradient(rarity['background_color'])
            except:
                raise WrongInputException(detail='wrong format for color')
            self.bot.db.edit_rarity(guild.id,
                                    rarity['id'] if 'id' in rarity else None,
                                    rarity['name'], rarity['foreground_color'],
                                    rarity['background_color'])
        except KeyError:
            raise WrongInputException(detail='missing parameter')
Exemplo n.º 5
0
Arquivo: web.py Projeto: skillor/Spark
async def get_rarities(module: 'InventoryModule', guild: discord.Guild,
                       member: discord.Member):
    rarities = await module.get_rarities(guild)
    for key, rarity in rarities.items():
        rarities[key]['image'] = base64.b64encode(
            (await module.create_rarity_image(
                guild.id, {
                    'id':
                    rarity['id'],
                    'name':
                    rarity['name'],
                    'foreground_color':
                    make_linear_gradient(rarity['foreground_color']),
                    'background_color':
                    make_linear_gradient(rarity['background_color']),
                })).fp.read()).decode('utf-8')

    return {
        'msg': 'success',
        'rarities': rarities,
    }
Exemplo n.º 6
0
 async def get_inventory(self, member: discord.Member) -> Dict:
     return dict(
         map(
             lambda item: (item.UserInventoryItem.item_type_id, {
                 'item_name':
                 item.InventoryItemType.name,
                 'item_amount':
                 item.UserInventoryItem.amount,
                 'item_useable':
                 item.InventoryItemType.useable,
                 'item_equipped':
                 item.UserInventoryItem.equipped,
                 'item_equippable':
                 item.InventoryItemType.equippable,
                 'rarity_name':
                 item.InventoryRarity.name,
                 'rarity_foreground_color':
                 make_linear_gradient(item.InventoryRarity.foreground_color
                                      ),
                 'rarity_background_color':
                 make_linear_gradient(item.InventoryRarity.background_color)
             }), self.bot.db.get_user_items(member.guild.id, member.id)))