Пример #1
0
async def split_text_file(file_name):
    buffer_lines = f"{hbold(file_name)}:\n"
    rez = list()
    with open(file_name, 'r+') as in_file:

        for line in in_file:

            if len(line) > MAX_MESSAGE_SYMBOLS:
                rez.append(buffer_lines)
                buffer_lines = ""
                separated_text = [
                    hpre(line)
                    for line in textwrap.wrap(line, MAX_MESSAGE_SYMBOLS)
                ]
                rez.extend(separated_text)
            elif len(buffer_lines) + len(line) > MAX_MESSAGE_SYMBOLS:
                rez.append(buffer_lines)
                buffer_lines = ""
            else:
                line = hpre(line)
                buffer_lines += line
        if len(buffer_lines) > 0:
            rez.append(buffer_lines)
        in_file.truncate(0)
    return rez
Пример #2
0
async def variants_formatting(message: types.Message):
    await message.answer(hbold('hbold'))
    await message.answer(hcode('hcode'))
    await message.answer(hitalic('hitalic'))
    await message.answer(hunderline('hunderline'))
    await message.answer(hstrikethrough('hstrikethrough'))
    await message.answer(hpre('hpre'))
Пример #3
0
async def get_top_from_private(message: types.Message, user: User):
    parts = message.text.split(maxsplit=1)
    if len(parts) > 1:
        chat = await Chat.get(chat_id=int(parts[1]))
    else:
        return await message.reply(
            "Эту команду можно использовать только в группах "
            "или с указанием id нужного чата, например:"
            "\n" + hpre("!top -1001399056118"))
    logger.info("user {user} ask top karma of chat {chat}",
                user=user.tg_id,
                chat=chat.chat_id)
    text = await get_karma_top(chat, user)

    await message.reply(text, disable_web_page_preview=True)
Пример #4
0
async def send_welcome(message: types.Message):
    # Get data from context
    # All of that available only in current context and from current update object
    # `data`- pseudo-alias for `ctx.get_update().conf['_context_data']`
    command = data['command']
    args = data['args']
    rand = data['some_random_data']
    has_args = data['has_args']

    # Send as pre-formatted code block.
    await message.reply(md.hpre(f"""command: {command}
args: {['Not available', 'available'][has_args]}: {args}
some random data: {rand}
message ID: {message.message_id}
message: {message.html_text}
    """),
                        parse_mode=ParseMode.HTML)
Пример #5
0
async def send_most_active_users(chat_id, channel_name, date=None):
    try:
        most_active_users = db.view_most_active_user_for_channel(
            chat_id, channel_name, date)

        if most_active_users:
            msg = f'ТОП 10 пользователей на канале {channel_name} за {"все время" if not date else date} :\n'
            counter = 1
            for row in most_active_users:
                msg = msg + f'{counter:^2}: {row[0]:<20} {row[1]:>4} сообщений\n'
                counter = counter + 1
            await bot.send_message(chat_id,
                                   markdown.hpre(msg),
                                   parse_mode=ParseMode.HTML)
        else:
            await bot.send_message(
                chat_id, f'На канале {channel_name} еще нет сообщений')
    except DbExceptions.TgChatIsNotSubscribedToTwChannel:
        await bot.send_message(chat_id,
                               f'Вы уже не подписаны на канал {channel_name}')
Пример #6
0
    hcode,
    hitalic,
    hunderline,
    hstrikethrough,
    hlink,
    hpre,
)


html_text = "\n".join(
    [
        "Привет, " + hbold("Сирежа"),
        "Как говорится:",
        hitalic("Волков боятся - в лес не ходить!"),
        "",
        "но мы не боимся дать отпор! " + hstrikethrough("Что тебе нужно?"),
        "Все это чистая хтмлуйня! ",
        "Узнай про себя кое что новое " + hlink("тут", "http://ya.ru"),
        "и нимножко коды: "
        + hpre(
            "from aiogram.dispatcher.filters import Command;from loguru import logger;from src.loader import dp;from aiogram.utils.markdown import hbold, hcode",
            sep=";",
        ),
    ]
)


@dp.message_handler(Command("format"))
async def bot_echo(message: types.Message):
    await message.answer(html_text)