コード例 #1
0
ファイル: base.py プロジェクト: alekssamos/KarmaBot
async def cmd_about(message: types.Message):
    logger.info("User {user} about", user=message.from_user.id)
    msg = await message.reply(
        'Форк карма бота. Исходники по ссылке https://github.com/alekssamos/KarmaBot\n'
        'Считает рейтинг ровно по единице, а не в зависимости от силы.')
    if message.chat.type != "PRIVATE":
        asyncio.create_task(
            delete_message(msg, config.TIME_TO_REMOVE_TEMP_MESSAGES))
        asyncio.create_task(
            delete_message(message, config.TIME_TO_REMOVE_TEMP_MESSAGES))
コード例 #2
0
ファイル: karma.py プロジェクト: alekssamos/KarmaBot
async def get_top(message: types.Message, chat: Chat, user: User):
    logger.info("user {user} ask his karma in chat {chat}",
                user=user.tg_id,
                chat=chat.chat_id)
    uk, number_in_top = await get_me_chat_info(chat=chat, user=user)
    msg = await message.reply(
        f"Ваш рейтинг в данном чате: <b>{uk.karma}</b> ({number_in_top})",
        disable_web_page_preview=True)
    asyncio.create_task(
        delete_message(msg, config.TIME_TO_REMOVE_TEMP_MESSAGES))
    asyncio.create_task(
        delete_message(message, config.TIME_TO_REMOVE_TEMP_MESSAGES))
コード例 #3
0
ファイル: base.py プロジェクト: alekssamos/KarmaBot
async def get_idchat(message: types.Message):
    text = (f"id этого чата: {hpre(message.chat.id)}\n"
            f"Ваш id: {hpre(message.from_user.id)}")
    if message.reply_to_message:
        text += (
            f"\nid {hbold(message.reply_to_message.from_user.full_name)}: "
            f"{hpre(message.reply_to_message.from_user.id)}")
    msg = await message.reply(text, disable_notification=True)
    if message.chat.type != "PRIVATE":
        asyncio.create_task(
            delete_message(msg, config.TIME_TO_REMOVE_TEMP_MESSAGES))
        asyncio.create_task(
            delete_message(message, config.TIME_TO_REMOVE_TEMP_MESSAGES))
コード例 #4
0
async def get_top(message: types.Message, chat: Chat, user: User,
                  config: Config):
    logger.info("user {user} ask his karma in chat {chat}",
                user=user.tg_id,
                chat=chat.chat_id)
    uk, number_in_top = await get_me_chat_info(chat=chat, user=user)
    msg = await message.reply(
        f"Ваша карма в данном чате: <b>{uk.karma:.2f}</b> ({number_in_top})",
        disable_web_page_preview=True)
    asyncio.create_task(
        delete_message(msg, config.time_to_remove_temp_messages))
    asyncio.create_task(
        delete_message(message, config.time_to_remove_temp_messages))
コード例 #5
0
ファイル: karma.py プロジェクト: alekssamos/KarmaBot
async def get_top(message: types.Message, chat: Chat, user: User):
    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)

    msg = await message.reply(text, disable_web_page_preview=True)
    asyncio.create_task(
        delete_message(msg, config.TIME_TO_REMOVE_TEMP_MESSAGES))
コード例 #6
0
ファイル: base.py プロジェクト: alekssamos/KarmaBot
async def cmd_help(message: types.Message):
    logger.info("User {user} read help in {chat}",
                user=message.from_user.id,
                chat=message.chat.id)
    msg = await message.reply((
        'Прибавить рейтинг можно начав сообщение с: "{plus}". \n'
        'Минусануть - написав первой строкой что-то из "{minus}".\n'
        'Чтобы выбрать пользователя - нужно ответить реплаем на сообщение пользователя '
        'или упомянуть его через @ (работает даже если у пользователя нет username).\n'
        'Увеличение и уменьшение идёт всегда ровно на одну единицу за раз\n'
        '<code>!top</code> [chat_id] - лучшие пользователи по рейтингу для текущего чата или для чата с chat_id \n'
        '<code>!about</code> - информация о боте и его исходники\n'
        '<code>!me</code> - посмотреть свою карму (желательно это делать в личных сообщениях с ботом)\n'
        # '<code>!report</code> {{реплаем}} - пожаловаться на сообщение модераторам\n'
        '<code>!idchat</code> - показать Ваш id, id чата и, '
        'если имеется, - id пользователя, которому Вы ответили командой'
    ).format(plus='", "'.join([*PLUS_TRIGGERS, *PLUS_EMOJI]),
             minus='", "'.join([*MINUS_TRIGGERS, *MINUS_EMOJI])))
    if message.chat.type != "PRIVATE":
        asyncio.create_task(
            delete_message(msg, config.TIME_TO_REMOVE_TEMP_MESSAGES))
        asyncio.create_task(
            delete_message(message, config.TIME_TO_REMOVE_TEMP_MESSAGES))
コード例 #7
0
ファイル: change_karma.py プロジェクト: alekssamos/KarmaBot
async def karma_change(message: types.Message, karma: dict, user: User, chat: Chat, target: User):

    try:
        result_change_karma = await change_karma(
            target_user=target,
            chat=chat,
            user=user,
            how_change=karma['karma_change'],
            comment=karma['comment'],
            bot=message.bot,
        )
    except SubZeroKarma:
        return await message.reply("У Вас слишком мало кармы для этого")
    except DontOffendRestricted:
        return await message.reply("Не обижай его, он и так наказан!")
    except CantChangeKarma as e:
        logger.info("user {user} can't change karma, {e}", user=user.tg_id, e=e)
        return
    if result_change_karma.count_auto_restrict:
        notify_auto_restrict_text = await render_text_auto_restrict(result_change_karma.count_auto_restrict, target)
    else:
        notify_auto_restrict_text = ""

    # How match karma was changed. Sign show changed difference, not difference for cancel
    how_changed_karma = result_change_karma.user_karma.karma \
        - result_change_karma.karma_after \
        + result_change_karma.abs_change

    msg = await message.reply(
        "Вы {how_change} рейтинг <b>{name}</b> до <b>{karma_new}</b> ({power})"
        "\n\n{notify_auto_restrict_text}".format(
            how_change=get_how_change_text(karma['karma_change']),
            name=quote_html(target.fullname),
            karma_new=result_change_karma.karma_after,
            power=result_change_karma.abs_change,
            notify_auto_restrict_text=notify_auto_restrict_text
        ),
        disable_web_page_preview=True,
        reply_markup=kb.get_kb_karma_cancel(
            user=user,
            karma_event=result_change_karma.karma_event,
            rollback_karma=-how_changed_karma,
            moderator_event=result_change_karma.moderator_event,
        )
    )
    asyncio.create_task(remove_kb(msg, config.TIME_TO_CANCEL_ACTIONS))
    asyncio.create_task(delete_message(msg, config.TIME_TO_REMOVE_TEMP_MESSAGES))