コード例 #1
0
async def joinvc(_, message):
    chat_id = message.chat.id
    if chat_id not in db:
        db[chat_id] = {}

    if "call" in db[chat_id]:
        return await message.reply_text("__**Bot Is Already In The VC**__")
    os.popen(f"cp etc/sample_input.raw input{chat_id}.raw")

    vc = GroupCall(app, f"input{chat_id}.raw")

    db[chat_id]["call"] = vc

    try:
        await db[chat_id]["call"].start(chat_id)
    except Exception:
        peer = await app.resolve_peer(chat_id)
        startVC = CreateGroupCall(
            peer=InputPeerChannel(
                channel_id=peer.channel_id,
                access_hash=peer.access_hash,
            ),
            random_id=app.rnd_id() // 9000000000,
        )
        try:
            await app.send(startVC)
            await db[chat_id]["call"].start(chat_id)
        except ChatAdminRequired:
            del db[chat_id]["call"]
            return await message.reply_text(
                "Make me admin with message delete and vc manage permission")
    await message.reply_text("__**Joined The Voice Chat.**__")
コード例 #2
0
async def joinvc(_, message, manual=False):
    if "call" in db:
        return await message.reply_text("__**Bot Is Already In The VC**__")
    os.popen(f"cp etc/sample_input.raw {PLAYOUT_FILE}")
    vc = pytgcalls.GroupCallFactory(
        app, CLIENT_TYPE,
        OUTGOING_AUDIO_BITRATE_KBIT).get_file_group_call(PLAYOUT_FILE)
    db["call"] = vc
    try:
        await vc.start(CHAT_ID)
    except Exception:
        peer = await app.resolve_peer(CHAT_ID)
        startVC = CreateGroupCall(
            peer=InputPeerChannel(
                channel_id=peer.channel_id,
                access_hash=peer.access_hash,
            ),
            random_id=app.rnd_id() // 9000000000,
        )
        try:
            await app.send(startVC)
            await vc.start(CHAT_ID)
        except ChatAdminRequired:
            del db["call"]
            return await message.reply_text(
                "Make me admin with message delete and vc manage permission")
    await message.reply_text(
        "__**Joined The Voice Chat.**__ \n\n**Note:** __If you can't hear anything,"
        + " Send /leavevc and then /joinvc again.__")
    await message.delete()
コード例 #3
0
async def joinvc(_, message):
    chat_id = message.chat.id
    if chat_id not in db:
        db[chat_id] = {}

    if "call" in db[chat_id]:
        return await message.reply_text("__**Bot Is Already In The VC**__",
                                        quote=False)
    os.popen(f"cp etc/sample_input.raw input{chat_id}.raw"
             )  # No security issue here
    vc = GroupCall(
        client=app,
        input_filename=f"input{chat_id}.raw",
        play_on_repeat=True,
        enable_logs_to_console=False,
    )
    try:
        await vc.start(chat_id)
    except RuntimeError:
        peer = await app.resolve_peer(chat_id)
        startVC = CreateGroupCall(
            peer=InputPeerChannel(
                channel_id=peer.channel_id,
                access_hash=peer.access_hash,
            ),
            random_id=app.rnd_id() // 9000000000,
        )
        try:
            await app.send(startVC)
            await joinvc(_, message)
        except ChatAdminRequired:
            return await message.reply_text(
                "Make me admin with message delete and vc manage permission")
    db[chat_id]["call"] = vc
    await message.reply_text("__**Joined The Voice Chat.**__", quote=False)
コード例 #4
0
ファイル: groupcall.py プロジェクト: Enzyy-dep/USERGE-X
async def start_vc_(message: Message):
    """Start voice chat"""
    chat_id = message.chat.id
    await userge.send(
        CreateGroupCall(
            peer=(await userge.resolve_peer(chat_id)),
            random_id=randint(10000, 999999999),
        ))
    await message.edit(f"Started Voice Chat in **Chat ID** : `{chat_id}`",
                       del_in=5,
                       log=__name__)
コード例 #5
0
ファイル: __main__.py プロジェクト: Keys-007/Userge-Plugins
async def joinvc(msg: Message):
    """ join video chat """
    await msg.delete()
    if Vars.CHAT_NAME:
        return await reply_text(msg, f"`Already joined in {Vars.CHAT_NAME}`")

    flags = msg.flags
    join_as = flags.get('-as')
    chat = flags.get('-at')

    if not chat and msg.chat.type == "private":
        return await msg.err(
            "Invalid chat, either use in group / channel or use -at flag.")
    if chat:
        if chat.strip("-").isnumeric():
            chat = int(chat)
        try:
            _chat = await VC_CLIENT.get_chat(chat)
        except Exception as e:
            return await reply_text(msg,
                                    f'Invalid Join In Chat Specified\n{e}')
        Vars.CHAT_ID = _chat.id
        Vars.CHAT_NAME = _chat.title
        # Joins video_chat in a remote chat and control it from Saved Messages
        # / Linked Chat
        CONTROL_CHAT_IDS.append(userge.id)
        if _chat.linked_chat:
            CONTROL_CHAT_IDS.append(_chat.linked_chat.id)
    else:
        chat_id_ = msg.chat.username or msg.chat.id
        try:
            # caching the peer in case of public chats to play without joining for VC_SESSION_STRING
            await VC_CLIENT.get_chat(chat_id_)
        except (ChannelInvalid, ChannelPrivate):
            msg_ = await reply_text(
                msg,
                'You are using VC_SESSION_STRING and it seems that user is '
                'not present in this group.\ntrying to join group.')
            join = await invite_vc_client(msg)
            await msg_.delete()
            if not join:
                return
        Vars.CHAT_ID = msg.chat.id
        Vars.CHAT_NAME = msg.chat.title
    if join_as:
        if join_as.strip("-").isnumeric():
            join_as = int(join_as)
        try:
            join_as = (await VC_CLIENT.get_chat(join_as)).id
        except Exception as e:
            Vars.CHAT_ID, Vars.CHAT_NAME = 0, ''
            CONTROL_CHAT_IDS.clear()
            return await reply_text(msg,
                                    f'Invalid Join As Chat Specified\n{e}')
        join_as_peers = await VC_CLIENT.send(
            GetGroupCallJoinAs(
                peer=(await VC_CLIENT.resolve_peer(Vars.CHAT_ID))))
        raw_id = int(str(join_as).replace("-100", ""))
        if raw_id not in [
                getattr(peers, "user_id", None)
                or getattr(peers, "channel_id", None)
                for peers in join_as_peers.peers
        ]:
            Vars.CHAT_ID, Vars.CHAT_NAME = 0, ''
            CONTROL_CHAT_IDS.clear()
            return await reply_text(
                msg, "You cant join the video chat as this channel.")

    if join_as:
        peer = await VC_CLIENT.resolve_peer(join_as)
    else:
        peer = await VC_CLIENT.resolve_peer('me')
    try:
        if not call.is_connected:
            await call.start()
        await call.join_group_call(
            Vars.CHAT_ID,
            AudioPiped('http://duramecho.com/Misc/SilentCd/Silence01s.mp3'),
            join_as=peer,
            stream_type=StreamType().pulse_stream)
    except NoActiveGroupCall:
        try:
            peer = await VC_CLIENT.resolve_peer(Vars.CHAT_ID)
            await VC_CLIENT.send(CreateGroupCall(peer=peer, random_id=2))
            await asyncio.sleep(3)
            Vars.CHAT_ID, Vars.CHAT_NAME = 0, ''
            CONTROL_CHAT_IDS.clear()
            return await joinvc(msg)
        except Exception as err:
            Vars.CHAT_ID, Vars.CHAT_NAME = 0, ''
            CONTROL_CHAT_IDS.clear()
            return await reply_text(msg, str(err))
    except (NodeJSNotInstalled, TooOldNodeJSVersion):
        return await reply_text(
            msg, "NodeJs is not installed or installed version is too old.")
    except AlreadyJoinedError:
        await call.leave_group_call(Vars.CHAT_ID)
        await asyncio.sleep(3)
        Vars.CHAT_ID, Vars.CHAT_NAME = 0, ''
        CONTROL_CHAT_IDS.clear()
        return await joinvc(msg)
    except Exception as e:
        Vars.CHAT_ID, Vars.CHAT_NAME = 0, ''
        CONTROL_CHAT_IDS.clear()
        return await reply_text(msg, f'Error during Joining the Call\n`{e}`')
    await on_join()
    await reply_text(msg, "`Joined VideoChat Successfully`", del_in=5)