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

pincer.objects.message   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 287
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 99
dl 0
loc 287
rs 10
c 0
b 0
f 0
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
25
from __future__ import annotations
26
27
from dataclasses import dataclass
28
from enum import Enum
29
from typing import List, Optional, Union
30
31
from pincer._config import GatewayConfig
32
from pincer.objects.application import Application
33
from pincer.objects.attachment import Attachment
34
from pincer.objects.channel import Channel, ChannelMention
35
from pincer.objects.embed import Embed
36
from pincer.objects.interactions import MessageInteraction
37
from pincer.objects.guild_member import GuildMember
38
from pincer.objects.message_component import MessageComponent
39
from pincer.objects.message_reference import MessageReference
40
from pincer.objects.reaction import Reaction
41
from pincer.objects.role import Role
42
from pincer.objects.sticker import StickerItem
43
from pincer.objects.user import User
44
from pincer.utils.api_object import APIObject
45
from pincer.utils.constants import MISSING, APINullable
46
from pincer.utils.snowflake import Snowflake
47
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...
48
49
50
class MessageActivityType(Enum):
51
    """
52
    The activity people can perform on a rich presence activity.
53
54
    Such an activity could for example be a spotify listen.
55
    """
56
    JOIN = 1
57
    SPECTATE = 2
58
    LISTEN = 3
59
    JOIN_REQUEST = 5
60
61
62
class MessageFlags(Enum):
63
    """
64
    Special message properties.
65
66
    :param CROSSPOSTED:
67
        the message has been published to subscribed
68
        channels (via Channel Following)
69
70
    :param IS_CROSSPOST:
71
        this message originated from a message
72
        in another channel (via Channel Following)
73
74
    :param SUPPRESS_EMBEDS:
75
        do not include any embeds when serializing this message
76
77
    :param SOURCE_MESSAGE_DELETED:
78
        the source message for this crosspost
79
        has been deleted (via Channel Following)
80
81
    :param URGENT:
82
        this message came from the urgent message system
83
84
    :param HAS_THREAD:
85
        this message has an associated thread,
86
        with the same id as the message
87
88
    :param EPHEMERAL:
89
        this message is only visible to the user
90
        who invoked the Interaction
91
92
    :param LOADING:
93
        this message is an Interaction
94
        Response and the bot is "thinking"
95
    """
96
    CROSSPOSTED = 1 << 0
97
    IS_CROSSPOST = 1 << 1
98
    SUPPRESS_EMBEDS = 1 << 2
99
    SOURCE_MESSAGE_DELETED = 1 << 3
100
    URGENT = 1 << 4
101
    HAS_THREAD = 1 << 5
102
    EPHEMERAL = 1 << 6
103
    LOADING = 1 << 7
104
105
106
class MessageType(Enum):
107
    """
108
    Represents the type of the message.
109
    """
110
    DEFAULT = 0
111
    RECIPIENT_ADD = 1
112
    RECIPIENT_REMOVE = 2
113
    CALL = 3
114
    CHANNEL_NAME_CHANGE = 4
115
    CHANNEL_ICON_CHANGE = 5
116
    CHANNEL_PINNED_MESSAGE = 6
117
    GUILD_MEMBER_JOIN = 7
118
    USER_PREMIUM_GUILD_SUBSCRIPTION = 8
119
    USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9
120
    USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10
121
    USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11
122
    CHANNEL_FOLLOW_ADD = 12
123
    GUILD_DISCOVERY_DISQUALIFIED = 14
124
    GUILD_DISCOVERY_REQUALIFIED = 15
125
    GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING = 16
126
    GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING = 17
127
    THREAD_CREATED = 18
128
    REPLY = 19
129
    APPLICATION_COMMAND = 20
130
131
    if GatewayConfig.version < 8:
132
        REPLY = 0
133
        APPLICATION_COMMAND = 0
134
135
    if GatewayConfig.version >= 9:
136
        THREAD_STARTER_MESSAGE = 21
137
138
    GUILD_INVITE_REMINDER = 22
139
140
141
@dataclass
142
class MessageActivity(APIObject):
143
    """
144
    Represents a Discord Message Activity object
145
146
    :param type:
147
        type of message activity
148
149
    :param party_id:
150
        party_id from a Rich Presence event
151
    """
152
    type: MessageActivityType
153
    party_id: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
154
155
156
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (30/7)
Loading history...
157
class Message(APIObject):
158
    """
159
    Represents a message sent in a channel within Discord.
160
161
    :param id:
162
        id of the message
163
164
    :param channel_id:
165
        id of the channel the message was sent in
166
167
    :param guild_id:
168
        id of the guild the message was sent in
169
170
    :param author:
171
        the author of this message (not guaranteed to be a valid user)
172
173
    :param member:
174
        member properties for this message's author
175
176
    :param content:
177
        contents of the message
178
179
    :param timestamp:
180
        when this message was sent
181
182
    :param edited_timestamp:
183
        when this message was edited (or null if never)
184
185
    :param tts:
186
        whether this was a TTS message
187
188
    :param mention_everyone:
189
        whether this message mentions everyone
190
191
    :param mentions:
192
        users specifically mentioned in the message
193
194
    :param mention_roles:
195
        roles specifically mentioned in this message
196
197
    :param mention_channels:
198
        channels specifically mentioned in this message
199
200
    :param attachments:
201
        any attached files
202
203
    :param embeds:
204
        any embedded content
205
206
    :param reactions:
207
        reactions to the message
208
209
    :param nonce:
210
        user for validating a message was sent
211
212
    :param pinned:
213
        whether this message is pinned
214
215
    :param webhook_id:
216
        if the message is generated by a webhook,
217
        this is the webhook's id
218
219
    :param type:
220
        type of message
221
222
    :param activity:
223
        sent with Rich Presence-related chat embeds
224
225
    :param application:
226
        sent with Rich Presence-related chat embeds
227
228
    :param application_id:
229
        if the message is a response to an Interaction,
230
        this is the id of the interaction's application
231
232
    :param message_reference:
233
        data showing the source of a crosspost,
234
        channel follow add, pin, or reply message
235
236
    :param flags:
237
        message flags combined as a bitfield
238
239
    :param referenced_message:
240
        the message associated with the message_reference
241
242
    :param interaction:
243
        sent if the message is a response to an Interaction
244
245
    :param thread:
246
        the thread that was started from this message,
247
        includes thread member object
248
249
    :param components:
250
        sent if the message contains components like buttons,
251
        action rows, or other interactive components
252
253
    :param sticker_items:
254
        sent if the message contains stickers
255
    """
256
    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...
257
    channel_id: Snowflake
258
    author: User
259
    content: str
260
    timestamp: Timestamp
261
    edited_timestamp: Optional[Timestamp]
262
    tts: bool
263
    mention_everyone: bool
264
    mentions: List[User]
265
    mention_roles: List[Role]
266
    mention_channels: List[ChannelMention]
267
    attachments: List[Attachment]
268
    embeds: List[Embed]
269
    pinned: bool
270
    type: MessageType
271
272
    guild_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
273
    member: APINullable[GuildMember] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
274
    reactions: APINullable[List[Reaction]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
275
    nonce: APINullable[Union[int, str]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
276
    webhook_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
277
    activity: APINullable[MessageActivity] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
278
    application: APINullable[Application] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
279
    application_id: APINullable[Snowflake] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
280
    message_reference: APINullable[MessageReference] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
281
    flags: APINullable[MessageFlags] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
282
    referenced_message: APINullable[Optional[Message]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
283
    interaction: APINullable[MessageInteraction] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
284
    thread: APINullable[Channel] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
285
    components: APINullable[List[MessageComponent]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
286
    sticker_items: APINullable[List[StickerItem]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
287