Пример #1
0

async def use_item(
        module: 'InventoryModule',
        guild: discord.Guild,
        member: discord.Member,
        item_type_id: int = Body(embed=True),
        amount: float = Body(embed=True),
):
    await module.use_item(member, int(item_type_id), float(amount))
    return {
        'msg': 'success',
    }


API_PAGES = [
    Page(path='inventory', view_func=get_inventory),
    Page(path='use-item', view_func=use_item, methods=['POST']),
    Page(path='edit-rarity', view_func=edit_rarity, methods=['POST']),
    Page(path='remove-rarity', view_func=remove_rarity, methods=['POST']),
    Page(path='set-rarity-order', view_func=set_rarity_order,
         methods=['POST']),
    Page(path='rarities', view_func=get_rarities),
    Page(path='rarity-image', view_func=rarity_image, methods=['POST']),
    Page(path='inventory-image', view_func=inventory_image, methods=['POST']),
    Page(path='item-action-options', view_func=get_item_action_options),
    Page(path='item-types', view_func=get_item_types),
    Page(path='edit-item-type', view_func=edit_item_type, methods=['POST']),
    Page(path='remove-item-type', view_func=remove_item_type, methods=['POST'])
]
Пример #2
0
            html_color(to_background_color[0], to_background_color[1]),
        })
    return {'msg': 'success', 'store': store}


async def buy_offer(
        module: 'StoreModule',
        guild: discord.Guild,
        member: discord.Member,
        offer_id: int = Body(embed=True),
        amount: float = Body(embed=True),
):
    await module.buy_offer(member, int(offer_id), float(amount))
    return {'msg': 'success'}


@has_permissions(administrator=True)
async def set_store(module: 'StoreModule',
                    guild: discord.Guild,
                    member: discord.Member,
                    store: Any = Body(embed=True)):
    module.bot.db.set_store(guild.id, store)
    return {'msg': 'success'}


API_PAGES = [
    Page(path='set-store', view_func=set_store, methods=['POST']),
    Page(path='get-store', view_func=get_store),
    Page(path='buy-offer', view_func=buy_offer, methods=['POST']),
]
Пример #3
0
    emoji_id = from_char(emoji)
    module.bot.image_creator.emoji_loader.cached_images.clear()
    with open(
            os.path.join(module.bot.image_creator.emoji_loader.emoji_path,
                         emoji_id + '.png'), 'wb') as f:
        f.write(emoji_file.file.read())
    module.bot.logger.info('saved new image for emoji {}'.format(emoji_id))

    return {
        'msg': 'success',
    }


API_PAGES = [
    Page(path='profile', view_func=get_profile),
    Page(path='settings', view_func=get_settings),
    Page(path='reset-setting', view_func=reset_setting, methods=['POST']),
    Page(path='set-setting', view_func=set_setting, methods=['POST']),
    Page(path='modules', view_func=get_modules),
    Page(path='set-module', view_func=set_module, methods=['POST']),
    Page(path='welcome-image', view_func=welcome_image, methods=['POST']),
    Page(path='invite-links', view_func=get_invite_links),
    Page(path='invite-link', view_func=invite_link, methods=['POST']),
    Page(path='text-channels', view_func=text_channels),
    Page(path='voice-channels', view_func=voice_channels),
    Page(path='send-message', view_func=send_msg_channel, methods=['POST']),
    Page(path='messages', view_func=get_messages),
    Page(path='nickname', view_func=set_nickname, methods=['POST']),
    Page(path='audio', view_func=send_voice_audio, methods=['POST']),
    Page(path='presence', view_func=set_presence, methods=['POST']),
Пример #4
0
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from . import PromoModule


async def get_promo_code(module: 'PromoModule', guild: discord.Guild,
                         member: discord.Member):
    return {'promo_code': await module.create_promo_code(member)}


async def redeem_promo_code(
        module: 'PromoModule',
        guild: discord.Guild,
        member: discord.Member,
        promo_code: str = Body(embed=True),
):
    if not await module.can_redeem_promo_code(member):
        raise WrongInputException(detail='promo code usage forbidden')
    asyncio.run_coroutine_threadsafe(
        module.redeem_promo_code(member, promo_code, time.time()),
        module.bot.bot.loop).result()
    return {'msg': 'success'}


API_PAGES = [
    Page(path='promo', view_func=get_promo_code, methods=['GET']),
    Page(path='redeem', view_func=redeem_promo_code, methods=['POST']),
]
Пример #5
0
@has_permissions(administrator=True)
async def get_wheelspin_admin(module: 'WheelspinModule', guild: discord.Guild,
                              member: discord.Member):
    return {
        'msg':
        'success',
        'wheelspin':
        list(
            map(lambda x: x.WheelspinProbability,
                module.bot.db.get_wheelspin(guild.id)))
    }


@has_permissions(administrator=True)
async def set_wheelspin(module: 'WheelspinModule',
                        guild: discord.Guild,
                        member: discord.Member,
                        wheelspin: Any = Body(embed=True)):
    await module.set_wheelspin(guild, wheelspin)
    return {'msg': 'success'}


API_PAGES = [
    Page(path='get-wheelspin', view_func=get_wheelspin),
    Page(path='spin-wheel', view_func=spin_wheel, methods=['POST']),
    Page(path='can-wheelspin', view_func=can_wheelspin),
    Page(path='get-wheelspin-admin', view_func=get_wheelspin_admin),
    Page(path='set-wheelspin', view_func=set_wheelspin, methods=['POST']),
]
Пример #6
0
    from . import ProfileModule


async def profile_image(
        module: 'ProfileModule',
        guild: discord.Guild,
        member: discord.Member,
        preview: Union[str, None] = Body(default=None, embed=True),
):
    if preview is None:
        img = await module.member_create_profile_image(member)
        return BytesFileResponse(img.fp,
                                 filename=img.filename,
                                 media_type='image/png')

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

    img = await module.member_create_profile_image_by_template(member, preview)
    return BytesFileResponse(img.fp,
                             filename=img.filename,
                             media_type='image/png')


API_PAGES = [
    Page(path='profile-image', view_func=profile_image, methods=['POST']),
]
Пример #7
0
        preview: Union[str, None] = Body(default=None, embed=True),
):
    role1 = RoleDummy()
    role2 = RoleDummy(color=(255, 0, 0))
    if preview is None:
        img = await module.member_create_rank_up_image(member, 42, 69, role1,
                                                       role2)
        return BytesFileResponse(img.fp,
                                 filename=img.filename,
                                 media_type='image/png')

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

    img = await module.member_create_rank_up_image_by_template(
        member, 42, 69, role1, role2, preview)
    return BytesFileResponse(img.fp,
                             filename=img.filename,
                             media_type='image/png')


API_PAGES = [
    Page(path='ranking', view_func=get_ranking, methods=['GET']),
    Page(path='ranking-image', view_func=ranking_image, methods=['POST']),
    Page(path='level-up-image', view_func=level_up_image, methods=['POST']),
    Page(path='rank-up-image', view_func=rank_up_image, methods=['POST']),
]
Пример #8
0
import discord
from fastapi import Body

from helpers.exceptions import WrongInputException
from helpers.tools import search_member
from webserver import Page

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from . import BoostModule


async def boost_user(module: 'BoostModule',
                     guild: discord.Guild,
                     member: discord.Member,
                     username: str = Body(embed=True)):
    boost_member = search_member(guild, username)
    if boost_member is None:
        raise WrongInputException(detail='user not found')

    await module.boost_user(member, boost_member)
    return {'msg': 'success'}


API_PAGES = [
    Page(path='boost', view_func=boost_user, methods=['POST']),
]