-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathecho.py
More file actions
72 lines (65 loc) · 2.38 KB
/
echo.py
File metadata and controls
72 lines (65 loc) · 2.38 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
from local_settings import bot_token, api_id, api_hash, dir_path
from tdLib.client import Client
client = Client()
def auth_callback(data):
print(data)
update_type = data.get("@type")
if update_type == "authorizationStateWaitTdlibParameters":
client.sendCommand(
{
"@type": "setTdlibParameters",
"parameters": {
"use_test_dc": False,
"api_id": api_id,
"api_hash": api_hash,
"device_model": "Desktop",
"system_version": "Unknown",
"application_version": "0.0",
"system_language_code": "en",
"database_directory": dir_path + "/tdLib/Database",
"files_directory": dir_path + "/tdLib/Files",
"use_file_database": True,
"use_chat_info_database": True,
"use_message_database": True,
"enable_storage_optimizer": False,
"ignore_file_names": True,
},
},
auth_callback,
)
elif update_type == "authorizationStateWaitEncryptionKey":
client.sendCommand(
{
"@type": "checkDatabaseEncryptionKey",
"encryption_key": "randomencryption",
},
auth_callback,
)
elif update_type == "authorizationStateWaitPhoneNumber":
client.sendCommand(
{"@type": "checkAuthenticationBotToken", "token": bot_token}, auth_callback
)
elif update_type == "ok":
client.sendCommand({"@type": "getAuthorizationState"}, auth_callback)
elif update_type == "authorizationStateReady":
pass # things begin here
def updateNewMessageListener(event_msg):
if event_msg["@type"] != "updateNewMessage":
return
if event_msg["message"]["is_outgoing"]:
return
chat_id = event_msg["message"]["chat_id"]
client.sendCommand(
{
"@type": "sendMessage",
"chat_id": chat_id,
"input_message_content": {
"@type": "inputMessageText",
"text": {"@type": "formattedText", "text": "Echo"},
},
}
)
pass
client.addListener(updateNewMessageListener)
client.sendCommand({"@type": "getAuthorizationState"}, auth_callback)
client.idle()