Passed
Pull Request — main (#195)
by
unknown
01:36
created

pincer.middleware.guild.guild_create_middleware()   A

Complexity

Conditions 1

Size

Total Lines 20
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 20
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# Copyright Pincer 2021-Present
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
"""Guild events"""
5
6
from pincer.middleware import guild_members_chunk
0 ignored issues
show
Bug introduced by
The name guild_members_chunk does not seem to exist in module pincer.middleware.
Loading history...
7
from ..core.dispatch import GatewayDispatch
8
from ..objects.events.guild import GuildBanAddEvent, GuildBanRemoveEvent, GuildEmojisUpdateEvent, GuildIntegrationsUpdateEvent, GuildMemberAddEvent, GuildMemberRemoveEvent, GuildMemberUpdateEvent, GuildMembersChunkEvent, GuildRoleCreateEvent, GuildRoleDeleteEvent, GuildRoleUpdateEvent, GuildStatusEvent , GuildStickersUpdateEvent 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Unused Code introduced by
Unused GuildRoleUpdateEvent imported from objects.events.guild
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (330/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
No space allowed before comma
Loading history...
9
from ..utils import Coro
10
from ..objects import Guild, Channel
11
from ..utils.conversion import construct_client_dict
12
from __future__ import annotations
0 ignored issues
show
introduced by
standard import "from __future__ import annotations" should be placed before "from pincer.middleware import guild_members_chunk"
Loading history...
introduced by
__future__ import is not the first non docstring statement
Loading history...
13
from ..objects.guild import Guild, UnavailableGuild
0 ignored issues
show
Unused Code introduced by
The import Guild was already done on line 10. You should be able to
remove this line.
Loading history...
14
15
from typing import TYPE_CHECKING
0 ignored issues
show
introduced by
standard import "from typing import TYPE_CHECKING" should be placed before "from pincer.middleware import guild_members_chunk"
Loading history...
16
17
if TYPE_CHECKING:
18
    from typing import List, Tuple
19
    from ..core.dispatch import GatewayDispatch
0 ignored issues
show
Unused Code introduced by
The import GatewayDispatch was already done on line 7. You should be able to
remove this line.
Loading history...
20
21
22
async def guild_create_middleware(self, payload: GatewayDispatch):
23
    """|coro|
24
25
    Middleware for ``on_guild_create``,
26
        generate the guild class that was created
27
28
    Parameters
29
    ----------
30
    payload : :class:`GatewayDispatch`
31
        The data received from the guild create event
32
33
    Returns
34
    -------
35
    Tuple[:class:`str`, List[:class:`~pincer.objects.guild.Guild`]]
36
37
        ``on_guild_create`` and a ``Guild``
38
    """
39
    guild = Guild.from_dict(construct_client_dict(self, payload.data))
40
    self.guilds[guild.id] = guild
41
    return "on_guild_create", [guild]
42
43
44
async def guild_ban_add_middleware(self, payload: GatewayDispatch):
45
    """|coro|
46
47
    Middleware for ``on_guild_ban_add`` event.
48
49
    Parameters
50
    ----------
51
    payload : :class:`GatewayDispatch`
52
        The data received from the guild ban add event.
53
54
    Returns
55
    -------
56
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildBaAddEvent`]]
57
        ``on_guild_ban_add_update`` and a ``GuildBanAddEvent``
58
    """
59
60
    return (
61
        "on_guild_ban_add",
62
        [GuildBanAddEvent.from_dict(construct_client_dict(self, payload.data))],
63
    )
64
65
async def guild_unban_middleware(self, payload: GatewayDispatch):
66
    """|coro|
67
68
    Middleware for ``on_guild_ban_remove`` event.
69
70
    Parameters
71
    ----------
72
    payload : :class:`GatewayDispatch`
73
        The data received from the guild ban remove event.
74
75
    Returns
76
    -------
77
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildBanRemoveEvent`]]
78
        ``on_guild_ban_remove_update`` and a ``GuildBanRemoveEvent``
79
    """
80
81
    return (
82
        "on_guild_ban_remove",
83
        [GuildBanRemoveEvent.from_dict(construct_client_dict(self, payload.data))],
84
    )
85
86
async def guild_delete_middleware(self, payload: GatewayDispatch):
87
    """|coro|
88
89
    Middleware for ``on_guild_delete`` event.
90
91
    Parameters
92
    ----------
93
    payload : :class:`GatewayDispatch`
94
        The data received from the guild delete event.
95
96
    Returns
97
    -------
98
    Tuple[:class:`str`, List[:class:`~pincer.objects.guild.guild.UnavailableGuild`]]
99
        ``on_guild_delete`` and an ``UnavailableGuild``
100
    """
101
    guild = UnavailableGuild.from_dict(construct_client_dict(self, payload.data))
102
103
    if guild.id in self.guilds.key():
104
        self.guilds.pop(guild.id)
105
106
    return "on_guild_delete", [guild]
107
108
async def guild_emojis_update_middleware(self, payload: GatewayDispatch):
109
    """|coro|
110
111
    Middleware for ``on_guild_emojis_update`` event.
112
113
    Parameters
114
    ----------
115
    payload : :class:`GatewayDispatch`
116
        The data received from the guild emojis update event.
117
118
    Returns
119
    -------
120
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildEmojisUpdateEvent`]]
121
        ``on_guild_emoji_update`` and a ``GuildEmojisUpdateEvent``
122
    """
123
124
    return (
125
        "on_guild_emojis_update",
126
        [
127
            GuildEmojisUpdateEvent.from_dict(
128
                construct_client_dict(self, payload.data)
129
            )
130
        ],
131
    )
132
133
async def guild_integrations_update_middleware(self, payload: GatewayDispatch):
134
    """|coro|
135
136
    Middleware for ``on_guild_integrations_update`` event.
137
138
    Parameters
139
    ----------
140
    payload : :class:`GatewayDispatch`
141
        The data received from the guild integrations update event.
142
143
    Returns
144
    -------
145
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildIntegrationsUpdateEvent`]]
146
        ``on_guild_integration_update`` and a ``GuildIntegrationsUpdateEvent``
147
    """
148
149
    return (
150
        "on_guild_integrations_update",
151
        [
152
            GuildIntegrationsUpdateEvent.from_dict(
153
                construct_client_dict(self, payload.data)
154
            )
155
        ],
156
    )
157
158
async def guild_member_add_middleware(self, payload: GatewayDispatch):
159
    """|coro|
160
161
    Middleware for ``on_guild_member_add`` event.
162
163
    Parameters
164
    ----------
165
    payload : :class:`GatewayDispatch`
166
        The data received from the guild member add event.
167
168
    Returns
169
    -------
170
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildMemberAddEvent`]]
171
        ``on_guild_member_add`` and a ``GuildMemberAddEvent``
172
    """
173
174
    return "on_guild_member_add", [
175
        GuildMemberAddEvent.from_dict(construct_client_dict(self, payload.data))
176
    ]
177
178
async def guild_member_remove_middleware(self, payload: GatewayDispatch):
179
    """|coro|
180
181
    Middleware for ``on_guild_member_remove`` event.
182
183
    Parameters
184
    ----------
185
    payload : :class:`GatewayDispatch`
186
        The data received from the guild member remove event.
187
188
    Returns
189
    -------
190
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildMemberRemoveEvent`]]
191
        ``on_guild_member_remove`` and a ``GuildMemberRemoveEvent``
192
    """
193
194
    return (
195
        "on_guild_member_remove",
196
        [GuildMemberRemoveEvent.from_dict(construct_client_dict(self, payload.data))],
197
    )
198
199
async def guild_member_update_middleware(self, payload: GatewayDispatch):
200
    """|coro|
201
202
    Middleware for ``on_guild_member_update`` event.
203
204
    Parameters
205
    ----------
206
    payload : :class:`GatewayDispatch`
207
        The data received from the guild member update event.
208
209
    Returns
210
    -------
211
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildMemberUpdateEvent`]]
212
        ``on_guild_member_update`` and a ``GuildMemberUpdateEvent``
213
    """
214
215
    return (
216
        "on_guild_member_update",
217
        [GuildMemberUpdateEvent.from_dict(construct_client_dict(self, payload.data))],
218
    )
219
220
async def guild_member_chunk_middleware(self, payload: GatewayDispatch):
221
    """|coro|
222
223
    Middleware for ``on_guild_member_chunk`` event.
224
225
    Parameters
226
    ----------
227
    payload : :class:`GatewayDispatch`
228
        The data received from the guild member chunk event.
229
230
    Returns
231
    -------
232
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildMemberChunkEvent`]]
233
        ``on_guild_member_chunk`` and a ``GuildMemberChunkEvent``
234
    """
235
236
    return (
237
        "on_guild_member_chunk",
238
        [GuildMembersChunkEvent.from_dict(
239
            construct_client_dict(self, payload.data)
240
        )]
241
    )
242
243
async def guild_role_create_middleware(self, payload: GatewayDispatch):
244
    """|coro|
245
246
    Middleware for ``on_guild_role_create`` event.
247
248
    Parameters
249
    ----------
250
    payload : :class:`GatewayDispatch`
251
        The data received from the guild role create event.
252
253
    Returns
254
    -------
255
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildRoleCreateEvent`]]
256
        ``on_guild_role_create`` and a ``GuildRoleCreateEvent``
257
    """
258
259
    return (
260
        "on_guild_role_create",
261
        [GuildRoleCreateEvent.from_dict(construct_client_dict(self, payload.data))],
262
    )
263
264
async def guild_role_delete_middleware(self, payload: GatewayDispatch):
265
    """|coro|
266
267
    Middleware for ``on_guild_role_delete`` event.
268
269
    Parameters
270
    ----------
271
    payload : :class:`GatewayDispatch`
272
        The data received from the guild role delete event.
273
274
    Returns
275
    -------
276
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildRoleDeleteEvent`]]
277
        ``on_guild_role_delete`` and a ``GuildRoleDeleteEvent``
278
    """
279
280
    return (
281
        "on_guild_role_delete",
282
        [GuildRoleDeleteEvent.from_dict(construct_client_dict(self, payload.data))],
283
    )
284
285
async def guild_update_middleware(self, payload: GatewayDispatch):
286
    """|coro|
287
288
    Middleware for ``on_guild_update`` event.
289
290
    Parameters
291
    ----------
292
    payload : :class:`GatewayDispatch`
293
        The data received from the guild update event.
294
295
    Returns
296
    -------
297
    Tuple[:class:`str`, List[:class:`~pincer.objects.guild.guild.Guild`]]
298
        ``on_guild_Update`` and an ``Guild``
299
    """
300
301
    channel_list = payload.data.pop("channels", [])
302
303
    channels: List[Channel] = [
304
        Channel.from_dict(construct_client_dict(self, channel))
305
        for channel in channel_list
306
    ]
307
308
    guild = Guild.from_dict(construct_client_dict(
309
        self,
310
        {"channels": channels, **payload.data}
311
    ))
312
    self.guild[guild.id] = guild
313
314
    return "on_guild_update", [guild]
315
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
316
async def guild_stickers_update_middleware(self, payload: GatewayDispatch):
317
    """|coro|
318
319
    Middleware for ``on_guild_stickers_update`` event.
320
321
    Parameters
322
    ----------
323
    payload : :class:`GatewayDispatch`
324
        The data received from the guild stickers update event.
325
326
    Returns
327
    -------
328
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildStickersUpdateEvent`]]
329
        ``on_guild_sticker_update`` and a ``GuildStickersUpdateEvent``
330
    """
331
332
    return (
333
        "on_guild_stickers_update",
334
        [
335
            GuildStickersUpdateEvent.from_dict(
336
                construct_client_dict(self, payload.data)
337
            )
338
        ],
339
    )
340
341
async def guild_status_middleware(self, payload: GatewayDispatch):
342
    """|coro|
343
344
    Middleware for ``on_guild_status`` event.
345
346
    Parameters
347
    ----------
348
    payload : :class:`GatewayDispatch`
349
        The data received from the guild status event.
350
351
    Return
352
    ------
353
    Tuple[:class:`str`, List[:class:`~pincer.objects.events.guild.GuildStatusEvent`]]
354
        ``on_guild_status`` and a ``GuildStatusEvent``
355
    """
356
    return "on_guild_status", [
357
        GuildStatusEvent.from_dict(construct_client_dict(self, payload.data))
358
    ]
359
360
361
def export() -> Coro:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
362
    return guild_ban_add_middleware, guild_unban_middleware, guild_create_middleware, guild_delete_middleware, guild_emojis_update_middleware, guild_member_add_middleware, guild_integrations_update_middleware, guild_member_remove_middleware, guild_member_update_middleware, guild_members_chunk, guild_role_create_middleware, guild_update_middleware, guild_stickers_update_middleware, guild_status_middleware
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (407/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...