async def _(event):
    chat = event.chat
    args = await get_user_from_event(event)
    user = event.sender
    if args:
        pass
    else:
        return
    if event.is_group:
        if (await is_register_admin(event.input_chat, event.sender_id)):
            pass
        else:
            return
    if event.is_private:
        await event.reply(
            "This command is specific to the group, not to my pm !")
        return

    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id):
        userid = args
        if not userid:
            await event.reply("Reply to a message or give a entity to promote")
            return
        user_id = userid.id
        getuser = sql.search_user_in_fed(fed_id, user_id)
        fed_id = sql.get_fed_id(chat.id)
        info = sql.get_fed_info(fed_id)
        get_owner = eval(info['fusers'])['owner']
        try:
            async for userr in tbot.iter_participants(
                    event.chat_id, filter=types.ChannelParticipantsAdmins):
                if not isinstance(userr.participant,
                                  types.ChannelParticipantCreator):
                    aid = userr.id
                    if int(aid) == int(get_owner):
                        await event.reply("Hey that's the federation owner !")
                        return
        except Exception as e:
            print(e)
        if getuser:
            await event.reply(
                "I cannot promote users who are already federation admins! Can remove them if you want!"
            )
            return
        if int(user_id) == int(BOT_ID):
            await event.reply(
                "I already am a federation admin in all federations!")
            return
        res = sql.user_join_fed(fed_id, user_id)
        if res:
            await event.reply("Successfully Promoted!")
        else:
            await event.reply("Failed to promote!")
    else:
        await event.reply("Only federation owners can do this!")
Exemplo n.º 2
0
async def _(event):
    try:
        chat = event.chat
        args = event.pattern_match.group(1)
        user = event.sender
        if event.is_group:
            if (await is_register_admin(event.input_chat, event.sender_id)):
                pass
            else:
                return
        if args:
            fed_id = args
            info = sql.get_fed_info(fed_id)
        else:
            fed_id = sql.get_fed_id(chat.id)
            if not fed_id:
                await event.reply("This chat is not in any federation!")
                return
            info = sql.get_fed_info(fed_id)

        if not info:
            await event.reply(
                "Couldn't find information about that federation!")
            return

        # print(fed_id+"\n"+user.id)
        if is_user_fed_admin(fed_id, user.id) is False:
            await event.reply("Only federation admins can do this!")
            return

        text = "<b>Federation Admin {}:</b>\n\n".format(info['fname'])
        text += "👑 Owner:\n"
        owner = await tbot.get_entity(int(info['owner']))
        try:
            owner_name = owner.first_name + " " + owner.last_name
        except:
            owner_name = owner.first_name
        text += f" • <p><a href='tg://user?id={owner.id}'>{owner_name}</a></p>\n"

        members = sql.all_fed_members(fed_id)
        if len(members) == 0:
            text += "\n🔱 There are no admins in this federation"
        else:
            text += "\n🔱 Admin:\n"
            for x in members:
                user = await tbot.get_entity(int(x))
                unamee = user.first_name
                text += f" • <p><a href='tg://user?id={user.id}'>{unamee}</a></p>\n"

        await event.reply(text, parse_mode="html")

    except Exception as e:
        print(e)
async def _(event):
    try:
        chat = event.chat
        args = event.pattern_match.group(1)
        user = event.sender
        if event.is_group:
            if (await is_register_admin(event.input_chat, event.sender_id)):
                pass
            else:
                return
        if args:
            fed_id = args
            info = sql.get_fed_info(fed_id)
        else:
            fed_id = sql.get_fed_id(chat.id)
            if not fed_id:
                await event.reply("This chat is not in any federation!")
                return
            info = sql.get_fed_info(fed_id)

        if not info:
            await event.reply(
                "Couldn't find information about that federation!")
            return

        if is_user_fed_admin(fed_id, user.id) is False:
            await event.reply("Only a federation admin can do this!")
            return

        owner = await tbot.get_entity(int(info['owner']))
        try:
            owner_name = owner.first_name + " " + owner.last_name
        except:
            owner_name = owner.first_name
        FEDADMIN = sql.all_fed_users(fed_id)
        TotalAdminFed = len(FEDADMIN)

        text = "<b>ℹ️ Federation Information:</b>"
        text += "\nFedID: <code>{}</code>".format(fed_id)
        text += "\nName: {}".format(info['fname'])
        text += f"\nCreator: <p><a href='tg://user?id={owner.id}'>{owner_name}</a></p>"
        text += "\nAll Admins: <code>{}</code>".format(TotalAdminFed)
        getfban = sql.get_all_fban_users(fed_id)
        text += "\nTotal banned users: <code>{}</code>".format(len(getfban))
        getfchat = sql.all_fed_chats(fed_id)
        text += "\nNumber of groups in this federation: <code>{}</code>".format(
            len(getfchat))
        await event.reply(text, parse_mode="html")
    except Exception as e:
        print(e)
async def _(event):
    try:
        chat = event.chat
        user = event.sender
        args = event.pattern_match.group(1)
        if event.is_group:
            if (await is_register_admin(event.input_chat, event.sender_id)):
                pass
            else:
                return
        if event.is_private:
            await event.reply(
                "This command is specific to the group, not to my pm !")
            return

        fed_id = sql.get_fed_id(chat.id)

        if not fed_id:
            await event.reply("This group is not in any federation!")
            return

        if is_user_fed_admin(fed_id, user.id) is False:
            await event.reply("Only fed admins can do this!")
            return

        if args:
            x = sql.set_frules(fed_id, args)
            if not x:
                await event.reply(
                    "There was an error while setting federation rules!\nPlease go to @MissJuliaRobotSupport to report this."
                )
                return

            rules = sql.get_fed_info(fed_id)['frules']
            getfed = sql.get_fed_info(fed_id)
            get_fedlog = sql.get_fed_log(fed_id)
            if get_fedlog:
                if eval(get_fedlog):
                    await tbot.send_message(
                        get_fedlog,
                        "**{}** has updated federation rules for fed **{}**".
                        format(user.first_name, getfed['fname']),
                        parse_mode="markdown")
            await event.reply(f"Rules have been changed to :\n{rules}!")
        else:
            await event.reply("Please give some rules to set.")
    except Exception as e:
        print(e)
async def _(event):
    chat = event.chat
    # user = event.sender
    if event.is_group:
        if (await is_register_admin(event.input_chat, event.sender_id)):
            pass
        else:
            return
    fed_id = sql.get_fed_id(chat.id)
    if not fed_id:
        await event.reply("This group is not in any federation!")
        return
    info = sql.get_fed_info(fed_id)
    text = "This group is part of the following federation:"
    text += "\n{} (ID: <code>{}</code>)".format(info['fname'], fed_id)
    await event.reply(text, parse_mode="html")
async def _(event):
    chat = event.chat
    args = await get_user_from_event(event)
    user = event.sender
    if args:
        pass
    else:
        return

    if event.is_group:
        if (await is_register_admin(event.input_chat, event.sender_id)):
            pass
        else:
            return

    if event.is_private:
        await event.reply(
            "This command is specific to the group, not to my pm !")
        return

    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id):
        userid = args
        if not userid:
            await event.reply("Reply to a message or give a entity to promote")
            return
        user_id = userid.id

        if user_id == BOT_ID:
            await event.reply(
                "You can't demote me from a federation created by me !")
            return

        if sql.search_user_in_fed(fed_id, user_id) is False:
            await event.reply(
                "I cannot demote people who are not federation admins!")
            return

        res = sql.user_demote_fed(fed_id, user_id)
        if res is True:
            await event.reply("Demoted from Fed Admin!")
        else:
            await event.reply("Demotion failed!")
    else:
        await event.reply("Only federation owners can do this!")
        return
async def _(event):
    chat = event.chat
    user = event.sender
    if event.is_group:
        if (await is_register_admin(event.input_chat, event.sender_id)):
            pass
        else:
            return
    if event.is_private:
        await event.reply(
            "This command is specific to the group, not to my pm !")
        return

    fed_id = sql.get_fed_id(chat.id)
    fed_info = sql.get_fed_info(fed_id)

    if user.id == OWNER_ID:
        pass
    else:
        try:
            async for userr in tbot.iter_participants(
                    event.chat_id, filter=types.ChannelParticipantsAdmins):
                if not isinstance(userr.participant,
                                  types.ChannelParticipantCreator):
                    aid = userr.id
                    if int(event.sender_id) != int(aid):
                        await event.reply(
                            "Only group creators can use this command!")
                        return
        except Exception as e:
            print(e)
    if sql.chat_leave_fed(chat.id) is True:
        get_fedlog = sql.get_fed_log(fed_id)
        if get_fedlog:
            await tbot.send_message(
                get_fedlog,
                "Chat *{}* has left the federation *{}*".format(
                    chat.title, fed_info['fname']),
                parse_mode="markdown")
        await event.reply("This group has left the federation **{}**".format(
            fed_info['fname']))
    else:
        await event.reply(
            "How can you leave a federation that you never joined ?")
async def _(event):
    chat = event.chat
    if event.is_group:
        if (await is_register_admin(event.input_chat, event.sender_id)):
            pass
        else:
            return
    if event.is_private:
        await event.reply(
            "This command is specific to the group, not to my pm !")
        return

    fed_id = sql.get_fed_id(chat.id)
    if not fed_id:
        await event.reply("This group is not in any federation!")
        return

    rules = sql.get_frules(fed_id)
    text = "**Rules for this fed:**\n\n"
    text += rules
    await event.reply(text)
Exemplo n.º 9
0
async def _(event):
    try:
        chat = event.chat
        user = event.sender
        args = event.pattern_match.group(1)
        if event.is_group:
            if (await is_register_admin(event.input_chat, event.sender_id)):
                pass
            else:
                return
        if event.is_private:
            await event.reply(
                "This command is specific to the group, not to my pm !")
            return
        if not args:
            await event.reply("Where is the federation ID ?")
            return

        fed_id = sql.get_fed_id(chat.id)

        if user.id in OWNER_ID:
            pass
        else:
            try:
                async for userr in tbot.iter_participants(
                        event.chat_id, filter=types.ChannelParticipantAdmins):
                    if not isinstance(userr.participant,
                                      types.ChannelParticipantCreator):
                        aid = userr.id
                        if int(event.sender_id) == int(aid):
                            await event.reply(
                                "Only group creators can use this command!")
                            return
            except Exception as e:
                print(e)
        if fed_id:
            await event.reply("You cannot join two federations from one chat")
            return

        if len(args) >= 1:
            getfed = sql.search_fed_by_id(args)
            if getfed is False:
                await event.reply("Please enter a valid federation ID")
                return

            x = sql.chat_join_fed(args, chat.title, chat.id)
            if not x:
                await event.reply(
                    "Failed to join federation! Please contact @MissJuliaRobotSupport should this problem persist!"
                )
                return

            get_fedlog = sql.get_fed_log(args)
            if get_fedlog:
                if eval(get_fedlog):
                    await tbot.send_message(
                        get_fedlog,
                        "Chat *{}* has joined the federation *{}*".format(
                            chat.title, getfed['fname']),
                        parse_mode="markdown")

            await event.reply(
                "This group has joined the federation: {}!".format(
                    getfed['fname']))
    except Exception as e:
        print(e)
async def _(event):
    try:
        chat = event.chat
        args = event.pattern_match.group(1)
        user = event.sender
        if event.is_group:
            if (await is_register_admin(event.input_chat, event.sender_id)):
                pass
            else:
                return
        if event.is_private:
            await event.reply(
                "This command is specific to the group, not to my pm !")
            return

        fed_id = sql.get_fed_id(chat.id)

        if not fed_id:
            await event.reply("This group is not a part of any federation!")
            return

        info = sql.get_fed_info(fed_id)
        getfednotif = sql.user_feds_report(info['owner'])

        if is_user_fed_admin(fed_id, user.id) is False:
            await event.reply("Only federation admins can do this!")
            return

        if "|" in args:
            iid, reasonn = args.split("|")
        cid = iid.strip()
        reason = reasonn.strip()
        if cid.isnumeric():
            cid = int(cid)
        entity = await tbot.get_input_entity(cid)
        try:
            user_id = entity.user_id
        except Exception:
            await event.reply("Couldn't fetch that user.")
            return
        if not reason:
            await event.reply("Need a reason for fban.")
            return
        fban, fbanreason, fbantime = sql.get_fban_user(fed_id, user_id)

        if not user_id:
            await event.reply("You don't seem to be referring to a user")
            return

        if user_id == BOT_ID:
            await event.reply("Haha you can't fban me.")
            return

        if is_user_fed_owner(fed_id, user_id) is True:
            await event.reply("You are the fed owner.\nI will not fban you !")
            return

        if is_user_fed_admin(fed_id, user_id) is True:
            await event.reply("That's a federation admin, I can't fban.")
            return

        if user_id == OWNER_ID:
            await event.reply("Haha i will never fban my owner !")
            return

        if user_id in [777000, 1087968824]:
            await event.reply("Fool! You can't attack Telegram's native tech!")
            return

        try:
            user_chat = await tbot.get_entity(user_id)
            isvalid = True
            fban_user_id = user_chat.id
            fban_user_name = user_chat.first_name
            fban_user_lname = user_chat.last_name
            fban_user_uname = user_chat.username
        except Exception as e:
            if not str(user_id).isdigit():
                await event.reply(e)
                return
            elif len(str(user_id)) != 9:
                await event.reply("That's not a user!")
                return
            isvalid = False
            fban_user_id = int(user_id)
            fban_user_name = "user({})".format(user_id)
            fban_user_lname = None
            fban_user_uname = None

        if isvalid and not isinstance(user_chat, User):
            await event.reply("That's not a user!")
            return

        if isvalid:
            user_target = f"<p><a href='tg://user?id={fban_user_id}'>{fban_user_name}</a></p>"
        else:
            user_target = fban_user_name

        if fban:
            fed_name = info['fname']
            temp = sql.un_fban_user(fed_id, fban_user_id)
            if not temp:
                await event.reply("Failed to update the reason for fedban!")
                return
            x = sql.fban_user(fed_id, fban_user_id, fban_user_name,
                              fban_user_lname, fban_user_uname, reason,
                              int(time.time()))
            if not x:
                await event.reply(
                    "Failed to ban from the federation! If this problem continues, contact @MissJuliaRobotSupport."
                )
                return

            fed_chats = sql.all_fed_chats(fed_id)
            # Will send to current chat
            await tbot.send_message(chat.id, "<b>FedBan reason updated</b>" \
                  "\n<b>Federation:</b> {}" \
                  "\n<b>Federation Admin:</b> {}" \
                  "\n<b>User:</b> {}" \
                  "\n<b>User ID:</b> <code>{}</code>" \
                  "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html")
            # Send message to owner if fednotif is enabled
            if getfednotif:
                await tbot.send_message(info['owner'], "<b>FedBan reason updated</b>" \
                     "\n<b>Federation:</b> {}" \
                     "\n<b>Federation Admin:</b> {}" \
                     "\n<b>User:</b> {}" \
                     "\n<b>User ID:</b> <code>{}</code>" \
                     "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html")
            # If fedlog is set, then send message, except fedlog is current chat
            get_fedlog = sql.get_fed_log(fed_id)
            if get_fedlog:
                if int(get_fedlog) != int(chat.id):
                    await tbot.send_message(get_fedlog, "<b>FedBan reason updated</b>" \
                        "\n<b>Federation:</b> {}" \
                        "\n<b>Federation Admin:</b> {}" \
                        "\n<b>User:</b> {}" \
                        "\n<b>User ID:</b> <code>{}</code>" \
                        "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html")
            for fedschat in fed_chats:
                try:
                    await tbot.kick_participant(fedschat, fban_user_id)
                except Exception as e:
                    print(e)

            # Fban for fed subscriber
            subscriber = list(sql.get_subscriber(fed_id))
            if len(subscriber) != 0:
                for fedsid in subscriber:
                    all_fedschat = sql.all_fed_chats(fedsid)
                    for fedschat in all_fedschat:
                        try:
                            await tbot.kick_participant(fedschat, fban_user_id)
                        except Exception as e:
                            print(e)
                            continue
            return

        fed_name = info['fname']

        x = sql.fban_user(fed_id, fban_user_id, fban_user_name,
                          fban_user_lname, fban_user_uname, reason,
                          int(time.time()))
        if not x:
            await event.reply(
                "Failed to ban from the federation! If this problem continues, contact @OnePunchSupport."
            )
            return

        fed_chats = sql.all_fed_chats(fed_id)
        # Will send to current chat
        await tbot.send_message(chat.id, "<b>FedBan reason updated</b>" \
              "\n<b>Federation:</b> {}" \
              "\n<b>Federation Admin:</b> {}" \
              "\n<b>User:</b> {}" \
              "\n<b>User ID:</b> <code>{}</code>" \
              "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html")
        # Send message to owner if fednotif is enabled
        if getfednotif:
            await tbot.send_message(info['owner'], "<b>FedBan reason updated</b>" \
                 "\n<b>Federation:</b> {}" \
                 "\n<b>Federation Admin:</b> {}" \
                 "\n<b>User:</b> {}" \
                 "\n<b>User ID:</b> <code>{}</code>" \
                 "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html")
        # If fedlog is set, then send message, except fedlog is current chat
        get_fedlog = sql.get_fed_log(fed_id)
        if get_fedlog:
            if int(get_fedlog) != int(chat.id):
                await tbot.send_message(get_fedlog, "<b>FedBan reason updated</b>" \
                    "\n<b>Federation:</b> {}" \
                    "\n<b>Federation Admin:</b> {}" \
                    "\n<b>User:</b> {}" \
                    "\n<b>User ID:</b> <code>{}</code>" \
                    "\n<b>Reason:</b> {}".format(fed_name, f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p>", user_target, fban_user_id, reason), parse_mode="html")
        chats_in_fed = 0
        for fedschat in fed_chats:
            chats_in_fed += 1
            try:
                await tbot.kick_participant(fedschat, fban_user_id)
            except Exception as e:
                print(e)

            # Fban for fed subscriber
            subscriber = list(sql.get_subscriber(fed_id))
            if len(subscriber) != 0:
                for fedsid in subscriber:
                    all_fedschat = sql.all_fed_chats(fedsid)
                    for fedschat in all_fedschat:
                        try:
                            await tbot.kick_participant(fedschat, fban_user_id)
                        except Exception as e:
                            print(e)
    except Exception as e:
        print(e)