Passed
Push — main ( c094fa...1db6e6 )
by
unknown
01:43
created

pincer.objects.user_message   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 302
Duplicated Lines 0 %

Importance

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