|
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 __future__ import annotations |
|
10
|
|
|
|
|
11
|
|
|
from typing import TYPE_CHECKING |
|
12
|
|
|
|
|
13
|
|
|
from ..objects.events.notification import NotificationCreateEvent |
|
14
|
|
|
from ..utils.types import Coro |
|
15
|
|
|
|
|
16
|
|
|
if TYPE_CHECKING: |
|
17
|
|
|
from ..client import Client |
|
18
|
|
|
from ..core.gateway import Gateway |
|
19
|
|
|
from ..core.gateway import GatewayDispatch |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
async def notification_create_middleware( |
|
23
|
|
|
self: Client, gateway: Gateway, payload: GatewayDispatch |
|
|
|
|
|
|
24
|
|
|
): |
|
25
|
|
|
"""|coro| |
|
26
|
|
|
|
|
27
|
|
|
Middleware for the ``on_notification_create`` event. |
|
28
|
|
|
|
|
29
|
|
|
Parameters |
|
30
|
|
|
---------- |
|
31
|
|
|
payload : :class:`~pincer.core.gateway.GatewayDispatch` |
|
32
|
|
|
The data received from the notification create event. |
|
33
|
|
|
gateway : :class:`~pincer.core.gateway.Gateway` |
|
34
|
|
|
The gateway for the current shard. |
|
35
|
|
|
|
|
36
|
|
|
Returns |
|
37
|
|
|
------- |
|
38
|
|
|
Tuple[:class:`str`, :class:`~pincer.objects.events.notification.NotificationCreateEvent`] |
|
39
|
|
|
``on_notification_create`` and a ``NotificationCreateEvent`` |
|
40
|
|
|
""" # noqa: E501 |
|
41
|
|
|
channel_id = payload.data.get("channel_id") |
|
42
|
|
|
payload.data["message"]["channel_id"] = channel_id |
|
43
|
|
|
return ( |
|
44
|
|
|
"on_notification_create", |
|
45
|
|
|
NotificationCreateEvent.from_dict(payload.data), |
|
46
|
|
|
) |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
def export() -> Coro: |
|
|
|
|
|
|
50
|
|
|
return notification_create_middleware |
|
51
|
|
|
|