Alialdlfy1 commited on
Commit
e928aa0
·
verified ·
1 Parent(s): b35a9c9

Delete runtime_probe.py

Browse files
Files changed (1) hide show
  1. runtime_probe.py +0 -171
runtime_probe.py DELETED
@@ -1,171 +0,0 @@
1
- """Standalone, read-only Telegram diagnostic probe.
2
-
3
- This file is not imported or called by any bot component. It reads the existing
4
- API_ID, API_HASH, SESSION_STRING, and BOT_TOKEN environment variables without
5
- printing their values.
6
-
7
- The clients are created in memory, so this probe does not create or modify a
8
- local Pyrogram session file. It does not send, delete, edit, or forward
9
- messages, and it does not join or leave any chat.
10
- """
11
-
12
- import asyncio
13
- import logging
14
- import os
15
- from typing import Optional
16
-
17
- from pyrogram import Client
18
-
19
-
20
- CHANNEL_ID = -1001210871112
21
-
22
- # Suppress library logs so stdout contains only diagnostic output.
23
- logging.basicConfig(level=logging.CRITICAL)
24
- for logger_name in ("pyrogram", "pyrogram.session", "pyrogram.client"):
25
- logging.getLogger(logger_name).setLevel(logging.CRITICAL)
26
-
27
-
28
- def safe_error(error: Exception, secrets: tuple[str, ...]) -> str:
29
- """Return complete exception text while redacting known secret values."""
30
- text = f"{type(error).__name__}: {error}"
31
- for secret in secrets:
32
- if secret:
33
- text = text.replace(secret, "[REDACTED]")
34
- return text
35
-
36
-
37
- async def main() -> None:
38
- api_id_text = os.environ.get("API_ID")
39
- api_hash = os.environ.get("API_HASH")
40
- session_string = os.environ.get("SESSION_STRING")
41
- bot_token = os.environ.get("BOT_TOKEN")
42
-
43
- missing = [
44
- name
45
- for name, value in (
46
- ("API_ID", api_id_text),
47
- ("API_HASH", api_hash),
48
- ("SESSION_STRING", session_string),
49
- ("BOT_TOKEN", bot_token),
50
- )
51
- if not value
52
- ]
53
- if missing:
54
- print("CONFIG_FAIL")
55
- print("missing_variables=" + ",".join(missing))
56
- return
57
-
58
- try:
59
- api_id = int(api_id_text)
60
- except ValueError as error:
61
- print("CONFIG_FAIL")
62
- print("API_ID must be an integer")
63
- print(safe_error(error, (api_hash, session_string, bot_token)))
64
- return
65
-
66
- secrets = (api_hash, session_string, bot_token)
67
- user_client: Optional[Client] = None
68
- bot_client: Optional[Client] = None
69
-
70
- try:
71
- user_client = Client(
72
- "runtime_probe_user",
73
- api_id=api_id,
74
- api_hash=api_hash,
75
- session_string=session_string,
76
- in_memory=True,
77
- )
78
- bot_client = Client(
79
- "runtime_probe_bot",
80
- api_id=api_id,
81
- api_hash=api_hash,
82
- bot_token=bot_token,
83
- in_memory=True,
84
- )
85
-
86
- await user_client.start()
87
-
88
- try:
89
- me = await user_client.get_me()
90
- print("USER_ME_OK")
91
- print(f"user_id={me.id}")
92
- print(f"username={me.username}")
93
- except Exception as error:
94
- print("USER_ME_FAIL")
95
- print(safe_error(error, secrets))
96
-
97
- try:
98
- chat = await user_client.get_chat(CHANNEL_ID)
99
- print("USER_GET_CHAT_OK")
100
- print(f"chat_id={chat.id}")
101
- print(f"title={chat.title}")
102
- print(f"username={chat.username}")
103
- print(f"type={chat.type}")
104
- except Exception as error:
105
- print("USER_GET_CHAT_FAIL")
106
- print(safe_error(error, secrets))
107
-
108
- try:
109
- messages = [
110
- message
111
- async for message in user_client.get_chat_history(
112
- CHANNEL_ID,
113
- limit=1,
114
- )
115
- ]
116
- if messages:
117
- print("USER_HISTORY_OK")
118
- print(f"latest_message_id={messages[0].id}")
119
- else:
120
- print("USER_HISTORY_FAIL")
121
- print("No message was returned")
122
- except Exception as error:
123
- print("USER_HISTORY_FAIL")
124
- print(safe_error(error, secrets))
125
-
126
- try:
127
- dialog_found = False
128
- async for dialog in user_client.get_dialogs():
129
- if dialog.chat and dialog.chat.id == CHANNEL_ID:
130
- dialog_found = True
131
- print("USER_DIALOG_FOUND")
132
- print(f"id={dialog.chat.id}")
133
- print(f"title={dialog.chat.title}")
134
- break
135
- if not dialog_found:
136
- print("USER_DIALOG_NOT_FOUND")
137
- except Exception as error:
138
- print("USER_DIALOG_NOT_FOUND")
139
- print(safe_error(error, secrets))
140
-
141
- await bot_client.start()
142
-
143
- try:
144
- chat = await bot_client.get_chat(CHANNEL_ID)
145
- print("BOT_GET_CHAT_OK")
146
- print(f"chat_id={chat.id}")
147
- print(f"title={chat.title}")
148
- print(f"username={chat.username}")
149
- print(f"type={chat.type}")
150
- except Exception as error:
151
- print("BOT_GET_CHAT_FAIL")
152
- print(safe_error(error, secrets))
153
-
154
- finally:
155
- if bot_client is not None:
156
- try:
157
- if bot_client.is_connected:
158
- await bot_client.stop()
159
- except Exception:
160
- pass
161
- if user_client is not None:
162
- try:
163
- if user_client.is_connected:
164
- await user_client.stop()
165
- except Exception:
166
- pass
167
-
168
-
169
- if __name__ == "__main__":
170
- asyncio.run(main())
171
-