telegrinder 0.1.dev158__py3-none-any.whl → 0.1.dev159__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.

@@ -1,22 +1,29 @@
1
+ import typing
2
+
1
3
  from fntypes.co import Nothing, Some
2
4
 
3
5
  from telegrinder.api import ABCAPI
4
6
  from telegrinder.msgspec_utils import Option
5
- from telegrinder.types import Update, UpdateType
7
+ from telegrinder.types import Model, Update
6
8
 
7
9
  from .base import BaseCute
8
10
 
11
+ ModelT = typing.TypeVar("ModelT", bound=Model)
12
+
9
13
 
10
14
  class UpdateCute(BaseCute[Update], Update, kw_only=True):
11
15
  api: ABCAPI
12
16
 
13
17
  @property
14
- def update_type(self) -> Option[UpdateType]:
15
- for name, update in self.to_dict(
16
- exclude_fields={"update_id"},
17
- ).items():
18
- if update is not None:
19
- return Some(UpdateType(name))
18
+ def incoming_update(self) -> Model:
19
+ return getattr(
20
+ self,
21
+ self.update_type.expect("Update object has no incoming update.").value,
22
+ )
23
+
24
+ def get_event(self, event_model: type[ModelT]) -> Option[ModelT]:
25
+ if isinstance(self.incoming_update, event_model):
26
+ return Some(self.incoming_update)
20
27
  return Nothing()
21
28
 
22
29