|
| 1 | +# Hydrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2023-present Hydrogram <https://hydrogram.org> |
| 3 | +# |
| 4 | +# This file is part of Hydrogram. |
| 5 | +# |
| 6 | +# Hydrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Hydrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from __future__ import annotations |
| 20 | + |
| 21 | +from typing import TYPE_CHECKING |
| 22 | + |
| 23 | +from hydrogram.types.object import Object |
| 24 | + |
| 25 | +if TYPE_CHECKING: |
| 26 | + from hydrogram import raw |
| 27 | + |
| 28 | + |
| 29 | +class Session(Object): |
| 30 | + """Contains info about a device session. |
| 31 | +
|
| 32 | + Parameters: |
| 33 | + id (``int``): |
| 34 | + Session id. |
| 35 | +
|
| 36 | + device_model (``str``): |
| 37 | + Device model used for authorization. |
| 38 | +
|
| 39 | + platform (``str``): |
| 40 | + Platform used for authorization. |
| 41 | +
|
| 42 | + system_version (``str``): |
| 43 | + System version used for authorization. |
| 44 | +
|
| 45 | + api_id (``int``): |
| 46 | + API ID used for authorization. |
| 47 | +
|
| 48 | + app_name (``str``): |
| 49 | + App name used for authorization. |
| 50 | +
|
| 51 | + app_version (``str``): |
| 52 | + App version used for authorization. |
| 53 | +
|
| 54 | + date_created (``int``): |
| 55 | + Date when authorization was created. |
| 56 | +
|
| 57 | + date_active (``int``): |
| 58 | + Date when authorization was last active. |
| 59 | +
|
| 60 | + ip (``str``): |
| 61 | + IP address used for authorization. |
| 62 | +
|
| 63 | + country (``str``): |
| 64 | + Country where authorization occurred. |
| 65 | +
|
| 66 | + region (``str``): |
| 67 | + Region where authorization occurred. |
| 68 | +
|
| 69 | + is_current (``bool``): |
| 70 | + Whether this is the current authorization. |
| 71 | +
|
| 72 | + is_official_app (``bool``): |
| 73 | + Whether this is an official app. |
| 74 | +
|
| 75 | + is_password_pending (``bool``): |
| 76 | + Whether a password is pending. |
| 77 | +
|
| 78 | + accepts_secret_chats (``bool``): |
| 79 | + Whether secret chat requests are allowed. |
| 80 | +
|
| 81 | + accepts_calls (``bool``): |
| 82 | + Whether call requests are allowed. |
| 83 | +
|
| 84 | + is_confirmed (``bool``): |
| 85 | + Whether the authorization is confirmed. |
| 86 | + """ |
| 87 | + |
| 88 | + def __init__( |
| 89 | + self, |
| 90 | + *, |
| 91 | + id: int, |
| 92 | + device_model: str, |
| 93 | + platform: str, |
| 94 | + system_version: str, |
| 95 | + api_id: int, |
| 96 | + app_name: str, |
| 97 | + app_version: str, |
| 98 | + date_created: int, |
| 99 | + date_active: int, |
| 100 | + ip: str, |
| 101 | + country: str, |
| 102 | + region: str, |
| 103 | + is_current: bool, |
| 104 | + is_official_app: bool, |
| 105 | + is_password_pending: bool, |
| 106 | + accepts_secret_chats: bool, |
| 107 | + accepts_calls: bool, |
| 108 | + is_confirmed: bool, |
| 109 | + ): |
| 110 | + super().__init__() |
| 111 | + |
| 112 | + self.id = id |
| 113 | + self.device_model = device_model |
| 114 | + self.platform = platform |
| 115 | + self.system_version = system_version |
| 116 | + self.api_id = api_id |
| 117 | + self.app_name = app_name |
| 118 | + self.app_version = app_version |
| 119 | + self.date_created = date_created |
| 120 | + self.date_active = date_active |
| 121 | + self.ip = ip |
| 122 | + self.country = country |
| 123 | + self.region = region |
| 124 | + self.is_current = is_current |
| 125 | + self.is_official_app = is_official_app |
| 126 | + self.is_password_pending = is_password_pending |
| 127 | + self.accepts_secret_chats = accepts_secret_chats |
| 128 | + self.accepts_calls = accepts_calls |
| 129 | + self.is_confirmed = is_confirmed |
| 130 | + |
| 131 | + @staticmethod |
| 132 | + def _parse(authorization: raw.types.Authorization) -> Session: |
| 133 | + return Session( |
| 134 | + id=authorization.hash, |
| 135 | + device_model=authorization.device_model, |
| 136 | + platform=authorization.platform, |
| 137 | + system_version=authorization.system_version, |
| 138 | + api_id=authorization.api_id, |
| 139 | + app_name=authorization.app_name, |
| 140 | + app_version=authorization.app_version, |
| 141 | + date_created=authorization.date_created, |
| 142 | + date_active=authorization.date_active, |
| 143 | + ip=authorization.ip, |
| 144 | + country=authorization.country, |
| 145 | + region=authorization.region, |
| 146 | + is_current=authorization.current, |
| 147 | + is_official_app=authorization.official_app, |
| 148 | + is_password_pending=authorization.password_pending, |
| 149 | + accepts_secret_chats=not authorization.encrypted_requests_disabled, |
| 150 | + accepts_calls=not authorization.call_requests_disabled, |
| 151 | + is_confirmed=not authorization.unconfirmed, |
| 152 | + ) |
0 commit comments