Пример #1
0
class User(SlottedModel, with_equality('id'), with_hash('id')):
    id = Field(snowflake)
    username = Field(text)
    avatar = Field(binary)
    discriminator = Field(str)
    bot = Field(bool, default=False)
    verified = Field(bool)
    email = Field(str)

    presence = Field(None)

    @property
    def avatar_url(self):
        if not self.avatar:
            return None

        return 'https://discordapp.com/api/users/{}/avatars/{}.jpg'.format(
            self.id, self.avatar)

    @property
    def mention(self):
        return '<@{}>'.format(self.id)

    def __str__(self):
        return u'{}#{}'.format(self.username, str(self.discriminator).zfill(4))

    def __repr__(self):
        return u'<User {} ({})>'.format(self.id, self)
Пример #2
0
class User(SlottedModel, with_equality('id'), with_hash('id')):
    id = Field(snowflake)
    username = Field(text)
    avatar = Field(text)
    discriminator = Field(text)
    bot = Field(bool, default=False)
    system = Field(bool, default=False)
    mfa_enabled = Field(bool)
    locale = Field(text)
    verified = Field(bool)
    email = Field(text)
    flags = Field(UserFlagsValue, cast=int)
    public_flags = Field(UserFlagsValue, cast=int, default=0)
    premium_type = Field(enum(PremiumType))
    presence = Field(None)

    def get_avatar_url(self, fmt=None, size=1024):
        if not self.avatar:
            return 'https://cdn.discordapp.com/embed/avatars/{}.png'.format(
                self.default_avatar.value)
        if fmt is not None:
            return 'https://cdn.discordapp.com/avatars/{}/{}.{}?size={}'.format(
                self.id, self.avatar, fmt, size)
        if self.avatar.startswith('a_'):
            return 'https://cdn.discordapp.com/avatars/{}/{}.gif?size={}'.format(
                self.id, self.avatar, size)
        else:
            return 'https://cdn.discordapp.com/avatars/{}/{}.webp?size={}'.format(
                self.id, self.avatar, size)

    @property
    def default_avatar(self):
        return DefaultAvatars[int(self.discriminator) %
                              len(DefaultAvatars.attrs)]

    @property
    def avatar_url(self):
        return self.get_avatar_url()

    @property
    def mention(self):
        return '<@{}>'.format(self.id)

    def open_dm(self):
        return self.client.api.users_me_dms_create(self.id)

    def __str__(self):
        return u'{}#{}'.format(self.username, str(self.discriminator).zfill(4))

    def __repr__(self):
        return u'<User {} ({})>'.format(self.id, self)
Пример #3
0
class User(SlottedModel, with_equality('id'), with_hash('id')):
    id = Field(snowflake)
    username = Field(text)
    avatar = Field(text)
    discriminator = Field(text)
    bot = Field(bool, default=False)
    verified = Field(bool)
    email = Field(text)

    presence = Field(None)

    def get_avatar_url(self, fmt='webp', size=1024):
        if not self.avatar:
            return 'https://cdn.discordapp.com/embed/avatars/{}.png'.format(
                self.default_avatar.value)

        return 'https://cdn.discordapp.com/avatars/{}/{}.{}?size={}'.format(
            self.id,
            self.avatar,
            fmt,
            size,
        )

    @property
    def default_avatar(self):
        return DefaultAvatars[int(self.discriminator) %
                              len(DefaultAvatars.attrs)]

    @property
    def avatar_url(self):
        return self.get_avatar_url()

    @property
    def mention(self):
        return '<@{}>'.format(self.id)

    def open_dm(self):
        return self.client.api.users_me_dms_create(self.id)

    def __str__(self):
        return u'{}#{}'.format(self.username, str(self.discriminator).zfill(4))

    def __repr__(self):
        return u'<User {} ({})>'.format(self.id, self)
Пример #4
0
Файл: user.py Проект: jhgg/disco
class User(Model, with_equality('id'), with_hash('id')):
    id = Field(snowflake)
    username = Field(text)
    discriminator = Field(str)
    avatar = Field(binary)
    verified = Field(bool)
    email = Field(str)

    presence = None

    @property
    def mention(self):
        return '<@{}>'.format(self.id)

    def to_string(self):
        return '{}#{}'.format(self.username, self.discriminator)

    def __str__(self):
        return '<User {} ({})>'.format(self.id, self.to_string())

    def on_create(self):
        self.client.state.users[self.id] = self