Passed
Pull Request — main (#158)
by
unknown
03:04 queued 01:39
created

pincer.objects.message.user_message   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 290
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 107
dl 0
loc 290
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A UserMessage.__str__() 0 2 1
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, Enum
8
from typing import List, Optional, Union, TYPE_CHECKING
9
10
from ..._config import GatewayConfig
11
from ...utils.api_object import APIObject
0 ignored issues
show
Bug introduced by
The name api_object does not seem to exist in module pincer.utils.
Loading history...
introduced by
Cannot import 'utils.api_object' due to syntax error 'invalid syntax (<unknown>, line 77)'
Loading history...
12
from ...utils.types import MISSING
13
14
if TYPE_CHECKING:
15
    from ..app.application import Application
16
    from ..app.interaction_base import MessageInteraction
17
    from ..guild.channel import Channel, ChannelMention
0 ignored issues
show
Bug introduced by
The name channel does not seem to exist in module pincer.objects.guild.
Loading history...
introduced by
Cannot import 'guild.channel' due to syntax error 'invalid syntax (<unknown>, line 235)'
Loading history...
18
    from ..guild.member import GuildMember
19
    from ..guild.role import Role
20
    from ..message.attachment import Attachment
21
    from ..message.component import MessageComponent
22
    from ..message.embed import Embed
23
    from ..message.reaction import Reaction
24
    from ..message.reference import MessageReference
25
    from ..message.sticker import StickerItem
26
    from ..user import User
27
    from ...utils.snowflake import Snowflake
28
    from ...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 'utils.timestamp' due to syntax error 'invalid syntax (<unknown>, line 70)'
Loading history...
29
    from ...utils import APINullable
30
31
32
class MessageActivityType(IntEnum):
33
    """
34
    The activity people can perform on a rich presence activity.
35
36
    Such an activity could for example be a spotify listen.
37
    """
38
    JOIN = 1
39
    SPECTATE = 2
40
    LISTEN = 3
41
    JOIN_REQUEST = 5
42
43
44
class MessageFlags(IntEnum):
45
    """
46
    Special message properties.
47
48
    :param CROSSPOSTED:
49
        the message has been published to subscribed
50
        channels (via Channel Following)
51
52
    :param IS_CROSSPOST:
53
        this message originated from a message
54
        in another channel (via Channel Following)
55
56
    :param SUPPRESS_EMBEDS:
57
        do not include any embeds when serializing this message
58
59
    :param SOURCE_MESSAGE_DELETED:
60
        the source message for this crosspost
61
        has been deleted (via Channel Following)
62
63
    :param URGENT:
64
        this message came from the urgent message system
65
66
    :param HAS_THREAD:
67
        this message has an associated thread,
68
        with the same id as the message
69
70
    :param EPHEMERAL:
71
        this message is only visible to the user
72
        who invoked the Interaction
73
74
    :param LOADING:
75
        this message is an Interaction
76
        Response and the bot is "thinking"
77
    """
78
    CROSSPOSTED = 1 << 0
79
    IS_CROSSPOST = 1 << 1
80
    SUPPRESS_EMBEDS = 1 << 2
81
    SOURCE_MESSAGE_DELETED = 1 << 3
82
    URGENT = 1 << 4
83
    HAS_THREAD = 1 << 5
84
    EPHEMERAL = 1 << 6
85
    LOADING = 1 << 7
86
87
88
class MessageType(IntEnum):
89
    """
90
    Represents the type of the message.
91
    """
92
    DEFAULT = 0
93
    RECIPIENT_ADD = 1
94
    RECIPIENT_REMOVE = 2
95
    CALL = 3
96
    CHANNEL_NAME_CHANGE = 4
97
    CHANNEL_ICON_CHANGE = 5
98
    CHANNEL_PINNED_MESSAGE = 6
99
    GUILD_MEMBER_JOIN = 7
100
    USER_PREMIUM_GUILD_SUBSCRIPTION = 8
101
    USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9
102
    USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10
103
    USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11
104
    CHANNEL_FOLLOW_ADD = 12
105
    GUILD_DISCOVERY_DISQUALIFIED = 14
106
    GUILD_DISCOVERY_REQUALIFIED = 15
107
    GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING = 16
108
    GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING = 17
109
    THREAD_CREATED = 18
110
    REPLY = 19
111
    APPLICATION_COMMAND = 20
112
113
    if GatewayConfig.version < 8:
114
        REPLY = 0
115
        APPLICATION_COMMAND = 0
116
117
    if GatewayConfig.version >= 9:
118
        THREAD_STARTER_MESSAGE = 21
119
120
    GUILD_INVITE_REMINDER = 22
121
122
123
@dataclass
124
class MessageActivity(APIObject):
125
    """
126
    Represents a Discord Message Activity object
127
128
    :param type:
129
        type of message activity
130
131
    :param party_id:
132
        party_id from a Rich Presence event
133
    """
134
    type: MessageActivityType
135
    party_id: APINullable[str] = MISSING
136
137
138
class AllowedMentionTypes(str, Enum):
139
    """
140
    The allowed mentions.
141
142
    :param ROLES:
143
        Controls role mentions
144
145
    :param USERS:
146
        Controls user mentions
147
148
    :param EVERYONE:
149
        Controls @everyone and @here mentions
150
    """
151
    ROLES = "roles"
152
    USERS = "user"
153
    EVERYONE = "everyone"
154
155
156
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (30/7)
Loading history...
157
class UserMessage(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
257
    channel_id: Snowflake
258
    author: User
259
    content: str
260
    timestamp: Timestamp
261
    tts: bool
262
    mention_everyone: bool
263
    mentions: List[GuildMember]
264
    mention_roles: List[Role]
265
    attachments: List[Attachment]
266
    embeds: List[Embed]
267
    pinned: bool
268
    type: MessageType
269
    edited_timestamp: Optional[Timestamp] = None
270
271
    mention_channels: APINullable[List[ChannelMention]] = MISSING
272
    guild_id: APINullable[Snowflake] = MISSING
273
    member: APINullable[GuildMember] = MISSING
274
    reactions: APINullable[List[Reaction]] = MISSING
275
    nonce: APINullable[Union[int, str]] = MISSING
276
    webhook_id: APINullable[Snowflake] = MISSING
277
    activity: APINullable[MessageActivity] = MISSING
278
    application: APINullable[Application] = MISSING
279
    application_id: APINullable[Snowflake] = MISSING
280
    message_reference: APINullable[MessageReference] = MISSING
281
    flags: APINullable[MessageFlags] = MISSING
282
    referenced_message: APINullable[Optional[UserMessage]] = MISSING
283
    interaction: APINullable[MessageInteraction] = MISSING
284
    thread: APINullable[Channel] = MISSING
285
    components: APINullable[List[MessageComponent]] = MISSING
286
    sticker_items: APINullable[List[StickerItem]] = MISSING
287
288
    def __str__(self):
289
        return self.content
290