Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
forcesubscribe.py180 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/>.7"""8✘ Commands Available -9 10• `{i}fsub <chat username><id>`11    Enable ForceSub in Used Chat !12 13• `{i}checkfsub`14    Check/Get Active ForceSub Setting of Used Chat.15 16• `{i}remfsub`17    Remove ForceSub from Used Chat !18 19    Note - You Need to be Admin in Both Channel/Chats20        in order to Use ForceSubscribe.21"""22 23import re24 25from telethon.errors.rpcerrorlist import ChatAdminRequiredError, UserNotParticipantError26from telethon.tl.custom import Button27from telethon.tl.functions.channels import GetParticipantRequest28from telethon.tl.functions.messages import ExportChatInviteRequest29from telethon.tl.types import (30    Channel,31    ChannelParticipantBanned,32    ChannelParticipantLeft,33    User,34)35 36from pyUltroid.dB.forcesub_db import add_forcesub, get_forcesetting, rem_forcesub37 38from . import (39    LOGS,40    asst,41    callback,42    events,43    get_string,44    in_pattern,45    inline_mention,46    udB,47    ultroid_bot,48    ultroid_cmd,49)50 51CACHE = {}52 53 54@ultroid_cmd(pattern="fsub( (.*)|$)", admins_only=True, groups_only=True)55async def addfor(e):56    match = e.pattern_match.group(1).strip()57    if not match:58        return await e.eor(get_string("fsub_1"), time=5)59    try:60        match = await e.client.parse_id(match)61    except BaseException:62        return await e.eor(get_string("fsub_2"), time=5)63    add_forcesub(e.chat_id, match)64    await e.eor("Added ForceSub in This Chat !")65    ultroid_bot.add_handler(force_sub, events.NewMessage(incoming=True))66 67 68@ultroid_cmd(pattern="remfsub$")69async def remor(e):70    res = rem_forcesub(e.chat_id)71    if not res:72        return await e.eor(get_string("fsub_3"), time=5)73    await e.eor("Removed ForceSub...")74 75 76@ultroid_cmd(pattern="checkfsub$")77async def getfsr(e):78    res = get_forcesetting(e.chat_id)79    if not res:80        return await e.eor("ForceSub is Not Active In This Chat !", time=5)81    cha = await e.client.get_entity(int(res))82    await e.eor(f"**ForceSub Status** : `Active`\n- **{cha.title}** `({res})`")83 84 85@in_pattern("fsub( (.*)|$)", owner=True)86async def fcall(e):87    match = e.pattern_match.group(1).strip()88    spli = match.split("_")89    user = await ultroid_bot.get_entity(int(spli[0]))90    cl = await ultroid_bot.get_entity(int(spli[1]))91    text = f"Hi {inline_mention(user)}, You Need to Join"92    text += f" {cl.title} in order to Chat in this Group."93    el = (94        f"https://t.me/{cl.username}"95        if cl.username96        else (await ultroid_bot(ExportChatInviteRequest(cl))).link97    )98 99    res = [100        await e.builder.article(101            title="forcesub",102            text=text,103            buttons=[104                [Button.url(text=get_string("fsub_4"), url=el)],105                [Button.inline(get_string("fsub_5"), data=f"unm_{match}")],106            ],107        )108    ]109    await e.answer(res)110 111 112@callback(re.compile("unm_(.*)"))113async def diesoon(e):114    match = (e.data_match.group(1)).decode("UTF-8")115    spli = match.split("_")116    if e.sender_id != int(spli[0]):117        return await e.answer(get_string("fsub_7"), alert=True)118    try:119        values = await ultroid_bot(GetParticipantRequest(int(spli[1]), int(spli[0])))120        if isinstance(values.participant, ChannelParticipantLeft) or (121            isinstance(values.participant, ChannelParticipantBanned) and values.left122        ):123            raise UserNotParticipantError("")124    except UserNotParticipantError:125        return await e.answer(126            "Please Join That Channel !\nThen Click This Button !", alert=True127        )128    await ultroid_bot.edit_permissions(129        e.chat_id, int(spli[0]), send_messages=True, until_date=None130    )131    await e.edit(get_string("fsub_8"))132 133 134async def force_sub(ult):135    if not udB.get_key("FORCESUB"):136        return137    user = await ult.get_sender()138    joinchat = get_forcesetting(ult.chat_id)139    if (not joinchat) or (isinstance(user, User) and user.bot):140        return141    if CACHE.get(ult.chat_id):142        if CACHE[ult.chat_id].get(user.id):143            CACHE[ult.chat_id].update({user.id: CACHE[ult.chat_id][user.id] + 1})144        else:145            CACHE[ult.chat_id].update({user.id: 1})146    else:147        CACHE.update({ult.chat_id: {user.id: 1}})148    count = CACHE[ult.chat_id][user.id]149    if count == 11:150        CACHE[ult.chat_id][user.id] = 1151        return152    if count in range(2, 11):153        return154    try:155        await ultroid_bot.get_permissions(int(joinchat), user.id)156        return157    except UserNotParticipantError:158        pass159    if isinstance(user, Channel):160        try:161            await ultroid_bot.edit_permissions(162                ult.chat_id, user.id, view_messages=False163            )164            return165        except BaseException as er:166            LOGS.exception(er)167    try:168        await ultroid_bot.edit_permissions(ult.chat_id, user.id, send_messages=False)169    except ChatAdminRequiredError:170        return171    except Exception as e:172        await ult.delete()173        LOGS.info(e)174    res = await ultroid_bot.inline_query(asst.me.username, f"fsub {user.id}_{joinchat}")175    await res[0].click(ult.chat_id, reply_to=ult.id)176 177 178if udB.get_key("FORCESUB"):179    ultroid_bot.add_handler(force_sub, events.NewMessage(incoming=True))180