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