Example #1
0
async def order_choose_day() -> InlineKeyboardMarkup:
    today = DateTime.day_num()
    btns = []

    if (ether_now := Ether.now()) and await Broadcast(ether_now).get_free_time(
    ) > 3 * 60:  # кнопка сейчас если эфир+влазит
        btns.append(_ikb(NEXT_DAYS[-1], cb.CBOrderTime(today, ether_now.num)))
Example #2
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 #3
0
def playlist_choose_time(day: int) -> InlineKeyboardMarkup:
    btns = [
        _ikb(ETHER_NAMES[time], cb.CBPlaylistTime(day, time))
        for time in ETHER_TIMES[day]
        if not Ether(day, time).is_already_play_today()
    ] + [_ikb(btns_text.BACK, cb.CBPlaylistBack())]
    return InlineKeyboardMarkup(row_width=3).add(*btns)
Example #4
0
def playlist_choose_day() -> InlineKeyboardMarkup:
    day_start = Ether.get_closest().day
    btns = []
    for day in range(4):
        day = (day + day_start) % 7
        btns.append(_ikb(WEEK_DAYS[day], cb.CBPlaylistDay(day)))
    return InlineKeyboardMarkup(row_width=4).add(*btns)
Example #5
0
async def order_choose_time(day: int,
                            attempts: int = 5) -> InlineKeyboardMarkup:
    btns = []
    for num in ETHER_TIMES[day]:
        ether = Ether(day, num)
        if ether.is_already_play_today():
            continue  # если сегодня и перерыв прошел - не добавляем кнопку

        free_minutes = await Broadcast(ether).get_free_time()

        if free_minutes < 60 and attempts > 0:
            btn = _ikb('❌' + ETHER_NAMES[num], cb.CBOrderNoTime(day, attempts))
        else:
            btn = _ikb(
                ('⚠' if free_minutes < 5 * 60 else '') + ETHER_NAMES[num],
                cb.CBOrderTime(day, num))

        btns.append(btn)

    btns.append(_ikb(btns_text.BACK, cb.CBOrderBack()))
    return InlineKeyboardMarkup(row_width=2).add(*btns)
Example #6
0
async def playlist_now(message: types.Message):
    ether = Ether.now()
    if not ether:
        print(Ether.ALL)
        return await message.answer(texts.PLAYLIST_NOW_NOTHING,
                                    reply_markup=kb.WHAT_PLAYING)

    playback = [
        str(i) if i else r'¯\_(ツ)_/¯'
        for i in await Broadcast(ether).get_playback()
    ]
    await message.answer(texts.PLAYLIST_NOW.format(*playback),
                         reply_markup=kb.WHAT_PLAYING)
Example #7
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))
Example #8
0
async def timetable(message: types.Message):
    text = ''
    for day_num, day_name in {0: 'Будни', 6: 'Воскресенье'}.items():
        text += f"{day_name} \n"
        for break_num, (start, stop) in others.ETHER_TIMES[day_num].items():
            text += f"   {start} - {stop}   {others.ETHER_NAMES[break_num]}\n"

    br = Ether.get_closest()
    if br.is_now():
        text += "\nЭфир прямо сейчас!"
    else:
        text += f"\nБлижайший эфир - {'сегодня' if br.is_today() else others.WEEK_DAYS[br.day]}," \
                f" {br.start_time.strftime('%H:%M')}"

    await message.answer(text)
Example #9
0
 async def query_handler_playlist_time(query: types.CallbackQuery,
                                       cb: kb.cb.CBPlaylistTime):
     await handlers_.users.playlist_show(query, Ether(cb.day, cb.time))
Example #10
0
 async def query_handler_order_unmoderate(query: types.CallbackQuery,
                                          cb: kb.cb.CBOrderUnModerate):
     await handlers_.order.admin_unmoderate(query, Ether(cb.day, cb.time),
                                            kb.STATUS(cb.status))
Example #11
0
 async def query_handler_order_time(query: types.CallbackQuery,
                                    cb: kb.cb.CBOrderTime):
     await handlers_.order.order_make(query, Ether(cb.day, cb.time))
Example #12
0
async def orders_queue_empty():
    await Broadcast(Ether.now()).play()
Example #13
0
async def ether_begin(day, time):
    from bot.handlers_ import utils
    broadcast = Broadcast(Ether(day, time))
    await broadcast.play()
    await utils.send_ether_begin(time)
    await broadcast.player.set_volume(100)  # включить музло на перерыве
Example #14
0
async def track_begin(track: PlaylistItem):
    if not (ether := Ether.now()):
        return
Example #15
0
async def next_track(message: types.Message):
    await Broadcast.player.next_track()
    await asyncio.sleep(0.2)
    prev, now, _ = await Broadcast(Ether.now()).get_playback()
    await message.answer(f'<i>{prev} ➡ {now}</i>')
Example #16
0
BAD_ORDER_BUT_OK = InlineKeyboardMarkup(row_width=1).add(
    _ikb(btns_text.BAD_ORDER_BUT_OK, cb.CBOrderBack()),
    _ikb(btns_text.CANCEL, cb.CBOrderCancel()))


#
async def order_choose_day() -> InlineKeyboardMarkup:
    today = DateTime.day_num()
    btns = []

    if (ether_now := Ether.now()) and await Broadcast(ether_now).get_free_time(
    ) > 3 * 60:  # кнопка сейчас если эфир+влазит
        btns.append(_ikb(NEXT_DAYS[-1], cb.CBOrderTime(today, ether_now.num)))

    if Ether.get_closest().is_today():  # кнопка сегодня
        btns.append(_ikb(NEXT_DAYS[0], cb.CBOrderDay(today)))

    for i in range(1, 4):  # завтра (1), послезавтра (2), послепослезавтра  (3)
        btns.append(_ikb(NEXT_DAYS[i], cb.CBOrderDay((today + i) % 7)))

    btns.append(_ikb(btns_text.CANCEL, cb.CBOrderCancel()))
    return InlineKeyboardMarkup(row_width=1).add(*btns)


async def order_choose_time(day: int,
                            attempts: int = 5) -> InlineKeyboardMarkup:
    btns = []
    for num in ETHER_TIMES[day]:
        ether = Ether(day, num)
        if ether.is_already_play_today():
Example #17
0
async def playlist_next(query: types.CallbackQuery):
    if not (ether := Ether.now()):
        return await query.message.answer(
            texts.CHOOSE_DAY, reply_markup=kb.playlist_choose_day())