telegrinder 0.1.dev160__py3-none-any.whl → 0.1.dev162__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.
Potentially problematic release.
This version of telegrinder might be problematic. Click here for more details.
- telegrinder/api/abc.py +3 -0
- telegrinder/api/api.py +7 -5
- telegrinder/api/error.py +3 -3
- telegrinder/bot/bot.py +2 -2
- telegrinder/bot/cute_types/base.py +1 -4
- telegrinder/bot/cute_types/message.py +140 -0
- telegrinder/bot/dispatch/composition.py +1 -1
- telegrinder/bot/dispatch/dispatch.py +1 -1
- telegrinder/bot/dispatch/waiter_machine/short_state.py +1 -1
- telegrinder/bot/scenario/__init__.py +2 -2
- telegrinder/bot/scenario/checkbox.py +10 -15
- telegrinder/bot/scenario/choice.py +2 -2
- telegrinder/modules.py +5 -3
- telegrinder/msgspec_json.py +3 -3
- telegrinder/msgspec_utils.py +34 -35
- telegrinder/tools/__init__.py +6 -0
- telegrinder/tools/buttons.py +8 -13
- telegrinder/tools/formatting/__init__.py +6 -0
- telegrinder/tools/formatting/html.py +10 -0
- telegrinder/tools/formatting/links.py +7 -0
- telegrinder/tools/formatting/spec_html_formats.py +27 -15
- telegrinder/tools/keyboard.py +3 -3
- telegrinder/tools/loop_wrapper/abc.py +4 -4
- telegrinder/types/enums.py +4 -0
- telegrinder/types/methods.py +175 -41
- telegrinder/types/objects.py +425 -201
- {telegrinder-0.1.dev160.dist-info → telegrinder-0.1.dev162.dist-info}/METADATA +1 -1
- {telegrinder-0.1.dev160.dist-info → telegrinder-0.1.dev162.dist-info}/RECORD +30 -30
- {telegrinder-0.1.dev160.dist-info → telegrinder-0.1.dev162.dist-info}/WHEEL +1 -1
- {telegrinder-0.1.dev160.dist-info → telegrinder-0.1.dev162.dist-info}/LICENSE +0 -0
telegrinder/api/abc.py
CHANGED
|
@@ -17,6 +17,9 @@ class Token(str):
|
|
|
17
17
|
if token.count(":") != 1 or not token.split(":")[0].isdigit():
|
|
18
18
|
raise InvalidTokenError("Invalid token, it should look like this '123:ABC'.")
|
|
19
19
|
return super().__new__(cls, token)
|
|
20
|
+
|
|
21
|
+
def __repr__(self) -> str:
|
|
22
|
+
return f"<Token: {self.bot_id}:{''.join(self.split(':')[-1])[:6]}...>"
|
|
20
23
|
|
|
21
24
|
@classmethod
|
|
22
25
|
def from_env(
|
telegrinder/api/api.py
CHANGED
|
@@ -16,7 +16,7 @@ def compose_data(
|
|
|
16
16
|
data: dict[str, typing.Any],
|
|
17
17
|
files: dict[str, tuple[str, bytes]],
|
|
18
18
|
) -> typing.Any:
|
|
19
|
-
converter = DataConverter(files=files)
|
|
19
|
+
converter = DataConverter(files=files.copy())
|
|
20
20
|
return client.get_form(
|
|
21
21
|
data={k: converter(v) for k, v in data.items()},
|
|
22
22
|
files=converter.files,
|
|
@@ -24,7 +24,9 @@ def compose_data(
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class API(ABCAPI, APIMethods):
|
|
27
|
-
|
|
27
|
+
"""Bot API with available API methods."""
|
|
28
|
+
|
|
29
|
+
API_URL = "https://api.telegram.org/"
|
|
28
30
|
|
|
29
31
|
def __init__(self, token: Token, *, http: ABCClient | None = None) -> None:
|
|
30
32
|
self.token = token
|
|
@@ -32,9 +34,9 @@ class API(ABCAPI, APIMethods):
|
|
|
32
34
|
super().__init__(self)
|
|
33
35
|
|
|
34
36
|
def __repr__(self) -> str:
|
|
35
|
-
return "<{}:
|
|
37
|
+
return "<{}: token={!r}, http={!r}>".format(
|
|
36
38
|
self.__class__.__name__,
|
|
37
|
-
self.
|
|
39
|
+
self.token,
|
|
38
40
|
self.http,
|
|
39
41
|
)
|
|
40
42
|
|
|
@@ -60,7 +62,7 @@ class API(ABCAPI, APIMethods):
|
|
|
60
62
|
assert "result" in response
|
|
61
63
|
return Ok(response["result"])
|
|
62
64
|
return Error(APIError(
|
|
63
|
-
code=response.get("error_code",
|
|
65
|
+
code=response.get("error_code", 400),
|
|
64
66
|
error=response.get("description"),
|
|
65
67
|
))
|
|
66
68
|
|
telegrinder/api/error.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class APIError(BaseException):
|
|
2
|
-
def __init__(self, code: int, error: str | None = None):
|
|
2
|
+
def __init__(self, code: int, error: str | None = None) -> None:
|
|
3
3
|
self.code, self.error = code, error
|
|
4
4
|
|
|
5
5
|
def __str__(self) -> str:
|
|
6
|
-
return f"[{self.code}] {self.error}"
|
|
6
|
+
return f"[{self.code}] {self.error or 'Something went wrong'}"
|
|
7
7
|
|
|
8
8
|
def __repr__(self) -> str:
|
|
9
|
-
return f"<APIError {self.__str__()}>"
|
|
9
|
+
return f"<APIError: {self.__str__()}>"
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class InvalidTokenError(BaseException):
|
telegrinder/bot/bot.py
CHANGED
|
@@ -15,7 +15,7 @@ class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
|
|
|
15
15
|
dispatch: DispatchT
|
|
16
16
|
polling: PollingT
|
|
17
17
|
loop_wrapper: LoopWrapperT
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def __init__(
|
|
20
20
|
self,
|
|
21
21
|
api: API,
|
|
@@ -23,7 +23,7 @@ class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
|
|
|
23
23
|
polling: PollingT | None = None,
|
|
24
24
|
dispatch: DispatchT | None = None,
|
|
25
25
|
loop_wrapper: LoopWrapperT | None = None,
|
|
26
|
-
):
|
|
26
|
+
) -> None:
|
|
27
27
|
self.api = api
|
|
28
28
|
self.dispatch = dispatch or Dispatch() # type: ignore
|
|
29
29
|
self.polling = polling or Polling(api) # type: ignore
|
|
@@ -33,8 +33,6 @@ if typing.TYPE_CHECKING:
|
|
|
33
33
|
else:
|
|
34
34
|
|
|
35
35
|
class BaseCute(typing.Generic[UpdateT]):
|
|
36
|
-
api: ABCAPI
|
|
37
|
-
|
|
38
36
|
@classmethod
|
|
39
37
|
def from_update(cls, update, bound_api):
|
|
40
38
|
return cls(**update.to_dict(), api=bound_api)
|
|
@@ -115,8 +113,7 @@ def shortcut(
|
|
|
115
113
|
params[k] = kwargs.pop(k, p.default) if p.default is not p.empty else kwargs.pop(k)
|
|
116
114
|
|
|
117
115
|
return await executor(self, method_name, get_params(params))
|
|
118
|
-
|
|
119
|
-
func.__repr__ = lambda _: f"<Shortcut {method_name!r}@{func!r}>"
|
|
116
|
+
|
|
120
117
|
inner.__shortcut__ = Shortcut( # type: ignore
|
|
121
118
|
method_name=method_name,
|
|
122
119
|
executor=executor,
|