Total Complexity | 2 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
2 | # Full MIT License can be found in `LICENSE` at the project root. |
||
3 | |||
4 | """ |
||
5 | sent when the client receives a notification |
||
6 | (mention or new message in eligible channels) |
||
7 | """ |
||
8 | |||
9 | from ..core.dispatch import GatewayDispatch |
||
10 | from ..objects.events.notification import NotificationCreateEvent |
||
11 | from ..utils.conversion import construct_client_dict |
||
12 | from ..utils.types import Coro |
||
13 | |||
14 | |||
15 | async def notification_create_middleware(self, payload: GatewayDispatch): |
||
16 | """|coro| |
||
17 | |||
18 | Middleware for ``on_notification_create`` event. |
||
19 | |||
20 | Parameters |
||
21 | ---------- |
||
22 | payload : :class:`GatewayDispatch` |
||
23 | The data received from the notification create event. |
||
24 | |||
25 | Returns |
||
26 | ------- |
||
27 | Tuple[:class:`str`, List[:class:`~pincer.objects.events.notification.NotificationCreateEvent`]] |
||
28 | ``on_notification_create`` and a ``NotificationCreateEvent`` |
||
29 | """ |
||
30 | channel_id: int = payload.data.get("channel_id") |
||
31 | payload.data["message"]["channel_id"] = channel_id |
||
32 | return "on_notification_create", [ |
||
33 | NotificationCreateEvent.from_dict(construct_client_dict(self, payload.data)) |
||
34 | ] |
||
35 | |||
36 | |||
37 | def export() -> Coro: |
||
|
|||
38 | return notification_create_middleware |
||
39 |