Ejemplo n.º 1
0
async def fstat(event):
    if event.is_group:
        if not await is_admin(event, event.sender_id):
            return await event.reply("You need to be an admin to do this!")
    args = event.pattern_match.group(2)
    if args:
        if len(args) > 12:
            info = sql.get_fed_info(args)
            if not info:
                return await event.reply(
                    "There is no federation with this FedID.")
            name = info["fname"]
            if event.reply_to_msg_id:
                msg = await event.get_reply_message()
                user_id = msg.sender_id
                fname = msg.sender.first_name
            else:
                user_id = event.sender_id
                fname = event.sender.first_name
            fban, fbanreason, fbantime = sql.get_fban_user(args, int(user_id))
            if not fban:
                return await event.reply(f"{fname} is not banned in this fed.")
            tym = fbantime
            k = f"{tym}"
            re = k[:4]
            rs = f"{k[:4]}/{k[-2:]}/{k[:6].replace(re, '')}"
            if fbanreason == '':
                text = f"{fname} is currently banned in {name}.\n\n**Date of Ban:** {rs}"
            if not fbanreason == '':
                text = f"{fname} is currently banned in {name},for the following **reason**:\n{fbanreason}\n\n**Date of Ban:** {rs}"
            return await event.reply(text)
        elif len(args) < 12:
            person = await get_user_from_event(event)
            user_id = person.id
            replied_user = await tbot(GetFullUserRequest(user_id))
            fname = replied_user.user.first_name
    else:
        if event.reply_to_msg_id:
            msg = await event.get_reply_message()
            user_id = msg.sender_id
            fname = msg.sender.first_name
        else:
            user_id = event.sender_id
            fname = event.sender.first_name
    mex = await event.reply(f"Checking fbans for {fname}...")
    uname, fbanlist = sql.get_user_fbanlist(str(user_id))
    if len(fbanlist) == 0:
        return await mex.edit(
            f"User {fname} hasn't been banned in any chats due to fedbans.")
    if len(fbanlist) <= 10:
        flist = f"The following federations have caused {fname} to be banned in chats:"
        for x in fbanlist:
            try:
                info = sql.get_fed_info(x[0])
                gname = info["fname"]
                flist += f"\n- `{x[0]}`:{gname}"
            except:
                pass
        await mex.edit(flist)
Ejemplo n.º 2
0
async def p(event):
    if event.is_private:
        return await event.reply(
            "This command is made to be run in a group where the person you would like to promote is present."
        )
    fedowner = sql.get_user_owner_fed_full(event.sender_id)
    if not fedowner:
        return await event.reply(
            "Only federation creators can promote people, and you don't seem to have a federation to promote to!"
        )
    args = await get_user_from_event(event)
    if not args:
        return await event.reply(
            "I don't know who you're talking about, you're going to need to specify a user...!"
        )
    chat = event.chat
    for f in fedowner:
        fed_id = f["fed_id"]
        name = f["fed"]["fname"]
    user_id = args.id
    fban, fbanreason, fbantime = sql.get_fban_user(fed_id, int(args.id))
    replied_user = await tbot(GetFullUserRequest(user_id))
    fname = replied_user.user.first_name
    print(69)
    if fban:
        if fbanreason != '':
            return await event.reply(
                f"User {fname} is fbanned in {name}. You should unfban them before promoting.\n\nReason:\n{fbanreason}"
            )
        else:
            return await event.reply(
                f"User {fname} is fbanned in {name}. You should unfban them before promoting."
            )
    getuser = sql.search_user_in_fed(fed_id, user_id)
    if getuser:
        return await event.reply(
            f"[{fname}](tg://user?id={args.id}) is already an admin in {name}!"
        )
    print(4)
    try:
        mk = f"{user_id}|{name[:5]}|{fed_id}"
        km = f"{user_id}|{event.sender_id}"
        await tbot.send_message(
            event.chat_id,
            f"Please get [{fname}](tg://user?id={args.id}) to confirm that they would like to be fed admin for {name}",
            buttons=[
                Button.inline("Confirm", data="fkfed_{}".format(mk)),
                Button.inline("Cancel", data="smex_{}".format(km)),
            ],
        )
    except Exception as e:
        print(e)
Ejemplo n.º 3
0
async def unfban(event):
    user = event.sender
    chat = event.chat_id
    if event.is_group:
        fed_id = sql.get_fed_id(chat)
        if not fed_id:
           return await event.reply("This chat isn't in any federations.")
    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 = "{}".format(f["fed_id"])
    info = sql.get_fed_info(fed_id)
    name = info["fname"]
    if is_user_fed_admin(fed_id, user.id) is False:
      return await event.reply(f"You aren't a federation admin for {name}!")
    input = event.pattern_match.group(1)
    if input:
      arg = input.split(" ", 1)
    if not event.reply_to_msg_id:
     if len(arg) == 2:
        iid = arg[0]
        reason = arg[1]
     else:
        iid = arg[0]
        reason = None
     if not iid.isnumeric():
        entity = await tbot.get_input_entity(iid)
        try:
          r_sender_id = entity.user_id
        except Exception:
           await event.reply("Couldn't fetch that user.")
           return
     else:
        r_sender_id = int(iid)
     try:
        replied_user = await tbot(GetFullUserRequest(r_sender_id))
        fname = replied_user.user.first_name
        username = replied_user.user.username
        lname = replied_user.user.last_name
     except Exception:
        fname = "User"
        username = None
        lname = None
    else:
        reply_message = await event.get_reply_message()
        iid = reply_message.sender_id
        fname = reply_message.sender.first_name
        lname = reply_message.sender.last_name
        username = reply_message.sender.username
        if input:
          reason = input
        else:
          reason = None
        r_sender_id = iid
    if r_sender_id == BOT_ID or r_sender_id == OWNER_ID:
        return await event.reply("Oh you're a funny one aren't you! How do you think I would have fbanned myself hm?.")
    name = info["fname"]
    fban_user_id = int(r_sender_id)
    fban_user_name = fname
    fban_user_lname = lname
    fban_user_uname = username
    fban, fbanreason, fbantime = sql.get_fban_user(fed_id, int(r_sender_id))
    if not fban:
      return await event.reply(f"This user isn't banned in the current federation, {name}. [{fed_id}]")
    temp = sql.un_fban_user(fed_id, fban_user_id)
    if temp:
      sxa = "**New un-FedBan**\n"
      sxa += f"**Fed:** {name}\n"
      sxa += f"**FedAdmin:** [{event.sender.first_name}](tg://user?id={event.sender_id})\n"
      sxa += f"**User:** [{fname}](tg://user?id={r_sender_id})\n"
      sxa += f"**User ID:** `{r_sender_id}`\n"
      if reason:
        sxa += f"**Reason:** {reason}"
      await tbot.send_message(
                event.chat_id,
                sxa)
      getfednotif = sql.user_feds_report(info["owner"])
      if getfednotif:
        if int(info["owner"]) != int(chat):
          await tbot.send_message(
                int(info["owner"]),
                sxa)
      get_fedlog = sql.get_fed_log(fed_id)
      if get_fedlog:
         if int(get_fedlog) != int(chat):
           await tbot.send_message(
                int(get_fedlog),
                sxa)
Ejemplo n.º 4
0
async def _(event):
    user = event.sender
    chat = event.chat_id
    if event.is_group:
        fed_id = sql.get_fed_id(chat)
        if not fed_id:
           return await event.reply("This chat isn't in any federations.")
    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 = "{}".format(f["fed_id"])
    info = sql.get_fed_info(fed_id)
    name = info["fname"]
    if is_user_fed_admin(fed_id, user.id) is False:
      return await event.reply(f"You aren't a federation admin for {name}!")
    input = event.pattern_match.group(1)
    if input:
      arg = input.split(" ", 1)
    if not event.reply_to_msg_id:
     if len(arg) == 2:
        iid = arg[0]
        reason = arg[1]
     else:
        iid = arg[0]
        reason = None
     if not iid.isnumeric():
        entity = await tbot.get_input_entity(iid)
        try:
          r_sender_id = entity.user_id
        except Exception:
           await event.reply("Couldn't fetch that user.")
           return
     else:
        r_sender_id = int(iid)
     try:
        replied_user = await tbot(GetFullUserRequest(r_sender_id))
        fname = replied_user.user.first_name
        username = replied_user.user.username
        lname = replied_user.user.last_name
     except Exception:
        fname = "User"
        username = None
        lname = None
    else:
        reply_message = await event.get_reply_message()
        iid = reply_message.sender_id
        fname = reply_message.sender.first_name
        lname = reply_message.sender.last_name
        username = reply_message.sender.username
        if input:
          reason = input
        else:
          reason = None
        r_sender_id = iid
    if r_sender_id == BOT_ID or r_sender_id == OWNER_ID:
        return await event.reply("Oh you're a funny one aren't you! I am _not_ going to fedban myself.")
    name = info["fname"]
    if is_user_fed_owner(fed_id, int(r_sender_id)) is True:
           return await event.reply(f"I'm not banning a fed admin from their own fed! [{name}]")
    if is_user_fed_admin(fed_id, int(r_sender_id)) is True:
           return await event.reply(f"I'm not banning a fed admin from their own fed! [{name}]")
    fban_user_id = int(r_sender_id)
    fban_user_name = fname
    fban_user_lname = lname
    fban_user_uname = username
    fban, fbanreason, fbantime = sql.get_fban_user(fed_id, int(r_sender_id))
    if fban:
      if fbanreason == '' and reason == None:
         return await event.reply(f'User [{fname}](tg://)/user?id={r_sender_id}) is already banned in {name}. There is no reason set for their fedban yet, so feel free to set one.')
      if reason == fbanreason:
         return await event.reply(f'User [{fname}](tg://user?id={r_sender_id}) has already been fbanned, with the exact same reason.')
      if reason == None:
       if fbanreason == '':
         return await event.reply(f'User [{fname}](tg://user?id={r_sender_id}) is already banned in {name}.')
       else:
         return await event.reply(f'User [{fname}](tg://user?id={r_sender_id}) is already banned in {name}, with reason:\n`{fbanreason}`.')
    if not fban:
       x = sql.fban_user(
                fed_id,
                fban_user_id,
                fban_user_name,
                fban_user_lname,
                fban_user_uname,
                reason,
                int(time.time()),
            )
       sax = "**New FedBan**\n"
       sax += f"**Fed:** {name}\n"
       sax += f"**FedAdmin:** [{event.sender.first_name}](tg://user?id={event.sender_id})\n"
       sax += f"**User:** [{fname}](tg://user?id={r_sender_id})\n"
       sax += f"**User ID:** `{r_sender_id}`\n"
       sax += f"**Reason:** {reason}"
    else:
            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()),
            )
            sax = "**FedBan Reason Update**\n"
            sax += f"**Fed:** {name}\n"
            sax += f"**FedAdmin:** [{event.sender.first_name}](tg://user?id={event.sender_id})\n"
            sax += f"**User:** [{fname}](tg://user?id={r_sender_id})\n"
            sax += f"**User ID:** `{r_sender_id}`\n"
            if not fbanreason == '':
              sax += f"**Previous Reason:** {fbanreason}\n"
            sax += f"**New Reason:** {reason}"
    await tbot.send_message(
                event.chat_id,
                sax)
    getfednotif = sql.user_feds_report(info["owner"])
    if getfednotif:
      if int(info["owner"]) != int(chat):
         await tbot.send_message(
                int(info["owner"]),
                sax)
    get_fedlog = sql.get_fed_log(fed_id)
    if get_fedlog:
        if int(get_fedlog) != int(chat):
           await tbot.send_message(
                int(get_fedlog),
                sax)
    fed_chats = list(sql.all_fed_chats(fed_id))
    if len(fed_chats) != 0:
        for fedschat in fed_chats:
                try:
                    await tbot(
                        EditBannedRequest(int(fedschat), int(fban_user_id), BANNED_RIGHTS)
                        )
                except Exception:
                    pass
    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(
                        EditBannedRequest(int(fedschat), int(fban_user_id), BANNED_RIGHTS)
                        )
                     except Exception:
                            continue