File size: 4,118 Bytes
78b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import uuid

from pyrogram import Client
from pyrogram.raw import base
from pyrogram.raw.functions.channels import GetFullChannel
from pyrogram.raw.functions.phone import (
    CreateGroupCall,
    DiscardGroupCall,
    ExportGroupCallInvite,
    GetGroupParticipants,
)
from pyrogram.types import Message

from . import HelpMenu, Symbols, group_only, hellbot, on_message


@on_message("startvc", chat_type=group_only, admin_only=True, allow_stan=True)
async def startvc(client: Client, message: Message):
    if len(message.command) > 1:
        call_name = await hellbot.input(message)
    else:
        call_name = "Hellbot VC"

    hell = await hellbot.edit(message, "Starting Voice Chat...")
    try:
        await client.invoke(
            CreateGroupCall(
                peer=(await client.resolve_peer(message.chat.id)),
                random_id=int(str(uuid.uuid4().int)[:8]),
                title=call_name,
            )
        )
        await hellbot.delete(hell, "Voice Chat started!")
    except Exception as e:
        await hellbot.error(hell, str(e))


@on_message("endvc", chat_type=group_only, admin_only=True, allow_stan=True)
async def endvc(client: Client, message: Message):
    hell = await hellbot.edit(message, "Ending Voice Chat...")

    try:
        full_chat: base.messages.ChatFull = await client.invoke(
            GetFullChannel(channel=(await client.resolve_peer(message.chat.id)))
        )
        await client.invoke(DiscardGroupCall(call=full_chat.full_chat.call))
        await hellbot.delete(hell, "Voice Chat ended!")
    except Exception as e:
        await hellbot.error(hell, str(e))


@on_message("vclink", chat_type=group_only, allow_stan=True)
async def vclink(client: Client, message: Message):
    hell = await hellbot.edit(message, "Getting Voice Chat link...")

    try:
        full_chat: base.messages.ChatFull = await client.invoke(
            GetFullChannel(channel=(await client.resolve_peer(message.chat.id)))
        )

        invite: base.phone.ExportedGroupCallInvite = await client.invoke(
            ExportGroupCallInvite(call=full_chat.full_chat.call)
        )
        await hellbot.delete(hell, f"Voice Chat Link: {invite.link}")
    except Exception as e:
        await hellbot.error(hell, f"`{e}`")


@on_message("vcmembers", chat_type=group_only, admin_only=True, allow_stan=True)
async def vcmembers(client: Client, message: Message):
    hell = await hellbot.edit(message, "Getting Voice Chat members...")

    try:
        full_chat: base.messages.ChatFull = await client.invoke(
            GetFullChannel(channel=(await client.resolve_peer(message.chat.id)))
        )
        participants: base.phone.GroupParticipants = await client.invoke(
            GetGroupParticipants(
                call=full_chat.full_chat.call,
                ids=[],
                sources=[],
                offset="",
                limit=1000,
            )
        )
        count = participants.count
        text = f"**Total Voice Chat Members:** `{count}`\n\n"
        for participant in participants.participants:
            text += f"{Symbols.bullet} `{participant.peer.user_id}`\n"

        await hell.edit(text)
    except Exception as e:
        await hellbot.error(hell, str(e))


HelpMenu("voicechat").add(
    "startvc",
    "<vc name (optional)>",
    "Start a voice chat in the group with the given name (optional)",
    "startvc Hellbot VC",
    "Only admins with manage voice chats permission can use this command.",
).add(
    "endvc",
    None,
    "End the voice chat in the group",
    "endvc",
    "Only admins with manage voice chats permission can use this command.",
).add(
    "vclink",
    None,
    "Get the invite link of currennt group's voice chat.",
    "vclink",
).add(
    "vcmembers",
    None,
    "Get the list of members in current group's voice chat.",
    "vcmembers",
    "Only admins with manage voice chats permission can use this command.",
).info(
    "Manage Voice Chats",
).done()