Exemple #1
0
async def smex_fed(event):
  chat = event.chat_id
  tata = event.pattern_match.group(1)
  data = tata.decode()
  input = data.split("_", 1)[1]
  user, owner= input.split("|")
  user = user.strip()
  cname = owner.strip()
  fedowner = sql.get_user_owner_fed_full(int(cname))
  for f in fedowner:
          fed_id = f["fed_id"]
          name = f["fed"]["fname"]
  rt = await tbot(GetFullUserRequest(int(user)))
  tr = await tbot(GetFullUserRequest(int(cname)))
  fname = rt.user.first_name
  dname = tr.user.first_name
  if not event.sender_id == int(user):
    return await event.answer("This action is not intended for you!.")
  res = sql.tr_fed(fed_id, int(user))
  if not res:
    return await event.edit("Fed transfer failed!")
  if res:
    ses = sql.user_join_fed(fed_id, int(cname))
    sql.user_demote_fed(fed_id, int(user))
    text = f"Congratulations! Federation {name} ({fed_id}) has successfully been transferred from [{dname}](tg://user?id={cname}) to [{fname}](tg://user?id={user})"
    await event.edit(text, buttons=None)
  sxa = "**Fed Transfer**\n"
  sxa += f"**Fed:** {name}\n"
  sxa += f"**New Fed Owner:** [{fname}](tg://user?id={user}) - `{user}`\n"
  sxa += f"**Old Fed Owner:** [{dname}](tg://user?id={cname}) - `{cname}`\n"
  sxa += f"\n[{fname}](tg://user?id={user}) is now the fed owner. They can promote/demote admins as they like."
  getfednotif = sql.user_feds_report(int(user))
  await tbot.send_message(event.chat_id, sxa)
  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)
Exemple #2
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(2)
    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)
Exemple #3
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}!")
    pop = event.pattern_match.group(1)
    if not event.reply_to_msg_id:
      if not pop:
        return await event.reply("I don't know who you're talking about, you're going to need to specify a user...!")
    if not event.reply_to_msg_id:
     art = event.pattern_match.group(1)
     if art:
      arg = art.split(" ", 1)
     if len(arg) == 2:
        iid = arg[0]
        reason = arg[1]
     else:
        iid = arg[0]
        reason = None
     input = reason
     if reason and len(input) > 1024:
         reason = reason[:1024]
     else:
         reason = reason
     if not iid.isnumeric():
        entity = await tbot.get_input_entity(iid)
        try:
          r_sender_id = entity.user_id
        except Exception:
           await event.reply("I don't know who you're talking about, you're going to need to specify a 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 = f"user(`{r_sender_id}`)"
        username = None
        lname = None
    else:
        input = event.pattern_match.group(1)
        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:
           if len(input) > 1024:
               reason = input[:1024]
           else:
               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 the fed owner 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:
       current_datetime = datetime.now(pytz.timezone("Asia/Kolkata"))
       kuk =  f"{current_datetime}"
       mal = kuk[:10]
       rec = mal.replace("-", "")
       x = sql.fban_user(
                fed_id,
                fban_user_id,
                fban_user_name,
                fban_user_lname,
                fban_user_uname,
                reason,
                int(rec),
            )
       if input and len(input) >= 1024:
         shrunk = "\n\nNote: The fban reason was over 1024 characters, so has been truncated."
       else:
         shrunk = ''
       if reason == None:
          reason = 'None given.'
       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}{shrunk}"
    else:
            if input and len(input) >= 1024:
               shrunk = "\n\nNote: The fban reason was over 1024 characters, so has been truncated."
            else:
               shrunk = ''
            current_datetime = datetime.now(pytz.timezone("Asia/Kolkata"))
            kuk =  f"{current_datetime}"
            mal = kuk[:10]
            rec = mal.replace("-", "")
            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(rec),
            )
            if reason == None:
                reason = 'None given.'
            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}{shrunk}"
    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:
                 x = sql.fban_user(
                fedsid,
                fban_user_id,
                fban_user_name,
                fban_user_lname,
                fban_user_uname,
                reason,
                int(rec),
                  )
                 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