1
|
|
|
# Copyright Pincer 2021-Present |
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root. |
3
|
|
|
|
4
|
|
|
""" |
5
|
|
|
sent when a user's voice state changes in a subscribed voice channel |
6
|
|
|
(mute, volume, etc.) |
7
|
|
|
""" |
8
|
|
|
from __future__ import annotations |
9
|
|
|
|
10
|
|
|
from typing import TYPE_CHECKING |
11
|
|
|
|
12
|
|
|
from ..objects.user.voice_state import VoiceState |
13
|
|
|
|
14
|
|
|
if TYPE_CHECKING: |
15
|
|
|
from typing import List, Tuple |
16
|
|
|
|
17
|
|
|
from ..client import Client |
18
|
|
|
from ..core.gateway import Gateway |
19
|
|
|
from ..core.gateway import GatewayDispatch |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
async def voice_state_update_middleware( |
23
|
|
|
self: Client, gateway: Gateway, payload: GatewayDispatch |
|
|
|
|
24
|
|
|
) -> Tuple[str, List[VoiceState]]: |
25
|
|
|
"""|coro| |
26
|
|
|
Middleware for the ``on_voice_state_update`` event. |
27
|
|
|
|
28
|
|
|
Parameters |
29
|
|
|
---------- |
30
|
|
|
payload : :class:`~pincer.core.gateway.GatewayDispatch` |
31
|
|
|
The data received from the voice state update event. |
32
|
|
|
gateway : :class:`~pincer.core.gateway.Gateway` |
33
|
|
|
The gateway for the current shard. |
34
|
|
|
|
35
|
|
|
Returns |
36
|
|
|
------- |
37
|
|
|
Tuple[:class:`str`, :class:`~pincer.objects.user.voice_state.VoiceState`] |
38
|
|
|
``on_voice_state_update`` and a ``VoiceState`` |
39
|
|
|
""" # noqa: E501 |
40
|
|
|
|
41
|
|
|
voice_state = VoiceState.from_dict(payload.data) |
42
|
|
|
guild = self.guilds.get(voice_state.guild_id) |
43
|
|
|
|
44
|
|
|
if guild: |
45
|
|
|
for index, state in enumerate(guild.voice_states): |
46
|
|
|
if state.user_id == voice_state.user_id: |
47
|
|
|
guild.voice_states[index] = voice_state |
48
|
|
|
break |
49
|
|
|
else: |
50
|
|
|
guild.voice_states.append(voice_state) |
51
|
|
|
|
52
|
|
|
return "on_voice_state_update", voice_state |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
def export(): |
|
|
|
|
56
|
|
|
return voice_state_update_middleware |
57
|
|
|
|