Exemplo n.º 1
0
async def info(event):
    if not event.is_private:
        if not await is_admin(event, event.sender_id):
            return await event.reply(
                "This command can only be used in private.")
    input = event.pattern_match.group(1)
    fedowner = sql.get_user_owner_fed_full(event.sender_id)
    if not input:
        if not fedowner:
            return await event.reply(
                "You need to give me a FedID to check, or be a federation creator to use this command!"
            )
    if input:
        fed_id = input
        info = sql.get_fed_info(fed_id)
        if not info:
            return await event.reply("There is no federation with this FedID.")
        name = info["fname"]
    elif fedowner:
        for f in fedowner:
            fed_id = f["fed_id"]
            name = f["fed"]["fname"]
        info = sql.get_fed_info(fed_id)
    if info:
        owner = int(info["owner"])
        getfban = sql.get_all_fban_users(fed_id)
        getfchat = sql.all_fed_chats(fed_id)
        FEDADMIN = sql.all_fed_users(fed_id)
        TotalAdminFed = len(FEDADMIN)

        caption = "Fed info:\n"
        caption += f"FedID: `{fed_id}`\n"
        caption += f"Name: {name}\n"
        caption += f"Creator: [this person](tg://user?id={owner}) (`{owner}`)\n"
        caption += f"Number of admins: `{TotalAdminFed}`\n"
        caption += f"Number of bans: `{len(getfban)}`\n"
        caption += f"Number of connected chats: `{len(getfchat)}`\n"
        try:
            subs = sql.get_subscriber(fed_id)
        except:
            subs = []
        caption += f"Number of subscribed feds: `{len(subs)}`"
        try:
            getmy = sql.get_mysubs(fed_id)
        except:
            getmy = []
        if len(getmy) == 0:
            caption += "\n\nThis federation is not subscribed to any other feds."
        else:
            caption += "\n\nSubscribed to the following feds:"
            for x in getmy:
                nfo = sql.get_fed_info(x)
                nme = nfo["fname"]
                caption += f"\n- {nme} (`{x}`)"
        buttons = Button.inline("Check Fed Admins",
                                data="fedadm_{}".format(fed_id))
        await tbot.send_message(event.chat_id, caption, buttons=buttons)
Exemplo n.º 2
0
async def fex(event):
 if event.is_group:
  fed_id = sql.get_fed_id(event.chat_id)
  if not fed_id:
       return await event.reply("This chat isn't in any federations.")
  else:
     if is_user_fed_owner(fed_id, int(event.sender_id)) is False:
        return await event.reply("Only the fed creator can export the ban list.")
 else:
  fedowner = sql.get_user_owner_fed_full(event.sender_id)
  if not fedowner:
          return await event.reply("It doesn't look like you have a federation yet!")
  for f in fedowner:
          fed_id = f["fed_id"]
 info = sql.get_fed_info(fed_id)
 name = info["fname"]
 getfban = sql.get_all_fban_users(fed_id)
 if len(getfban) == 0:
  return await event.reply(f"There are no banned users in {name}")
 backups = ""
 try:
            for users in getfban:
                getuserinfo = sql.get_all_fban_users_target(fed_id, users)
                json_parser = {
                    "user_id": users,
                    "first_name": getuserinfo["first_name"],
                    "last_name": getuserinfo["last_name"],
                    "user_name": getuserinfo["user_name"],
                    "reason": getuserinfo["reason"],
                }
                backups += json.dumps(json_parser)
                backups += "\n"
            with BytesIO(str.encode(backups)) as output:
                output.name = "fbanned_users.csv"
                await tbot.send_file(
                    event.chat_id,
                    file=output,
                    filename="fbanned_users.json",
                    caption="Fbanned users in \n** {}**.".format(
                        info["fname"]
                    ),
                )
 except Exception as e:
  print(e)