Beispiel #1
0
def get_user_bio(client: Client,
                 uid: int,
                 normal: bool = False,
                 printable: bool = False) -> Optional[str]:
    # Get user's bio
    result = None
    try:
        user_id = resolve_peer(client, uid)
        if not user_id:
            return None

        flood_wait = True
        while flood_wait:
            flood_wait = False
            try:
                user: UserFull = client.send(GetFullUser(id=user_id))
                if user and user.about:
                    result = t2t(user.about, normal, printable)
            except FloodWait as e:
                flood_wait = True
                wait_flood(e)
    except Exception as e:
        logger.warning(f"Get user {uid} bio error: {e}", exc_info=True)

    return result
Beispiel #2
0
def get_full_user_row(member: ChatMember):
    fully: UserFull = app.send(GetFullUser(id=app.resolve_peer(member.user.id)))
    joined_date = None
    if member.date:
        joined_date = datetime.fromtimestamp(member.date).astimezone().isoformat()
    return [
        fully.user.id,
        joined_date,
        member.status,
        None if fully.user.photo else "Unset",
        fully.user.first_name,
        fully.user.last_name,
        fully.user.username,
        fully.about,
    ]
Beispiel #3
0
def get_user_full(client: Client, uid: int) -> Optional[UserFull]:
    # Get a full user
    result = None

    try:
        user_id = resolve_peer(client, uid)

        if not user_id:
            return None

        result = client.send(GetFullUser(id=user_id))
    except FloodWait as e:
        raise e
    except Exception as e:
        logger.warning(f"Get user {uid} full error: {e}", exc_info=True)

    return result
Beispiel #4
0
def get_user(app: Client, member: ChatMember, get_bio=False):
    joined_date = None
    if member.joined_date:
        joined_date = datetime \
            .fromtimestamp(member.joined_date) \
            .astimezone() \
            .isoformat()
    bio = None
    if get_bio:
        fully: UserFull = app.send(
            GetFullUser(id=app.resolve_peer(member.user.id)))
        bio = fully.about
    return {
        "User ID": str(member.user.id),
        "Joined Date": joined_date,
        "Status": member.status,
        "Photo": None if member.user.photo else "Unset",
        "First name": member.user.first_name,
        "Last name": member.user.last_name,
        "Username": member.user.username,
        "Bio": bio,
    }
Beispiel #5
0
 def _get_command_list(self) -> List[BotCommand]:
     return self.client.send(GetFullUser(id=self.peer)).bot_info.commands
Beispiel #6
0
def get_full_user(app, tg_id_or_username):
    peer_user = app.resolve_peer(tg_id_or_username)
    if not isinstance(peer_user, InputPeerUser):
        return
    return app.send(GetFullUser(id=peer_user))