-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (33 loc) · 1.2 KB
/
main.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
from typing import Optional
from mainloop import MainLoop
from telegram.auth.api import APIAuth
from telegram.auth.base import StaticSecrets
from telegram.auth.schemes.live import TelegramProduction
from telegram.client import TelegramClient
from telegram.tgmodules.getcode import GetAuthCode
from telegram.tgmodules.savecontacts import SaveContacts
from telegram.tgmodules.userinfo import UserInfo
from telegram.util import Environment
def main():
core = MainLoop(Environment.Production)
def clientForClosure(phonenumber, username: Optional[str]=None, secrets: Optional[StaticSecrets]=None):
scheme = TelegramProduction(core.API_ID, core.API_HASH, "accounts/" + phonenumber, secrets, True)
return TelegramClient(APIAuth(phonenumber, scheme), [
UserInfo(
phonenumber,
core.accounts,
username,
),
SaveContacts(core.db, phonenumber),
GetAuthCode()
])
async def onStart():
for account in await core.accounts.getAccounts():
await core.addClient(clientForClosure(
account.phone_number,
account.username,
None if account.two_factor_password is None else StaticSecrets(account.two_factor_password)
))
core.mainLoop(onStart, clientForClosure)
if __name__ == "__main__":
main()