Example #1
0
async def set_url(message: types.Message, state: FSMContext):
    url_markup = types.InlineKeyboardMarkup()
    urls = re.findall(r'[^`*-]+ - https?://[^\s]+', message.text)
    for i in urls:
        button = types.InlineKeyboardButton(text=i.split(' - ')[0],
                                            url=i.split(' - ')[1])
        url_markup.add(button)

    async with state.proxy() as data:
        data['post']['urls'] = url_markup
        offset = data['offset']
        data['offset'] += 1
        text = get_text_with_img(data['post'])
        post_keyboard = edit_post_keyboard(data['post'])

    await message.delete()
    await States.TASK_SETTINGS.set()

    try:
        await bot.edit_message_text(text=text,
                                    chat_id=message.chat.id,
                                    message_id=message.message_id -
                                    (1 + offset),
                                    reply_markup=post_keyboard)
    except ButtonURLInvalid:
        data['post']['urls'] = ''
        post_keyboard = edit_post_keyboard(data['post'])
        await bot.edit_message_text(text=text,
                                    chat_id=message.chat.id,
                                    message_id=message.message_id -
                                    (1 + offset),
                                    reply_markup=post_keyboard)
Example #2
0
async def set_delay(message: types.Message, state: FSMContext):
    try:
        time_start = datetime.datetime.strptime(message.text, '%H:%M %d.%m.%y')
    except ValueError:
        return await error_delay(message, state)

    now_today = datetime.datetime.utcnow() + datetime.timedelta(hours=3)
    if time_start < now_today:
        return await error_delay(message, state)
    elif time_start - now_today < datetime.timedelta(minutes=10):
        return await error_delay(message, state)

    async with state.proxy() as data:
        data['post']['time_start'] = time_start
        data['post']['flag'] = 'delay'
        offset = data['offset']
        data['offset'] += 1
        header = get_header(data['post'])
        header_keyboard = edit_header_keyboard(data['post'])
        text = get_text_with_img(data['post'])
        post_keyboard = edit_post_keyboard(data['post'])

    await message.delete()
    await States.TASK_SETTINGS.set()

    await bot.edit_message_text(text=header,
                                chat_id=message.chat.id,
                                message_id=message.message_id - (2 + offset),
                                reply_markup=header_keyboard)
    await bot.edit_message_text(text=text,
                                chat_id=message.chat.id,
                                message_id=message.message_id - (1 + offset),
                                reply_markup=post_keyboard)
Example #3
0
async def del_url(callback: types.CallbackQuery, state: FSMContext):
    async with state.proxy() as data:
        data['post']['urls'] = ''
        text = get_text_with_img(data['post'])
        post_keyboard = edit_post_keyboard(data['post'])

    await callback.message.edit_text(text, reply_markup=post_keyboard)
Example #4
0
async def set_interval(message: types.Message, state: FSMContext):
    interval = int(re.search(r'\d{2,4}', message.text).group())
    if 9 < interval < 1441:
        async with state.proxy() as data:
            data['post']['interval'] = interval
            offset = data['offset']
            data['offset'] += 1
            text = get_text_with_img(data['post'])
            header = get_header(data['post'])
            post_keyboard = edit_post_keyboard(data['post'])
            header_keyboard = edit_header_keyboard(data['post'])

        await message.delete()
        await States.TASK_SETTINGS.set()
        await bot.edit_message_text(text=header,
                                    chat_id=message.chat.id,
                                    message_id=message.message_id -
                                    (2 + offset),
                                    reply_markup=header_keyboard)
        try:
            await bot.edit_message_text(text=text,
                                        chat_id=message.chat.id,
                                        message_id=message.message_id -
                                        (1 + offset),
                                        reply_markup=post_keyboard)
        except MessageNotModified:
            return
    else:
        await error_interval(message, state)
Example #5
0
async def set_channels(message: types.Message, state: FSMContext):
    channels = []
    channels.extend(list(set(re.findall(r'@\w{5,}\b', message.text))))
    channels.extend(list(set(re.findall(r't.me/\w{5,}\b', message.text))))
    if channels:
        async with state.proxy() as data:
            offset = data['offset']
            data['offset'] += 1
            data['post']['channels'] = channels
            text = get_text_with_img(data['post'])
            header = get_header(data['post'])
            post_keyboard = edit_post_keyboard(data['post'])
            header_keyboard = edit_header_keyboard(data['post'])

        await message.delete()
        await States.TASK_SETTINGS.set()
        await bot.edit_message_text(text=header,
                                    chat_id=message.chat.id,
                                    message_id=message.message_id -
                                    (2 + offset),
                                    reply_markup=header_keyboard)
        try:
            await bot.edit_message_text(text=text,
                                        chat_id=message.chat.id,
                                        message_id=message.message_id -
                                        (1 + offset),
                                        reply_markup=post_keyboard)
        except MessageNotModified:
            return
    else:
        await error_channel(message, state)
Example #6
0
async def edited_content(message: types.Message, state: FSMContext):
    async with state.proxy() as data:
        data['post']['text'] = message.text
        text = get_text_with_img(data['post'])
        post_keyboard = edit_post_keyboard(data['post'])

    await bot.edit_message_text(text=text,
                                chat_id=message.chat.id,
                                message_id=message.message_id + 2,
                                reply_markup=post_keyboard)
Example #7
0
async def del_delay(callback: types.CallbackQuery, state: FSMContext):
    async with state.proxy() as data:
        data['post']['time_start'] = None
        data['post']['flag'] = ''
        header = get_header(data['post'])
        header_keyboard = edit_header_keyboard(data['post'])
        text = get_text_with_img(data['post'])
        post_keyboard = edit_post_keyboard(data['post'])

    await bot.edit_message_text(text=header,
                                chat_id=callback.message.chat.id,
                                message_id=callback.message.message_id - 1,
                                reply_markup=header_keyboard)
    await bot.edit_message_text(text=text,
                                chat_id=callback.message.chat.id,
                                message_id=callback.message.message_id,
                                reply_markup=post_keyboard)
Example #8
0
async def set_image(message: types.Message, state: FSMContext):
    tg_url = await message.photo[-1].get_url()
    img_url = get_img_url(tg_url)
    async with state.proxy() as data:
        data['post'][
            'img'] = f'<a href="{img_url}">&#8205;</a>'  # f'[⁠]({img_url})'
        offset = data['offset']
        data['offset'] += 1
        text = get_text_with_img(data['post'])
        post_keyboard = edit_post_keyboard(data['post'])

    await message.delete()
    await States.TASK_SETTINGS.set()
    await bot.edit_message_text(text=text,
                                chat_id=message.chat.id,
                                message_id=message.message_id - (1 + offset),
                                reply_markup=post_keyboard)
Example #9
0
async def create_content(message: types.Message, state: FSMContext):
    text = message.text
    async with state.proxy() as data:
        data['post']['text'] = text
        header = get_header(data['post'])
        header_keyboard = edit_header_keyboard((data['post']))
        post_keyboard = edit_post_keyboard(data['post'])

    await States.TASK_SETTINGS.set()
    await bot.delete_message(chat_id=message.chat.id,
                             message_id=message.message_id - 4)
    await bot.delete_message(chat_id=message.chat.id,
                             message_id=message.message_id - 3)
    await bot.delete_message(chat_id=message.chat.id,
                             message_id=message.message_id - 2)
    await bot.delete_message(chat_id=message.chat.id,
                             message_id=message.message_id - 1)
    await message.answer(text=header, reply_markup=header_keyboard)
    await message.answer(text=text, reply_markup=post_keyboard)