Passed
Pull Request — main (#44)
by
unknown
01:34
created

pincer.objects.channel   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 208
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 62
dl 0
loc 208
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A __str__() 0 3 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# MIT License
3
#
4
# Copyright (c) 2021 Pincer
5
#
6
# Permission is hereby granted, free of charge, to any person obtaining
7
# a copy of this software and associated documentation files
8
# (the "Software"), to deal in the Software without restriction,
9
# including without limitation the rights to use, copy, modify, merge,
10
# publish, distribute, sublicense, and/or sell copies of the Software,
11
# and to permit persons to whom the Software is furnished to do so,
12
# subject to the following conditions:
13
#
14
# The above copyright notice and this permission notice shall be
15
# included in all copies or substantial portions of the Software.
16
#
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
from __future__ import annotations
25
26
from dataclasses import dataclass
27
from enum import Enum
28
from typing import Optional, List
29
30
from pincer._config import GatewayConfig
31
from pincer.objects.guild_member import GuildMember
32
from pincer.objects.user import User
33
from pincer.objects.thread import ThreadMetadata
34
from pincer.utils.api_object import APIObject
35
from pincer.utils.constants import APINullable, MISSING
36
from pincer.utils.snowflake import Snowflake
37
from pincer.utils.timestamp import Timestamp
0 ignored issues
show
Bug introduced by
The name timestamp does not seem to exist in module pincer.utils.
Loading history...
introduced by
Cannot import 'pincer.utils.timestamp' due to syntax error 'invalid syntax (<unknown>, line 91)'
Loading history...
38
39
40
class ChannelType(Enum):
41
    """Represents a channel its type."""
42
    GUILD_TEXT = 0
43
    DM = 1
44
    GUILD_VOICE = 2
45
    GROUP_DM = 3
46
    GUILD_CATEGORY = 4
47
    GUILD_NEWS = 5
48
    GUILD_STORE = 6
49
50
    if GatewayConfig.version >= 9:
51
        GUILD_NEWS_THREAD = 10
52
        GUILD_PUBLIC_THREAD = 11
53
        GUILD_PRIVATE_THREAD = 12
54
55
    GUILD_STAGE_VOICE = 13
56
57
58
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (26/7)
Loading history...
59
class Channel(APIObject):
60
    """
61
    Represents a Discord Channel Mention object
62
63
    :param id:
64
        the id of this channel
65
66
    :param type:
67
        the type of channel
68
69
    :param application_id:
70
        application id of the group DM creator if it is bot-created
71
72
    :param bitrate:
73
        the bitrate (in bits) of the voice channel
74
75
    :param default_auto_archive_duration:
76
        default duration for newly created threads, in minutes, to
77
        automatically archive the thread after recent activity, can be set to:
78
        60, 1440, 4320, 10080
79
80
    :param guild_id:
81
        the id of the guild (may be missing for some channel objects received
82
        over gateway guild dispatches)
83
84
    :param icon:
85
        icon hash
86
    :param last_message_id:
87
        the id of the last message sent in this channel (may not point to an
88
        existing or valid message)
89
90
    :param last_pin_timestamp:
91
        when the last pinned message was pinned. This may be null in events
92
        such as GUILD_CREATE when a message is not pinned.
93
94
    :param member:
95
        thread member object for the current user, if they have joined the
96
        thread, only included on certain API endpoints
97
98
    :param member_count:
99
        an approximate count of users in a thread, stops counting at 50
100
101
    :param message_count:
102
        an approximate count of messages in a thread, stops counting at 50
103
104
    :param name:
105
        the name of the channel (1-100 characters)
106
107
    :param nsfw:
108
        whether the channel is nsfw
109
110
    :param owner_id:
111
        id of the creator of the group DM or thread
112
113
    :param parent_id:
114
        for guild channels: id of the parent category for a channel (each
115
        parent category can contain up to 50 channels), for threads: id of the
116
        text channel this thread was created
117
118
    :param permissions:
119
        computed permissions for the invoking user in the channel, including
120
        overwrites, only included when part of the resolved data received on a
121
        slash command interaction
122
123
    :param permission_overwrites:
124
        explicit permission overwrites for members and roles
125
126
    :param position:
127
        sorting position of the channel
128
129
    :param rate_limit_per_user:
130
        amount of seconds a user has to wait before sending another message
131
        (0-21600); bots, as well as users with the permission manage_messages
132
        or manage_channel, are unaffected
133
134
    :param recipients:
135
        the recipients of the DM
136
137
    :param rtc_region:
138
        voice region id for the voice channel, automatic when set to null
139
140
    :param thread_metadata:
141
        thread-specific fields not needed by other channels
142
143
    :param topic:
144
        the channel topic (0-1024 characters)
145
146
    :param user_limit:
147
        the user limit of the voice channel
148
149
    :param video_quality_mode:
150
        the camera video quality mode of the voice channel, 1 when not present
151
    """
152
153
    id: Snowflake
1 ignored issue
show
Coding Style Naming introduced by
Attribute name "id" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
154
    type: ChannelType
155
156
    application_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
157
    bitrate: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
158
    default_auto_archive_duration: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
159
    guild_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
160
    icon: APINullable[Optional[str]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
161
    last_message_id: APINullable[Optional[Snowflake]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
162
    last_pin_timestamp: APINullable[Optional[Timestamp]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
163
    member: APINullable[GuildMember] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
164
    member_count: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
165
    message_count: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
166
    name: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
167
    nsfw: APINullable[bool] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
168
    owner_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
169
    parent_id: APINullable[Optional[Snowflake]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
170
    permissions: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
171
    permission_overwrites: APINullable[List[...]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
172
    position: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
173
    rate_limit_per_user: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
174
    recipients: APINullable[List[User]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
175
    rtc_region: APINullable[Optional[str]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
176
    thread_metadata: APINullable[ThreadMetadata] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
177
    topic: APINullable[Optional[str]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
178
    user_limit: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
179
    video_quality_mode: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
180
181
182
def __str__(self):
183
    """return the discord tag when object gets used as a string."""
184
    return self.name or str(self.id)
185
186
187
@dataclass
188
class ChannelMention(APIObject):
189
    """
190
    Represents a Discord Channel Mention object
191
192
    :param id:
193
        id of the channel
194
195
    :param guild_id:
196
        id of the guild containing the channel
197
198
    :param type:
199
        the type of channel
200
201
    :param name:
202
        the name of the channel
203
    """
204
    id: Snowflake
1 ignored issue
show
Coding Style Naming introduced by
Attribute name "id" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
205
    guild_id: Snowflake
206
    type: ChannelType
207
    name: str
208