-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.py
40 lines (36 loc) · 1 KB
/
usage.py
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
import pyrogram.errors
import pyrogram.client
import tg_api_gen
import asyncio
async def authorise(client):
phone = input('phone: ')
code = await client.send_code(
phone_number = phone
)
print(code)
try:
return await client.sign_in(
phone_number = phone,
phone_code_hash = code.phone_code_hash,
phone_code = input('code: '),
)
except pyrogram.errors.SessionPasswordNeeded:
return await client.check_password(
password = input('password: ')
)
async def main():
client = pyrogram.client.Client(
name = 'my_client_name',
**tg_api_gen.generate_random(),
)
await client.connect()
try:
user = await client.get_me()
print('user already authorised')
except:
print('user is not authorised yet, authorising...')
user = await authorise(client)
print(user)
await client.send_message('me', 'hello world')
await client.stop()
asyncio.run(main())