File size: 3,095 Bytes
44aada1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
For TeleBot, credits to @pureindialover
"""
# Re-written by @its_xditya

from telethon.tl import functions

from telebot import CMD_HELP
from telebot.utils import admin_cmd


@telebot.on(admin_cmd(outgoing=True, pattern="create (b|g|c)(?: |$)(.*)"))
async def telegraphs(grop):

    """ For .create command, Creating New Group & Channel """

    if not grop.text[0].isalpha() and grop.text[0] not in ("/", "#", "@", "!"):

        if grop.fwd_from:

            return

        type_of_group = grop.pattern_match.group(1)

        group_name = grop.pattern_match.group(2)

        if type_of_group == "b":

            try:

                result = await grop.client(
                    functions.messages.CreateChatRequest(  # pylint:disable=E0602
                        users=["@Serena_Robot"],
                        # Not enough users (to create a chat, for example)
                        # Telegram, no longer allows creating a chat with
                        # ourselves
                        title=group_name,
                    )
                )

                created_chat_id = result.chats[0].id

                await grop.client(
                    functions.messages.DeleteChatUserRequest(
                        chat_id=created_chat_id, user_id="@Serena_Robot"
                    )
                )

                result = await grop.client(
                    functions.messages.ExportChatInviteRequest(
                        peer=created_chat_id,
                    )
                )

                await grop.edit(
                    "Your `{}` Group Made Boss!. Join [{}]({})".format(
                        group_name, group_name, result.link
                    )
                )

            except Exception as e:  # pylint:disable=C0103,W0703

                await grop.edit(str(e))

        elif type_of_group == "g" or type_of_group == "c":

            try:

                r = await grop.client(
                    functions.channels.CreateChannelRequest(  # pylint:disable=E0602
                        title=group_name,
                        about="Welcome to this Channel boss",
                        megagroup=False if type_of_group == "c" else True,
                    )
                )

                created_chat_id = r.chats[0].id

                result = await grop.client(
                    functions.messages.ExportChatInviteRequest(
                        peer=created_chat_id,
                    )
                )

                await grop.edit(
                    "Your `{}` Group/Channel Has been made Sir!. Join [{}]({})".format(
                        group_name, group_name, result.link
                    )
                )

            except Exception as e:  # pylint:disable=C0103,W0703

                await grop.edit(str(e))


CMD_HELP.update(
    {
        "create": "\
Create\
\nUsage: Create Channel, Group & Group With Bot.\
\n\n.create g\
\nUsage: Create a Private Group.\
\n\n.create b\
\nUsage: Create a Group with Bot.\
\n\n.create c\
\nUsage: Create a Channel.\
"
    }
)