Passed
Push — main ( f2fd3d...7a88f3 )
by
unknown
02:16 queued 15s
created

VoiceChannel.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass
7
from enum import IntEnum
8
from typing import Dict, Optional, List, TYPE_CHECKING, Union, overload
9
10
from ..._config import GatewayConfig
11
from ...utils.api_object import APIObject
12
from ...utils.types import MISSING
13
14
if TYPE_CHECKING:
15
    from ..guild.overwrite import Overwrite
16
    from ..guild.thread import ThreadMetadata
17
    from ..guild.member import GuildMember
18
    from ..user import User
19
    from ... import Client
20
    from ...core.http import HTTPClient
21
    from ...utils import APINullable, Snowflake, Timestamp
22
23
24
class ChannelType(IntEnum):
25
    """Represents a channel its type."""
26
    GUILD_TEXT = 0
27
    DM = 1
28
    GUILD_VOICE = 2
29
    GROUP_DM = 3
30
    GUILD_CATEGORY = 4
31
    GUILD_NEWS = 5
32
    GUILD_STORE = 6
33
34
    if GatewayConfig.version >= 9:
35
        GUILD_NEWS_THREAD = 10
36
        GUILD_PUBLIC_THREAD = 11
37
        GUILD_PRIVATE_THREAD = 12
38
39
    GUILD_STAGE_VOICE = 13
40
41
42
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (28/7)
Loading history...
43
class Channel(APIObject):
44
    """
45
    Represents a Discord Channel Mention object
46
47
    :param _client:
48
        reference to the Client
49
50
    :param _http:
51
        reference to the HTTPClient
52
53
    :param id:
54
        the id of this channel
55
56
    :param type:
57
        the type of channel
58
59
    :param application_id:
60
        application id of the group DM creator if it is bot-created
61
62
    :param bitrate:
63
        the bitrate (in bits) of the voice channel
64
65
    :param default_auto_archive_duration:
66
        default duration for newly created threads, in minutes, to
67
        automatically archive the thread after recent activity, can be set to:
68
        60, 1440, 4320, 10080
69
70
    :param guild_id:
71
        the id of the guild (may be missing for some channel objects received
72
        over gateway guild dispatches)
73
74
    :param icon:
75
        icon hash
76
    :param last_message_id:
77
        the id of the last message sent in this channel (may not point to an
78
        existing or valid message)
79
80
    :param last_pin_timestamp:
81
        when the last pinned message was pinned. This may be null in events
82
        such as GUILD_CREATE when a message is not pinned.
83
84
    :param member:
85
        thread member object for the current user, if they have joined the
86
        thread, only included on certain API endpoints
87
88
    :param member_count:
89
        an approximate count of users in a thread, stops counting at 50
90
91
    :param message_count:
92
        an approximate count of messages in a thread, stops counting at 50
93
94
    :param name:
95
        the name of the channel (1-100 characters)
96
97
    :param nsfw:
98
        whether the channel is nsfw
99
100
    :param owner_id:
101
        id of the creator of the group DM or thread
102
103
    :param parent_id:
104
        for guild channels: id of the parent category for a channel (each
105
        parent category can contain up to 50 channels), for threads: id of the
106
        text channel this thread was created
107
108
    :param permissions:
109
        computed permissions for the invoking user in the channel, including
110
        overwrites, only included when part of the resolved data received on a
111
        slash command interaction
112
113
    :param permission_overwrites:
114
        explicit permission overwrites for members and roles
115
116
    :param position:
117
        sorting position of the channel
118
119
    :param rate_limit_per_user:
120
        amount of seconds a user has to wait before sending another message
121
        (0-21600); bots, as well as users with the permission manage_messages
122
        or manage_channel, are unaffected
123
124
    :param recipients:
125
        the recipients of the DM
126
127
    :param rtc_region:
128
        voice region id for the voice channel, automatic when set to null
129
130
    :param thread_metadata:
131
        thread-specific fields not needed by other channels
132
133
    :param topic:
134
        the channel topic (0-1024 characters)
135
136
    :param user_limit:
137
        the user limit of the voice channel
138
139
    :param video_quality_mode:
140
        the camera video quality mode of the voice channel, 1 when not present
141
    """
142
143
    _client: Client
0 ignored issues
show
introduced by
The variable Client does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
144
    _http: HTTPClient
0 ignored issues
show
introduced by
The variable HTTPClient does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
145
146
    id: Snowflake
0 ignored issues
show
introduced by
The variable Snowflake does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
147
    type: ChannelType
148
149
    application_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
The variable APINullable does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
150
    bitrate: APINullable[int] = MISSING
151
    default_auto_archive_duration: APINullable[int] = MISSING
152
    guild_id: APINullable[Snowflake] = MISSING
153
    icon: APINullable[Optional[str]] = MISSING
154
155
    last_message_id: APINullable[Optional[Snowflake]] = MISSING
156
    last_pin_timestamp: APINullable[Optional[Timestamp]] = MISSING
0 ignored issues
show
introduced by
The variable Timestamp does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
157
    member: APINullable[GuildMember] = MISSING
0 ignored issues
show
introduced by
The variable GuildMember does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
158
159
    member_count: APINullable[int] = MISSING
160
161
    message_count: APINullable[int] = MISSING
162
163
    name: APINullable[str] = MISSING
164
    nsfw: APINullable[bool] = MISSING
165
    owner_id: APINullable[Snowflake] = MISSING
166
    parent_id: APINullable[Optional[Snowflake]] = MISSING
167
    permissions: APINullable[str] = MISSING
168
    permission_overwrites: APINullable[List[Overwrite]] = MISSING
0 ignored issues
show
introduced by
The variable Overwrite does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
169
    position: APINullable[int] = MISSING
170
    rate_limit_per_user: APINullable[int] = MISSING
171
    recipients: APINullable[List[User]] = MISSING
0 ignored issues
show
introduced by
The variable User does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
172
    rtc_region: APINullable[Optional[str]] = MISSING
173
    thread_metadata: APINullable[ThreadMetadata] = MISSING
0 ignored issues
show
introduced by
The variable ThreadMetadata does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
174
    topic: APINullable[Optional[str]] = MISSING
175
    user_limit: APINullable[int] = MISSING
176
    video_quality_mode: APINullable[int] = MISSING
177
178
    @classmethod
179
    async def from_id(cls, client: Client, id: int) -> Channel:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
introduced by
Missing function or method docstring
Loading history...
180
        data = (await client.http.get(f"channels/{id}")) or {}
181
        data.update(
182
            {
183
                "_client": client,
184
                "_http": client.http,
185
                "type": ChannelType(data.pop("type"))
186
            }
187
        )
188
189
        channel_cls = _channel_type_map.get(data["type"], Channel)
190
        return channel_cls.from_dict(data)
191
192
    @overload
193
    async def edit(
194
            self, *, name: str = None,
195
            type: ChannelType = None,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
196
            position: int = None, topic: str = None, nsfw: bool = None,
197
            rate_limit_per_user: int = None, bitrate: int = None,
198
            user_limit: int = None,
199
            permissions_overwrites: List[Overwrite] = None,
200
            parent_id: Snowflake = None, rtc_region: str = None,
201
            video_quality_mod: int = None,
202
            default_auto_archive_duration: int = None
203
    ) -> Channel:
204
        ...
205
206
    async def edit(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
207
        data = await self._http.patch(f"channels/{self.id}", kwargs)
208
        data.update(
209
            {
210
                "_client": self.client,
0 ignored issues
show
Bug introduced by
Instance of 'Channel' has no 'client' member; maybe '_client'?

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
211
                "_http": self._http,
212
                "type": ChannelType(data.pop("type"))
213
            }
214
        )
215
        channel_cls = _channel_type_map.get(data["type"], Channel)
216
        return channel_cls.from_dict(data)
217
218
219
def __str__(self):
220
    """return the discord tag when object gets used as a string."""
221
    return self.name or str(self.id)
222
223
224
class TextChannel(Channel):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
225
    def __init__(self, *args, **kwargs):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
226
        super().__init__(*args, **kwargs)
227
228
    @overload
229
    async def edit(
0 ignored issues
show
best-practice introduced by
Too many arguments (10/5)
Loading history...
Bug introduced by
Parameters differ from overridden 'edit' method
Loading history...
230
            self, name: str = None, type: ChannelType = None,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
231
            position: int = None, topic: str = None, nsfw: bool = None,
232
            rate_limit_per_user: int = None,
233
            permissions_overwrites: List[Overwrite] = None,
234
            parent_id: Snowflake = None,
235
            default_auto_archive_duration: int = None
236
    ) -> Union[TextChannel, NewsChannel]:
237
        ...
238
239
    async def edit(self, **kwargs):
240
        return await super().edit(**kwargs)
241
242
243
class VoiceChannel(Channel):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
244
    def __init__(self, *args, **kwargs):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
245
        super().__init__(*args, **kwargs)
246
247
    @overload
248
    async def edit(
0 ignored issues
show
Bug introduced by
Parameters differ from overridden 'edit' method
Loading history...
best-practice introduced by
Too many arguments (8/5)
Loading history...
249
            self, name: str = None, position: int = None, bitrate: int = None,
250
            user_limit: int = None,
251
            permissions_overwrites: List[Overwrite] = None,
252
            rtc_region: str = None, video_quality_mod: int = None
253
    ) -> VoiceChannel:
254
        ...
255
256
    async def edit(self, **kwargs):
257
        return await super().edit(**kwargs)
258
259
260
class CategoryChannel(Channel):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
261
    def __init__(self, *args, **kwargs):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
262
        super().__init__(*args, **kwargs)
263
264
265
class NewsChannel(Channel):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
266
    def __init__(self, *args, **kwargs):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
267
        super().__init__(*args, **kwargs)
268
269
    @overload
270
    async def edit(
0 ignored issues
show
best-practice introduced by
Too many arguments (9/5)
Loading history...
Bug introduced by
Parameters differ from overridden 'edit' method
Loading history...
271
            self, name: str = None, type: ChannelType = None,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
272
            position: int = None, topic: str = None, nsfw: bool = None,
273
            permissions_overwrites: List[Overwrite] = None,
274
            parent_id: Snowflake = None,
275
            default_auto_archive_duration: int = None
276
    ) -> Union[TextChannel, NewsChannel]:
277
        ...
278
279
    async def edit(self, **kwargs):
280
        return await super().edit(**kwargs)
281
282
283
@dataclass
284
class ChannelMention(APIObject):
285
    """
286
    Represents a Discord Channel Mention object
287
288
    :param id:
289
        id of the channel
290
291
    :param guild_id:
292
        id of the guild containing the channel
293
294
    :param type:
295
        the type of channel
296
297
    :param name:
298
        the name of the channel
299
    """
300
    id: Snowflake
0 ignored issues
show
introduced by
The variable Snowflake does not seem to be defined in case TYPE_CHECKING on line 14 is False. Are you sure this can never be the case?
Loading history...
301
    guild_id: Snowflake
302
    type: ChannelType
303
    name: str
304
305
306
_channel_type_map: Dict[ChannelType, Channel] = {
307
    ChannelType.GUILD_TEXT: TextChannel,
308
    ChannelType.GUILD_VOICE: VoiceChannel,
309
    ChannelType.GUILD_CATEGORY: CategoryChannel,
310
    ChannelType.GUILD_NEWS: NewsChannel
311
}
312