Example #1
0
async def _gen_order_caption(ether: Ether, user: types.User,
                             audio_name: str = None, status: kb.STATUS = None, moder: types.User = None) -> str:
    is_now = ether.is_now()
    user_name = utils.get_user_name(user) + ' #' + id_to_hashtag(user.id)
    text_datetime = ether.name + (' (сейчас!)' if is_now else '')

    if not status:  # Неотмодеренный заказ
        assert audio_name is not None
        is_now_mark = '‼️' if is_now else '❗️'
        bad_words = await _get_bad_words_text(audio_name)
        is_anime = '🅰️' if await music.check.is_anime(audio_name) else ''

        return f'{is_now_mark} Новый заказ: \n' \
               f'{text_datetime} \n' \
               f'от {user_name}<code>   </code>{texts.HASHTAG_MODERATE}\n' \
               f'{is_anime}{bad_words}'
    else:
        assert moder is not None
        status_text = "✅Принят" if status != kb.STATUS.REJECT else "❌Отклонен"
        moder_name = utils.get_user_name(moder)

        return f'Заказ: \n' \
               f'{text_datetime}\n' \
               f'от {user_name}\n' \
               f'{status_text} ({moder_name})'
Example #2
0
async def admin_moderate(query: types.CallbackQuery, ether: Ether, status: kb.STATUS):
    user = utils.get_user_from_entity(query.message)
    moder = query.from_user
    admin_text = await _gen_order_caption(ether, user, status=status, moder=moder)
    track = PlaylistItem.from_tg(query.message.audio).add_track_info(user.id, user.first_name, query.message.message_id)

    try:
        await query.message.edit_caption(admin_text, reply_markup=kb.admin_unmoderate(ether, status))
    except exceptions.MessageNotModified:
        return  # если не отредачилось значит кнопка уже отработалась

    stats.add(query.message.message_id, moder.id, user.id, str(track), status, DateTime.now())

    if status == kb.STATUS.REJECT:  # кнопка отмена
        return communication.cache_add(
            await BOT.send_message(user.id, texts.ORDER_DENIED.format(track, ether.name)), query.message)

    await query.message.chat.do('record_audio')
    msg_to_user: Optional[str]
    try:
        if status != kb.STATUS.NOW:
            await _can_approve_order(ether, query.message.audio)
        ether_ = None if status == kb.STATUS.NOW else ether
        new_track = await Broadcast(ether_).add_track(track, audio=query.message.audio)

    except DuplicateException:
        when_playing = 'Такой же трек уже принят на этот эфир'
        msg_to_user = texts.ORDER_ACCEPTED.format(track, ether.name)
    except NotEnoughSpaceException:
        when_playing = 'не успел :('
        msg_to_user = None
        communication.cache_add(await BOT.send_audio(
            user.id, query.message.audio.file_id, reply_markup=await kb.order_choose_day(),
            caption=texts.ORDER_ACCEPTED_TOOLATE.format(track, ether.name)), query.message
        )
    else:
        if status == kb.STATUS.NOW:
            when_playing = 'прямо сейчас!'
            msg_to_user = texts.ORDER_ACCEPTED_UPNEXT.format(track, when_playing)
        elif ether.is_now():
            minutes_left = round((new_track.start_time - DateTime.now()).seconds / 60)
            when_playing = f'через {minutes_left} ' + utils.case_by_num(minutes_left, 'минуту', 'минуты', 'минут')
            msg_to_user = texts.ORDER_ACCEPTED_UPNEXT.format(track, when_playing)
        else:
            when_playing = 'Заиграет когда надо'
            msg_to_user = texts.ORDER_ACCEPTED.format(track, ether.name)

    if msg_to_user:
        communication.cache_add(await BOT.send_message(user.id, msg_to_user), query.message)
    with suppress(exceptions.MessageNotModified):
        await query.message.edit_caption(admin_text + '\n🕑 ' + when_playing, reply_markup=kb.admin_unmoderate(ether, status))