Пример #1
0
async def queuer(_, message):
    global running
    try:
        usage = """
**Usage:**
__/play Song_Name__
__/play youtube/saavn Song_Name__
__/play Reply_On_Audio__"""

        async with PLAY_LOCK:
            if (
                len(message.command) < 2
                and not message.reply_to_message
            ):
                return await message.reply_text(usage)
            if "call" not in db:
                return await message.reply_text(
                    "**Use /joinvc First!**"
                )
            if message.reply_to_message:
                if message.reply_to_message.audio:
                    service = "telegram"
                    song_name = message.reply_to_message.audio.title
                else:
                    return await message.reply_text(
                        "**Reply to a telegram audio file**"
                    )
            else:
                text = message.text.split("\n")[0]
                text = text.split(None, 2)[1:]
                service = text[0].lower()
                services = ["youtube", "saavn"]
                if service in services:
                    song_name = text[1]
                else:
                    service = get_default_service()
                    song_name = " ".join(text)
            requested_by = message.from_user.first_name
            if "queue" not in db:
                db["queue"] = asyncio.Queue()
            if not db["queue"].empty() or db.get("running"):
                await message.reply_text("__**Added To Queue.__**")

            await db["queue"].put(
                {
                    "service": service or telegram,
                    "requested_by": requested_by,
                    "query": song_name,
                    "message": message,
                }
            )
        if not db.get("running"):
            db["running"] = True
            await start_queue()
    except Exception as e:
        await message.reply_text(str(e))
        e = traceback.format_exc()
        print(e)
Пример #2
0
async def queuer(_, message):
    global running
    chat_id = message.chat.id
    try:
        usage = """
**Usage:**
__**/play Song_Name**__ (uses youtube service)
__**/play youtube/saavn/deezer Song_Name**__
__**/play Reply_On_Audio**__"""

        if len(message.command) < 2 and (not message.reply_to_message or
                                         not message.reply_to_message.audio):
            return await message.reply_text(usage, quote=False)
        if chat_id not in db:
            db[chat_id] = {}
        if "call" not in db[chat_id]:
            return await message.reply_text("**Use /joinvc First!**")
        if message.reply_to_message:
            if message.reply_to_message.audio:
                service = "telegram"
                song_name = message.reply_to_message.audio.title
            else:
                return await message.reply_text(
                    "**Reply to a telegram audio file**")
        else:
            text = message.text.split("\n")[0]
            text = text.split(None, 2)[1:]
            service = text[0].lower()
            services = ["youtube", "deezer", "saavn"]
            if service in services:
                song_name = text[1]
            else:
                service = get_default_service()
                song_name = " ".join(text)
        requested_by = message.from_user.first_name
        if chat_id not in db:
            db[chat_id] = {}
        if "queue" not in db[chat_id]:
            db[chat_id]["queue"] = asyncio.Queue()
        if not db[chat_id]["queue"].empty() or ("running" in db[chat_id]
                                                and db[chat_id]["running"]):
            await message.reply_text("__**Added To Queue.__**", quote=False)

        await db[chat_id]["queue"].put({
            "service":
            deezer if service == "deezer" else saavn if service == "saavn" else
            youtube if service == "youtube" else telegram,
            "requested_by":
            requested_by,
            "query":
            song_name,
            "message":
            message,
        })
        if "running" not in db[chat_id]:
            db[chat_id]["running"] = False
        if not db[chat_id]["running"]:
            db[chat_id]["running"] = True
            await start_queue(chat_id)
    except Exception as e:
        await message.reply_text(str(e), quote=False)
        e = traceback.format_exc()
        print(e)