Exemple #1
0
async def admin_cancel(query, day: int, time: int, status: bool):
    user = query.message.caption_entities[0].user
    name = bot_utils.get_audio_name(query.message.audio)

    admin_keyboard = bot_utils.keyboard_admin(day, time, name, user.id)
    now = bot_utils.is_break_now(day, time)
    text_datetime = bot_utils.TEXT['days1'][
        day] + ', ' + bot_utils.get_break_name(time)
    text_admin = ('‼️' if now else '❗️') + \
                 'Новый заказ - ' + text_datetime + \
                 (' (сейчас!)' if now else '') + \
                 ' от ' + bot_utils.get_user_name(user)

    await bot.edit_message_caption(caption=text_admin,
                                   chat_id=ADMINS_CHAT_ID,
                                   message_id=query.message.message_id,
                                   reply_markup=admin_keyboard)

    if status:
        path = bot_utils.get_music_path(day, time) / (name + '.mp3')

        for i in await music_api.radioboss_api(
                action='getplaylist2'):  # удалить из плейлиста радиобосса
            if i.attrib['FILENAME'] == str(path):
                await music_api.radioboss_api(action='delete',
                                              pos=i.attrib['INDEX'])
                break
        bot_utils.delete_file(path)  # удалить с диска
Exemple #2
0
async def predlozka_time(query, day: int, time: int):
    user = query.from_user
    name = bot_utils.get_audio_name(query.message.audio)

    is_ban = ban.chek_ban(user.id)
    if is_ban:
        return await bot.send_message(
            query.message.chat.id, "Вы не можете предлагать музыку до " +
            datetime.fromtimestamp(is_ban).strftime("%d.%m %H:%M"))

    admin_keyboard = bot_utils.keyboard_admin(day, time, name, user.id)
    now = bot_utils.is_break_now(day, time)
    text_datetime = bot_utils.TEXT['days1'][
        day] + ', ' + bot_utils.get_break_name(time)
    text_admin = ('‼️' if now else '❗️') + \
                 'Новый заказ - ' + text_datetime + \
                 (' (сейчас!)' if now else '') + \
                 ' от ' + bot_utils.get_user_name(user)

    await bot.edit_message_caption(
        caption=bot_utils.TEXT['predlozka_moderating'].format(text_datetime),
        chat_id=query.message.chat.id,
        message_id=query.message.message_id,
        reply_markup=types.InlineKeyboardMarkup())

    await bot.send_message(user.id,
                           bot_utils.TEXT['menu'],
                           reply_markup=bot_utils.keyboard_start)

    await bot.send_audio(ADMINS_CHAT_ID,
                         query.message.audio.file_id,
                         text_admin,
                         reply_markup=admin_keyboard)
Exemple #3
0
async def admin_unchoice(query, day: int, time: int, status: str):
    user = query.message.caption_entities[0].user
    name = bot_utils.get_audio_name(query.message.audio)

    admin_text, _ = await bot_utils.gen_order_caption(day, time, user,
                                                      audio_name=bot_utils.get_audio_name(query.message.audio))

    await bot.edit_message_caption(ADMINS_CHAT_ID, query.message.message_id,
                                   caption=admin_text, reply_markup=keyboards.admin_choose(day, time))

    if status != 'reject':  # если заказ был принят а щас отменяют
        path = bot_utils.get_music_path(day, time) / (name + '.mp3')
        bot_utils.delete_file(path)  # удалить с диска
        for i in await music_api.radioboss_api(action='getplaylist2'):  # удалить из плейлиста радиобосса
            if i.attrib['FILENAME'] == str(path):
                await music_api.radioboss_api(action='delete', pos=i.attrib['INDEX'])
                break
Exemple #4
0
async def order_time_choiced(query, day: int, time: int):
    user = query.from_user

    is_ban = ban.chek_ban(user.id)
    if is_ban:
        return await bot.send_message(query.message.chat.id, "Вы не можете предлагать музыку до " +
                                      datetime.fromtimestamp(is_ban).strftime("%d.%m %H:%M"))

    admin_text, also = await bot_utils.gen_order_caption(day, time, user,
                                                         audio_name=bot_utils.get_audio_name(query.message.audio))

    await bot.edit_message_caption(query.message.chat.id, query.message.message_id,
                                   caption=consts.text['order_moderating'].format(also['text_datetime']),
                                   reply_markup=types.InlineKeyboardMarkup())
    await bot.send_message(query.message.chat.id, consts.text['menu'], reply_markup=keyboards.start)
    await bot.send_audio(ADMINS_CHAT_ID, query.message.audio.file_id, admin_text,
                         reply_markup=keyboards.admin_choose(day, time))
Exemple #5
0
async def admin_choice(query, status: bool, user_id, day: int, time: int):
    name = bot_utils.get_audio_name(query.message.audio)

    new_text = 'Заказ: ' + query.message.caption.split(' - ')[1].split(' от')[0] + \
               ', от ' + bot_utils.get_user_name(query.message.caption_entities[0].user) + \
               ' - ' + ("✅Принят" if status else "❌Отклонен") + \
               ' (' + bot_utils.get_user_name(query.from_user) + ')'

    keyboard_cancel = types.InlineKeyboardMarkup()
    keyboard_cancel.add(
        types.InlineKeyboardButton(text='Отмена',
                                   callback_data='-|-'.join([
                                       'admin_cancel',
                                       str(day),
                                       str(time), 'ok' if status else 'neok'
                                   ])))

    await bot.edit_message_caption(caption=new_text,
                                   chat_id=query.message.chat.id,
                                   message_id=query.message.message_id,
                                   reply_markup=keyboard_cancel)

    if status:
        to = bot_utils.get_music_path(day, time) / (name + '.mp3')
        bot_utils.create_dirs(to)
        await query.message.audio.download(to, timeout=60)
        await bot_utils.write_sender_tag(
            to, query.message.caption_entities[0].user)
        if bot_utils.is_break_now(day, time):
            data = await playlist_api.get_suggestion_data()
            msg = bot_utils.TEXT['predlozka_ok_next'].format(
                name, 'прямо сейчас!'
                if data[0] == -2 else f'примерно через {data[1]} ' +
                bot_utils.case_by_num(data[1], 'минуту', 'минуты', 'минут'))
            await music_api.radioboss_api(action='inserttrack',
                                          filename=to,
                                          pos=data[0])
            await bot.send_message(user_id, msg)
        else:
            await bot.send_message(user_id,
                                   bot_utils.TEXT['predlozka_ok'].format(name))
    else:
        await bot.send_message(user_id,
                               bot_utils.TEXT['predlozka_neok'].format(name))
Exemple #6
0
async def admin_choice(query, day: int, time: int, status: str):
    audio_name = bot_utils.get_audio_name(query.message.audio)
    user = query.message.caption_entities[0].user

    admin_text, also = await bot_utils.gen_order_caption(day, time, user, status=status, moder=query.from_user)
    await bot.edit_message_caption(query.message.chat.id, query.message.message_id, caption=admin_text,
                                   reply_markup=keyboards.admin_unchoose(day, time, status))

    if status == 'reject':  # отмена
        return await bot.send_message(user.id, consts.text['order_neok'].format(audio_name))

    to = bot_utils.get_music_path(day, time) / (audio_name + '.mp3')
    bot_utils.create_dirs(to)
    await query.message.audio.download(to, timeout=60)
    await bot_utils.write_sender_tag(to, user)

    if not also['now']:  # если щас не этот эфир то похуй
        return await bot.send_message(user.id, consts.text['order_ok'].format(audio_name))

    # todo check doubles

    when_playing = ''
    if status == 'now':  # следующим
        when_playing = 'прямо сейчас!'
        await music_api.radioboss_api(action='inserttrack', filename=to, pos=-2)
        await bot.send_message(user.id, consts.text['order_ok_next'].format(audio_name, when_playing))

    if status == 'queue':  # в очередь
        last_track = await playlist_api.get_new_order_pos()
        if not last_track:  # нету места
            when_playing = 'не успел :('
            await bot.send_message(user.id, consts.text['order_ok_but_notime'].format(audio_name))
        else:  # есть место
            minutes_left = round((last_track['time_start'] - datetime.now()).seconds / 60)
            when_playing = f'через {minutes_left} ' + bot_utils.case_by_num(minutes_left, 'минуту', 'минуты', 'минут')

            await music_api.radioboss_api(action='inserttrack', filename=to, pos=last_track['index'])
            await bot.send_message(user.id, consts.text['order_ok_next'].format(audio_name, when_playing))

    await bot.edit_message_caption(query.message.chat.id, query.message.message_id,
                                   caption=admin_text + '\n🕑 ' + when_playing,
                                   reply_markup=keyboards.admin_unchoose(day, time, status))
Exemple #7
0
async def admin_reply(message):
    if message.reply_to_message.audio:  # на заказ
        to = message.reply_to_message.caption_entities[0].user.id
        txt = "На ваш заказ <i>(" + bot_utils.get_audio_name(
            message.reply_to_message.audio) + ")</i> ответили:"

    if message.reply_to_message.forward_from:  # на отзыв
        to = message.reply_to_message.forward_from.id
        txt = "На ваше сообщение ответили: "

    await bot.send_message(to, txt)
    if message.audio:
        await bot.send_audio(to, message.audio.file_id)
    elif message.sticker:
        await bot.send_sticker(to, message.sticker.file_id)
    elif message.photo:
        await bot.send_photo(
            to,
            message.photo[-1].file_id,
            caption=message.caption if hasattr(message, "caption") else "")
    else:
        await bot.send_message(to, message.text, parse_mode='markdown')
Exemple #8
0
async def admin_check_text(query):
    name = bot_utils.get_audio_name(query.message.audio)
    text = await music_api.search_text(name)
    bad_words = bot_utils.check_bad_words(text)
    await bot.answer_callback_query(query.id, text=bad_words)