Browse Source

Merge 1015ba4704 into 333fcebcd4

pull/18/merge
r3t4rd3d 8 years ago
committed by GitHub
parent
commit
1e6d144f45
  1. 110
      disco/types/message.py
  2. 71
      disco/types/user.py

110
disco/types/message.py

@ -53,12 +53,38 @@ class MessageReaction(SlottedModel):
class MessageEmbedFooter(SlottedModel): class MessageEmbedFooter(SlottedModel):
"""
Message embed footer object.
Attributes
----------
text : str
Footer text.
icon_url : str
URL of footer icon.
proxy_icon_url : str
Proxied URL of the footer icon.
"""
text = Field(text) text = Field(text)
icon_url = Field(text) icon_url = Field(text)
proxy_icon_url = Field(text) proxy_icon_url = Field(text)
class MessageEmbedImage(SlottedModel): class MessageEmbedImage(SlottedModel):
"""
Message embed image object.
Attributes
----------
url : str
Source URL of image.
proxy_url : str
Proxied URL of the image.
height : int
height of image.
width : int
width of image.
"""
url = Field(text) url = Field(text)
proxy_url = Field(text) proxy_url = Field(text)
width = Field(int) width = Field(int)
@ -66,6 +92,20 @@ class MessageEmbedImage(SlottedModel):
class MessageEmbedThumbnail(SlottedModel): class MessageEmbedThumbnail(SlottedModel):
"""
Message embed thumbnail object.
Attributes
----------
url : str
Source URL of thumbnail.
proxy_url : str
Proxied URL of the thumbnail.
height : int
height of thumbnail.
width : int
width of thumbnail.
"""
url = Field(text) url = Field(text)
proxy_url = Field(text) proxy_url = Field(text)
width = Field(int) width = Field(int)
@ -73,12 +113,38 @@ class MessageEmbedThumbnail(SlottedModel):
class MessageEmbedVideo(SlottedModel): class MessageEmbedVideo(SlottedModel):
"""
Message embed video object.
Attributes
----------
url : str
Source URL of video.
height : int
height of video.
width : int
width of video.
"""
url = Field(text) url = Field(text)
height = Field(int) height = Field(int)
width = Field(int) width = Field(int)
class MessageEmbedAuthor(SlottedModel): class MessageEmbedAuthor(SlottedModel):
"""
Message embed author object.
Attributes
----------
name : str
Name of author.
url : str
URL of author.
icon_url : str
URL of author icon.
icon_proxy_url : str
Proxied URL of the author icon.
"""
name = Field(text) name = Field(text)
url = Field(text) url = Field(text)
icon_url = Field(text) icon_url = Field(text)
@ -86,6 +152,18 @@ class MessageEmbedAuthor(SlottedModel):
class MessageEmbedField(SlottedModel): class MessageEmbedField(SlottedModel):
"""
Message embed field object.
Attributes
----------
name : str
Name of the field.
value : str
Value of the field.
inline : bool
Whether or not this field should display inline.
"""
name = Field(text) name = Field(text)
value = Field(text) value = Field(text)
inline = Field(bool) inline = Field(bool)
@ -105,6 +183,20 @@ class MessageEmbed(SlottedModel):
Description of the embed. Description of the embed.
url : str url : str
URL of the embed. URL of the embed.
timestamp : datetime
Timestamp of the embed content.
color : int
Color code of the embed.
footer : :class:`MessageEmbedFooter`
Footer information.
image : :class:`MessageEmbedImage`
Image information.
thumbnail : :class:`MessageEmbedThumbnail`
Thumbnail information.
video : :class:`MessageEmbedVideo`
Video information.
fields : list(:class:`MessageEmbedField`)
Fields information.
""" """
title = Field(text) title = Field(text)
type = Field(str, default='rich') type = Field(str, default='rich')
@ -120,21 +212,39 @@ class MessageEmbed(SlottedModel):
fields = ListField(MessageEmbedField) fields = ListField(MessageEmbedField)
def set_footer(self, *args, **kwargs): def set_footer(self, *args, **kwargs):
"""
Adds :class:`MessageEmbedFooter` to the embed.
"""
self.footer = MessageEmbedFooter(*args, **kwargs) self.footer = MessageEmbedFooter(*args, **kwargs)
def set_image(self, *args, **kwargs): def set_image(self, *args, **kwargs):
"""
Adds :class:`MessageEmbedImage` to the embed.
"""
self.image = MessageEmbedImage(*args, **kwargs) self.image = MessageEmbedImage(*args, **kwargs)
def set_thumbnail(self, *args, **kwargs): def set_thumbnail(self, *args, **kwargs):
"""
Adds :class:`MessageEmbedThumbnail` to the embed.
"""
self.thumbnail = MessageEmbedThumbnail(*args, **kwargs) self.thumbnail = MessageEmbedThumbnail(*args, **kwargs)
def set_video(self, *args, **kwargs): def set_video(self, *args, **kwargs):
"""
Adds :class:`MessageEmbedVideo` to the embed.
"""
self.video = MessageEmbedVideo(*args, **kwargs) self.video = MessageEmbedVideo(*args, **kwargs)
def set_author(self, *args, **kwargs): def set_author(self, *args, **kwargs):
"""
Adds :class:`MessageEmbedAuthor` to the embed.
"""
self.author = MessageEmbedAuthor(*args, **kwargs) self.author = MessageEmbedAuthor(*args, **kwargs)
def add_field(self, *args, **kwargs): def add_field(self, *args, **kwargs):
"""
Appends :class:`MessageEmbedField` to the embed.
"""
self.fields.append(MessageEmbedField(*args, **kwargs)) self.fields.append(MessageEmbedField(*args, **kwargs))

71
disco/types/user.py

@ -12,6 +12,26 @@ DefaultAvatars = Enum(
class User(SlottedModel, with_equality('id'), with_hash('id')): class User(SlottedModel, with_equality('id'), with_hash('id')):
"""
User object.
Attributes
----------
id : snowflake
The ID of this user.
username : str
The name of the user.
avatar : str
The user\'s avatar hash.
discriminator : str
The user\'s discriminator (4-digit discord-tag).
bot : bool
Whether this user is a bot.
verified : bool
Whether the email on this account has been verified.
email : str
The user\'s email address.
"""
id = Field(snowflake) id = Field(snowflake)
username = Field(text) username = Field(text)
avatar = Field(text) avatar = Field(text)
@ -23,6 +43,21 @@ class User(SlottedModel, with_equality('id'), with_hash('id')):
presence = Field(None) presence = Field(None)
def get_avatar_url(self, fmt='webp', size=1024): def get_avatar_url(self, fmt='webp', size=1024):
"""
Returns the URL to the user\'s avatar.
Args
----
fmt : str
Imageformat of the avatar.
size : int
Size of the avatar.
Returns
-------
str
The URL to the user\'s avatar.
"""
if not self.avatar: if not self.avatar:
return 'https://cdn.discordapp.com/embed/avatars/{}.png'.format(self.default_avatar.value) return 'https://cdn.discordapp.com/embed/avatars/{}.png'.format(self.default_avatar.value)
@ -35,14 +70,23 @@ class User(SlottedModel, with_equality('id'), with_hash('id')):
@property @property
def default_avatar(self): def default_avatar(self):
"""
Returns the Default avatar url of the user.
"""
return DefaultAvatars[int(self.discriminator) % len(DefaultAvatars.attrs)] return DefaultAvatars[int(self.discriminator) % len(DefaultAvatars.attrs)]
@property @property
def avatar_url(self): def avatar_url(self):
"""
Returns the avatar url of the user.
"""
return self.get_avatar_url() return self.get_avatar_url()
@property @property
def mention(self): def mention(self):
"""
Formated string that mentions the user.
"""
return '<@{}>'.format(self.id) return '<@{}>'.format(self.id)
def open_dm(self): def open_dm(self):
@ -70,12 +114,39 @@ Status = Enum(
class Game(SlottedModel): class Game(SlottedModel):
"""
Represents the activity of a user.
Attributes
----------
type : `GameType`
Whether the user is just playing the game or streaming.
Possible values are: `DEFAULT` (Playing ...) and `STREAMING` (Streaming ...).
name : str
Name of the Game.
url : str
Stream URL. Only validated when `GameType` is `STREAMING`.
"""
type = Field(GameType) type = Field(GameType)
name = Field(text) name = Field(text)
url = Field(text) url = Field(text)
class Presence(SlottedModel): class Presence(SlottedModel):
"""
Represents the Presence of a user.
Attributes
----------
user : :class:`disco.types.user.User`
game : :class:`disco.types.user.Game`
The user\'s current activity.
status : `Status`
The user\'s current status.
Possible values are: `ONLINE`, `IDLE`, `DND` (Do not Disturb) and `OFFLINE`.
"""
user = Field(User, alias='user', ignore_dump=['presence']) user = Field(User, alias='user', ignore_dump=['presence'])
game = Field(Game) game = Field(Game)
status = Field(Status) status = Field(Status)

Loading…
Cancel
Save