mm-telegram 0.0.8__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mm_telegram/__init__.py
CHANGED
mm_telegram/simple_message.py
CHANGED
@@ -1,58 +1,31 @@
|
|
1
1
|
import asyncio
|
2
|
-
import time
|
3
2
|
|
4
|
-
import
|
5
|
-
from mm_std import Err, Ok, Result, hr, hra
|
3
|
+
from mm_std import Result, http_request
|
6
4
|
|
7
5
|
|
8
|
-
def send_message(bot_token: str, chat_id: int, message: str, long_message_delay: int = 3) -> Result[list[int]]:
|
6
|
+
async def send_message(bot_token: str, chat_id: int, message: str, long_message_delay: int = 3) -> Result[list[int]]:
|
9
7
|
messages = _split_string(message, 4096)
|
10
8
|
responses = []
|
11
9
|
result = []
|
12
10
|
while True:
|
13
11
|
text = messages.pop(0)
|
14
12
|
params = {"chat_id": chat_id, "text": text}
|
15
|
-
res =
|
16
|
-
responses.append(res.
|
17
|
-
if res.
|
18
|
-
return
|
13
|
+
res = await http_request(f"https://api.telegram.org/bot{bot_token}/sendMessage", method="post", json=params)
|
14
|
+
responses.append(res.to_dict())
|
15
|
+
if res.is_err():
|
16
|
+
return Result.err(res.error or "error", extra={"responses": [responses]})
|
19
17
|
|
20
|
-
message_id =
|
18
|
+
message_id = res.parse_json_body("result.message_id", none_on_error=True)
|
21
19
|
if message_id:
|
22
20
|
result.append(message_id)
|
23
21
|
else:
|
24
|
-
return
|
25
|
-
|
26
|
-
if len(messages):
|
27
|
-
time.sleep(long_message_delay)
|
28
|
-
else:
|
29
|
-
break
|
30
|
-
return Ok(result, data={"responses": responses})
|
31
|
-
|
32
|
-
|
33
|
-
async def async_send_message(bot_token: str, chat_id: int, message: str, long_message_delay: int = 3) -> Result[list[int]]:
|
34
|
-
messages = _split_string(message, 4096)
|
35
|
-
responses = []
|
36
|
-
result = []
|
37
|
-
while True:
|
38
|
-
text = messages.pop(0)
|
39
|
-
params = {"chat_id": chat_id, "text": text}
|
40
|
-
res = await hra(f"https://api.telegram.org/bot{bot_token}/sendMessage", method="post", params=params)
|
41
|
-
responses.append(res.json)
|
42
|
-
if res.error is not None:
|
43
|
-
return Err(res.error, data={"last_res": res.to_dict(), "responses": responses})
|
44
|
-
|
45
|
-
message_id = pydash.get(res.json, "result.message_id")
|
46
|
-
if message_id:
|
47
|
-
result.append(message_id)
|
48
|
-
else:
|
49
|
-
return Err("unknown_response", data={"last_res": res.to_dict(), "responses": responses})
|
22
|
+
return Result.err("unknown_response", extra={"responses": responses})
|
50
23
|
|
51
24
|
if len(messages):
|
52
25
|
await asyncio.sleep(long_message_delay)
|
53
26
|
else:
|
54
27
|
break
|
55
|
-
return
|
28
|
+
return Result.ok(result, extra={"responses": responses})
|
56
29
|
|
57
30
|
|
58
31
|
def _split_string(text: str, chars_per_string: int) -> list[str]:
|
@@ -0,0 +1,6 @@
|
|
1
|
+
mm_telegram/__init__.py,sha256=Nl5I50id12u28Q0H_uHziyd2t_bjySeZAH1etBOVW3A,57
|
2
|
+
mm_telegram/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
mm_telegram/simple_message.py,sha256=fT0zhmUPqq_w2EvTdOKLC0JhVMh3nZmthApY8dmY_fk,1193
|
4
|
+
mm_telegram-0.1.1.dist-info/METADATA,sha256=8Iusxz_r-QCJMu7dN8BNW9VN2EFNUZBxO3G0NwNYnEc,108
|
5
|
+
mm_telegram-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
+
mm_telegram-0.1.1.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
mm_telegram/__init__.py,sha256=Lt7dNthxAyeswHnf72il9uFGq1c083CA9c8OCRZU0jY,126
|
2
|
-
mm_telegram/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
mm_telegram/simple_message.py,sha256=O0ubcTHBBCruByDr6l9DiL14BeVQFeBHTYyURz1ckRc,2175
|
4
|
-
mm_telegram-0.0.8.dist-info/METADATA,sha256=MixRPCFyPcPOddqHb1f2bIzkKgjBWCwJpVrRV-SxEv4,109
|
5
|
-
mm_telegram-0.0.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
-
mm_telegram-0.0.8.dist-info/RECORD,,
|
File without changes
|