Exemple #1
0
    async def edit_item_type(self, guild: discord.Guild, item_type):
        try:
            actions = self.bot.module_manager.hooks.get(
                guild.id, INVENTORY_ITEM_ACTION_HOOK)
            item_actions = []
            for item_action in item_type['actions']:
                if item_action['action'] not in actions:
                    raise WrongInputException(detail='action "{}" not found'.
                                              format(item_type['action']))

                item_actions.append({
                    'action': item_action['action'],
                    'action_options': {
                        k: item_action['action_options'][k]['value']
                        for k, v in actions[item_action['action']]
                        ['options'].items()
                    }
                })

            self.bot.db.edit_inventory_item_type(
                guild.id, item_type['id'] if 'id' in item_type else None,
                item_type['name'], item_type['rarity_id'],
                item_type['always_visible'], item_type['tradable'],
                item_type['equippable'], item_type['useable'],
                json.dumps(item_actions))
        except KeyError:
            raise WrongInputException(detail='missing parameter')
Exemple #2
0
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')
Exemple #3
0
async def set_setting(
        module: 'GeneralModule',
        guild: discord.Guild,
        member: discord.Member,
        key: str = Body(embed=True),
        value: Any = Body(embed=True),
):
    if key not in module.bot.module_manager.settings.keys(guild.id):
        raise WrongInputException(detail='setting key not correct')
    if not module.bot.module_manager.settings.set(guild.id, key, value):
        raise WrongInputException(detail='setting value not correct')

    return {
        'msg': 'success',
        'value': module.bot.module_manager.settings.get(guild.id, key)
    }
Exemple #4
0
async def welcome_image(
        module: 'GeneralModule',
        guild: discord.Guild,
        member: discord.Member,
        preview: Union[str, None] = Body(default=None, embed=True),
):
    if preview is None:
        img = await module.member_create_welcome_image(member)
        return BytesFileResponse(
            img.fp,
            filename=img.filename,
            media_type='image/png',
        )

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

    img = await module.member_create_welcome_image_by_template(member, preview)
    return BytesFileResponse(
        img.fp,
        filename=img.filename,
        media_type='image/png',
    )
Exemple #5
0
async def rank_up_image(
        module: 'LevelsystemModule',
        guild: discord.Guild,
        member: discord.Member,
        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')
Exemple #6
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')
Exemple #7
0
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'}
Exemple #8
0
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'}
Exemple #9
0
async def get_messages(
    module: 'GeneralModule',
    guild: discord.Guild,
    member: discord.Member,
    channel_id: str,
    limit: int = 100,
):
    channel = search_text_channel(guild, channel_id)
    if channel is None:
        raise WrongInputException(detail='channel not found')

    return {
        'messages':
        asyncio.run_coroutine_threadsafe(
            channel.history(limit=limit).flatten(),
            module.bot.bot.loop).result()
    }
Exemple #10
0
async def send_msg_channel(
        module: 'GeneralModule',
        guild: discord.Guild,
        member: discord.Member,
        channel_id: str = Body(embed=True),
        message: str = Body(embed=True),
):
    channel = search_text_channel(guild, str(channel_id))
    if channel is None:
        raise WrongInputException(detail='channel not found')

    asyncio.run_coroutine_threadsafe(channel.send(str(message)),
                                     module.bot.bot.loop).result()

    return {
        'msg': 'success',
    }
Exemple #11
0
async def send_voice_audio(
        module: 'GeneralModule',
        guild: discord.Guild,
        member: discord.Member,
        audio_file: UploadFile = File(),
        voice_channel: str = Form(),
):
    if not AUDIO_IMPORTED:
        raise WrongInputException(detail='audio not supported')

    stream = BytesIO()
    sound = AudioSegment.from_file(audio_file.file)
    sound.export(stream, format='wav')
    await module.bot.play_audio(PCMAudio(stream),
                                search_voice_channel(guild, voice_channel))

    return {
        'msg': 'success',
    }
Exemple #12
0
async def ranking_image(
        module: 'LevelsystemModule',
        guild: discord.Guild,
        member: discord.Member,
        preview: Union[str, None] = Body(default=None, embed=True),
):
    if preview is None:
        img = await module.create_leaderboard_image(member)
        return BytesFileResponse(img.fp,
                                 filename=img.filename,
                                 media_type='image/png')

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

    img = await module.create_leaderboard_image_by_template(member, preview)
    return BytesFileResponse(img.fp,
                             filename=img.filename,
                             media_type='image/png')
Exemple #13
0
async def inventory_image(
        module: 'InventoryModule',
        guild: discord.Guild,
        member: discord.Member,
        preview: Union[str, None] = Body(default=None, embed=True),
):
    inventory = await module.get_inventory(member)

    if preview is None:
        img = await module.create_inventory_image(guild.id, inventory)
        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_inventory_image_by_template(inventory, preview)
    return BytesFileResponse(img.fp,
                             filename=img.filename,
                             media_type='image/png')
Exemple #14
0
async def change_emoji(
        module: 'GeneralModule',
        guild: discord.Guild,
        member: discord.Member,
        emoji_file: UploadFile = File(),
        emoji: str = Form(),
):
    if not is_emoji(emoji):
        raise WrongInputException(detail='emoji is wrong')

    if not module.bot.image_creator.emoji_loader.save_downloaded_emojis:
        raise MethodNotAvailableException(detail='cannot save emojis')

    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',
    }