Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
chats.py369 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7from . import get_help8 9__doc__ = get_help("help_chats")10 11 12from telethon.errors import ChatAdminRequiredError as no_admin13from telethon.tl.functions.channels import (14    CreateChannelRequest,15    DeleteChannelRequest,16    EditPhotoRequest,17    GetFullChannelRequest,18    UpdateUsernameRequest,19)20from telethon.tl.functions.messages import (21    CreateChatRequest,22    ExportChatInviteRequest,23    GetFullChatRequest,24)25from telethon.tl.types import (26    ChannelParticipantsKicked,27    User,28    UserStatusEmpty,29    UserStatusLastMonth,30    UserStatusLastWeek,31    UserStatusOffline,32    UserStatusOnline,33    UserStatusRecently,34)35 36from . import HNDLR, LOGS, asst, con, get_string, mediainfo, os, types, udB, ultroid_cmd37 38 39@ultroid_cmd(40    pattern="delchat",41    groups_only=True,42)43async def _(e):44    xx = await e.eor(get_string("com_1"))45    try:46        match = e.text.split(" ", maxsplit=1)[1]47        chat = await e.client.parse_id(match)48    except IndexError:49        chat = e.chat_id50    try:51        await e.client(DeleteChannelRequest(chat))52    except TypeError:53        return await xx.eor(get_string("chats_1"), time=10)54    except no_admin:55        return await xx.eor(get_string("chats_2"), time=10)56    await e.client.send_message(57        int(udB.get_key("LOG_CHANNEL")), get_string("chats_6").format(e.chat_id)58    )59 60 61@ultroid_cmd(62    pattern="getlink( (.*)|$)",63    groups_only=True,64    manager=True,65)66async def _(e):67    reply = await e.get_reply_message()68    match = e.pattern_match.group(1).strip()69    if reply and not isinstance(reply.sender, User):70        chat = await reply.get_sender()71    else:72        chat = await e.get_chat()73    if hasattr(chat, "username") and chat.username:74        return await e.eor(f"Username: @{chat.username}")75    request, usage, title, link = None, None, None, None76    if match:77        split = match.split(maxsplit=1)78        request = split[0] in ["r", "request"]79        title = "Created by Ultroid"80        if len(split) > 1:81            match = split[1]82            spli = match.split(maxsplit=1)83            if spli[0].isdigit():84                usage = int(spli[0])85            if len(spli) > 1:86                title = spli[1]87        elif not request:88            if match.isdigit():89                usage = int(match)90            else:91                title = match92        if request and usage:93            usage = 094    if request or title:95        try:96            r = await e.client(97                ExportChatInviteRequest(98                    e.chat_id,99                    request_needed=request,100                    usage_limit=usage,101                    title=title,102                ),103            )104        except no_admin:105            return await e.eor(get_string("chats_2"), time=10)106        link = r.link107    else:108        if isinstance(chat, types.Chat):109            FC = await e.client(GetFullChatRequest(chat.id))110        elif isinstance(chat, types.Channel):111            FC = await e.client(GetFullChannelRequest(chat.id))112        else:113            return114        Inv = FC.full_chat.exported_invite115        if Inv and not Inv.revoked:116            link = Inv.link117    if link:118        return await e.eor(f"Link:- {link}")119    await e.eor("`Failed to getlink!\nSeems like link is inaccessible to you...`")120 121 122@ultroid_cmd(123    pattern="create (b|g|c)(?: |$)(.*)",124)125async def _(e):126    type_of_group = e.pattern_match.group(1).strip()127    group_name = e.pattern_match.group(2)128    username = None129    if " ; " in group_name:130        group_ = group_name.split(" ; ", maxsplit=1)131        group_name = group_[0]132        username = group_[1]133    xx = await e.eor(get_string("com_1"))134    if type_of_group == "b":135        try:136            r = await e.client(137                CreateChatRequest(138                    users=[asst.me.username],139                    title=group_name,140                ),141            )142            created_chat_id = r.chats[0].id143            result = await e.client(144                ExportChatInviteRequest(145                    peer=created_chat_id,146                ),147            )148            await xx.edit(149                get_string("chats_4").format(group_name, result.link),150                link_preview=False,151            )152        except Exception as ex:153            await xx.edit(str(ex))154    elif type_of_group in ["g", "c"]:155        try:156            r = await e.client(157                CreateChannelRequest(158                    title=group_name,159                    about=get_string("chats_5"),160                    megagroup=type_of_group != "c",161                )162            )163 164            created_chat_id = r.chats[0].id165            if username:166                await e.client(UpdateUsernameRequest(created_chat_id, username))167                result = f"https://t.me/{username}"168            else:169                result = (170                    await e.client(171                        ExportChatInviteRequest(172                            peer=created_chat_id,173                        ),174                    )175                ).link176            await xx.edit(177                get_string("chats_6").format(f"[{group_name}]({result})"),178                link_preview=False,179            )180        except Exception as ex:181            await xx.edit(str(ex))182 183 184# ---------------------------------------------------------------- #185 186 187@ultroid_cmd(188    pattern="setgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"189)190async def _(ult):191    if not ult.is_reply:192        return await ult.eor("`Reply to a Media..`", time=5)193    match = ult.pattern_match.group(1).strip()194    if not ult.client._bot and match:195        try:196            chat = await ult.client.parse_id(match)197        except Exception as ok:198            return await ult.eor(str(ok))199    else:200        chat = ult.chat_id201    reply = await ult.get_reply_message()202    if reply.photo or reply.sticker or reply.video:203        replfile = await reply.download_media()204    elif reply.document and reply.document.thumbs:205        replfile = await reply.download_media(thumb=-1)206    else:207        return await ult.eor("Reply to a Photo or Video..")208    mediain = mediainfo(reply.media)209    if "animated" in mediain:210        replfile = await con.convert(replfile, convert_to="mp4")211    else:212        replfile = await con.convert(213            replfile, outname="chatphoto", allowed_formats=["jpg", "png", "mp4"]214        )215    file = await ult.client.upload_file(replfile)216    try:217        if "pic" not in mediain:218            file = types.InputChatUploadedPhoto(video=file)219        await ult.client(EditPhotoRequest(chat, file))220        await ult.eor("`Group Photo has Successfully Changed !`", time=5)221    except Exception as ex:222        await ult.eor(f"Error occured.\n`{str(ex)}`", time=5)223    os.remove(replfile)224 225 226@ultroid_cmd(227    pattern="delgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"228)229async def _(ult):230    match = ult.pattern_match.group(1).strip()231    chat = ult.chat_id232    if not ult.client._bot and match:233        chat = match234    try:235        await ult.client(EditPhotoRequest(chat, types.InputChatPhotoEmpty()))236        text = "`Removed Chat Photo..`"237    except Exception as E:238        text = str(E)239    return await ult.eor(text, time=5)240 241 242@ultroid_cmd(pattern="unbanall$", manager=True, admins_only=True, require="ban_users")243async def _(event):244    xx = await event.eor("Searching Participant Lists.")245    p = 0246    title = (await event.get_chat()).title247    async for i in event.client.iter_participants(248        event.chat_id,249        filter=ChannelParticipantsKicked,250        aggressive=True,251    ):252        try:253            await event.client.edit_permissions(event.chat_id, i, view_messages=True)254            p += 1255        except no_admin:256            pass257        except BaseException as er:258            LOGS.exception(er)259    await xx.eor(f"{title}: {p} unbanned", time=5)260 261 262@ultroid_cmd(263    pattern="rmusers( (.*)|$)",264    groups_only=True,265    admins_only=True,266    fullsudo=True,267)268async def _(event):269    xx = await event.eor(get_string("com_1"))270    input_str = event.pattern_match.group(1).strip()271    p, a, b, c, d, m, n, y, w, o, q, r = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0272    async for i in event.client.iter_participants(event.chat_id):273        p += 1  # Total Count274        if isinstance(i.status, UserStatusEmpty):275            if "empty" in input_str:276                try:277                    await event.client.kick_participant(event.chat_id, i)278                    c += 1279                except BaseException:280                    pass281            else:282                y += 1283        if isinstance(i.status, UserStatusLastMonth):284            if "month" in input_str:285                try:286                    await event.client.kick_participant(event.chat_id, i)287                    c += 1288                except BaseException:289                    pass290            else:291                m += 1292        if isinstance(i.status, UserStatusLastWeek):293            if "week" in input_str:294                try:295                    await event.client.kick_participant(event.chat_id, i)296                    c += 1297                except BaseException:298                    pass299            else:300                w += 1301        if isinstance(i.status, UserStatusOffline):302            if "offline" in input_str:303                try:304                    await event.client.kick_participant(event.chat_id, i)305                    c += 1306                except BaseException:307                    pass308            else:309                o += 1310        if isinstance(i.status, UserStatusOnline):311            if "online" in input_str:312                try:313                    await event.client.kick_participant(event.chat_id, i)314                    c += 1315                except BaseException:316                    pass317            else:318                q += 1319        if isinstance(i.status, UserStatusRecently):320            if "recently" in input_str:321                try:322                    await event.client.kick_participant(event.chat_id, i)323                    c += 1324                except BaseException:325                    pass326            else:327                r += 1328        if i.bot:329            if "bot" in input_str:330                try:331                    await event.client.kick_participant(event.chat_id, i)332                    c += 1333                except BaseException:334                    pass335            else:336                b += 1337        elif i.deleted:338            if "deleted" in input_str:339                try:340                    await event.client.kick_participant(event.chat_id, i)341                    c += 1342                except BaseException:343                    pass344            else:345                d += 1346        elif i.status is None:347            if "none" in input_str:348                try:349                    await event.client.kick_participant(event.chat_id, i)350                    c += 1351                except BaseException:352                    pass353            else:354                n += 1355    if input_str:356        required_string = f"**>> Kicked** `{c} / {p}` **users**\n\n"357    else:358        required_string = f"**>> Total** `{p}` **users**\n\n"359    required_string += f"  `{HNDLR}rmusers deleted`  **••**  `{d}`\n"360    required_string += f"  `{HNDLR}rmusers empty`  **••**  `{y}`\n"361    required_string += f"  `{HNDLR}rmusers month`  **••**  `{m}`\n"362    required_string += f"  `{HNDLR}rmusers week`  **••**  `{w}`\n"363    required_string += f"  `{HNDLR}rmusers offline`  **••**  `{o}`\n"364    required_string += f"  `{HNDLR}rmusers online`  **••**  `{q}`\n"365    required_string += f"  `{HNDLR}rmusers recently`  **••**  `{r}`\n"366    required_string += f"  `{HNDLR}rmusers bot`  **••**  `{b}`\n"367    required_string += f"  `{HNDLR}rmusers none`  **••**  `{n}`"368    await xx.eor(required_string)369