Code Duplication    Length = 20-34 lines in 2 locations

pincer/objects/message/message.py 1 location

@@ 36-69 (lines=34) @@
33
    PILLOW_IMPORT = False
34
35
36
@dataclass
37
class AllowedMentions(APIObject):
38
    """Represents the entities the client can mention
39
40
    Attributes
41
    ----------
42
    parse: List[:class:`~pincer.objects.message.user_message.AllowedMentionTypes`]
43
        An array of allowed mention types to parse from the content.
44
    roles: List[Union[:class:`~pincer.objects.guild.role.Role`, :class:`~pincer.utils.snowflake.Snowflake`]]
45
        List of ``Role`` objects or snowflakes of allowed mentions.
46
    users: List[Union[:class:`~pincer.objects.user.user.User` :class:`~pincer.utils.snowflake.Snowflake`]]
47
        List of ``user`` objects or snowflakes of allowed mentions.
48
    reply: :class:`bool`
49
        If replies should mention the author.
50
        |default| :data:`True`
51
    """  # noqa: E501
52
53
    parse: List[AllowedMentionTypes]
54
    roles: List[Union[Role, Snowflake]]
55
    users: List[Union[User, Snowflake]]
56
    reply: bool = True
57
58
    def to_dict(self):
59
        def get_str_id(obj: Union[Snowflake, User, Role]) -> str:
60
            if hasattr(obj, "id"):
61
                obj = obj.id
62
63
            return str(obj)
64
65
        return {
66
            "parse": self.parse,
67
            "roles": list(map(get_str_id, self.roles)),
68
            "users": list(map(get_str_id, self.users)),
69
            "replied_user": self.reply
70
        }
71
72

pincer/objects/message/user_message.py 1 location

@@ 209-228 (lines=20) @@
206
    EVERYONE = "everyone"
207
208
209
@dataclass
210
class AllowedMentions(APIObject):
211
    parse: List[AllowedMentionTypes]
212
    roles: List[Union[Role, Snowflake]]
213
    users: List[Union[User, Snowflake]]
214
    reply: bool = True
215
216
    @staticmethod
217
    def get_str_id(obj: Union[Snowflake, User, Role]) -> str:
218
        if hasattr(obj, "id"):
219
            obj = obj.id
220
221
        return str(obj)
222
223
    def to_dict(self):
224
        return {
225
            "parse": self.parse,
226
            "roles": list(map(self.get_str_id, self.roles)),
227
            "users": list(map(self.get_str_id, self.users)),
228
            "replied_user": self.reply
229
        }
230
231