class GuildEmoji(Emoji): """ An emoji object. Attributes ---------- id : snowflake The ID of this emoji. name : str The name of this emoji. require_colons : bool Whether this emoji requires colons to use. managed : bool Whether this emoji is managed by an integration. roles : list(snowflake) Roles this emoji is attached to. """ id = Field(snowflake) guild_id = Field(snowflake) name = Field(text) require_colons = Field(bool) managed = Field(bool) roles = ListField(snowflake) @property def url(self): return 'https://discordapp.com/api/emojis/{}.png'.format(self.id) @cached_property def guild(self): return self.client.state.guilds.get(self.guild_id)
class MessageReactionRemoveEmoji(GatewayEvent): """ Sent when all reactions of a single emoji are removed from a message. Attributes ---------- guild_id : Snowflake The guild ID the message is in. channel_id : Snowflake The channel ID the message is in. message_id : Snowflake The ID of the message for which the reaction was removed from. emoji : :class:`disco.types.message.MessageReactionEmoji` The emoji that was removed. """ guild_id = Field(snowflake) channel_id = Field(snowflake) message_id = Field(snowflake) emoji = Field(MessageReactionEmoji) @property def channel(self): return self.client.state.channels.get(self.channel_id) @property def guild(self): return self.channel.guild
class PermissionOverwrite(Model): """ A PermissionOverwrite for a :class:`Channel` Attributes ---------- id : snowflake The overwrite ID type : :const:`disco.types.channel.PermissionsOverwriteType` The overwrite type allowed : :class:`PermissionValue` All allowed permissions denied : :class:`PermissionValue` All denied permissions """ id = Field(snowflake) type = Field(enum(PermissionOverwriteType)) allow = Field(PermissionValue) deny = Field(PermissionValue) def save(self): return self.channel.update_overwrite(self) def delete(self): return self.channel.delete_overwrite(self)
class MessageReactionAdd(GatewayEvent): """ Sent when a reaction is added to a message. Attributes ---------- channel_id : snowflake The channel ID the message is in. messsage_id : snowflake The ID of the message for which the reaction was added too. user_id : snowflake The ID of the user who added the reaction. emoji : :class:`disco.types.message.MessageReactionEmoji` The emoji which was added. """ channel_id = Field(snowflake) message_id = Field(snowflake) user_id = Field(snowflake) emoji = Field(MessageReactionEmoji) def delete(self): self.client.api.channels_messages_reactions_delete( self.channel_id, self.message_id, self.emoji.to_string() if self.emoji.id else self.emoji.name, self.user_id, ) @property def channel(self): return self.client.state.channels.get(self.channel_id) @property def guild(self): return self.channel.guild
class VoiceServerUpdate(GatewayEvent): """ Sent when a voice server is updated. """ token = Field(str) endpoint = Field(str) guild_id = Field(snowflake)
class TestModel(Model): a = Field(int) b = Field(int) @cached_property def value(self): return self.a + self.b
class TypingStart(GatewayEvent): """ Sent when a user begins typing in a channel. """ channel_id = Field(snowflake) user_id = Field(snowflake) timestamp = Field(snowflake)
class Emoji(SlottedModel): """ Represents either a standard or custom Discord emoji. Attributes ---------- id : snowflake? The emoji ID (will be none if this is not a custom emoji). name : str The name of this emoji. """ id = Field(snowflake) name = Field(text) @cached_property def custom(self): return bool(self.id) def __eq__(self, other): if isinstance(other, Emoji): return self.id == other.id and self.name == other.name raise NotImplementedError def to_string(self): if self.id: return '{}:{}'.format(self.name, self.id) return self.name
class MessageReactionRemove(GatewayEvent): """ Sent when a reaction is removed from a message. Attributes ---------- channel_id : snowflake The channel ID the message is in. messsage_id : snowflake The ID of the message for which the reaction was removed from. user_id : snowflake The ID of the user who originally added the reaction. emoji : :class:`disco.types.message.MessageReactionEmoji` The emoji which was removed. """ channel_id = Field(snowflake) message_id = Field(snowflake) user_id = Field(snowflake) emoji = Field(MessageReactionEmoji) @property def channel(self): return self.client.state.channels.get(self.channel_id) @property def guild(self): return self.channel.guild
class WatcherChangeParserStart(GatewayEvent): app_id = Field(str) branch_name = Field(str) branch_version = Field(str) parser = Field(str) def __str__(self): return "{} - {}".format(self.app_id, self.parser)
class WatcherChangeBranch(GatewayEvent): app_id = Field(str) branch_name = Field(str) old_branchinfo = Field(dict) new_branchinfo = Field(dict) def __str__(self): return "{} - {}".format(self.old_branchinfo, self.new_branchinfo)
class Ready(GatewayEvent): """ Sent after the initial gateway handshake is complete. Contains data required for bootstrapping the client's states. """ version = Field(int, alias='v') session_id = Field(str) user = Field(User) guilds = Field(listof(Guild))
class WatcherChangeParserResult(GatewayEvent): app_id = Field(str) branch_name = Field(str) branch_version = Field(str) parser = Field(str) # name of parser result = ListField(str) # absolute path to some files def __str__(self): return "[{}][{}][{}]".format(self.app_id, self.parser, self.result)
class WatcherLogMessage(GatewayEvent): """ Sent for LOGERROR, LOGWARNING, LOGINFO, LOGDEBUG """ logtype = Field(BotCommand) logmsg = Field(str) def __str__(self): return "{} - {}".format(self.logtype, self.logmsg)
class Invite(Model): """ An invite object Attributes ---------- code : str The invite code. inviter : :class:`disco.types.user.User` The user who created this invite. guild : :class:`disco.types.guild.Guild` The guild this invite is for. channel : :class:`disco.types.channel.Channel` The channel this invite is for. max_age : int The time after this invite's creation at which it expires. max_uses : int The maximum number of uses. uses : int The current number of times the invite was used. temporary : bool Whether this invite only grants temporary membership. created_at : datetime When this invite was created. """ code = Field(str) inviter = Field(User) guild = Field(Guild) channel = Field(Channel) max_age = Field(int) max_uses = Field(int) uses = Field(int) temporary = Field(bool) created_at = Field(datetime)
class GuildConfigObject(Model): bot = Field(BotConfig) web = Field(WebConfig) # permissions = Field(PermissionsConfig) # plugins = RawField() def __init__(self, raw_data): self.raw = raw_data obj = yaml.load(raw_data) super(GuildConfigObject, self).__init__(obj)
class Timestamps(SlottedModel): start = Field(int) end = Field(int) @cached_property def start_time(self): return datetime.utcfromtimestamp(self.start / 1000) @cached_property def end_time(self): return datetime.utcfromtimestamp(self.end / 1000)
class PermissionOverwrite(ChannelSubType): """ A PermissionOverwrite for a :class:`Channel`. Attributes ---------- id : snowflake The overwrite ID type : :const:`disco.types.channel.PermissionsOverwriteType` The overwrite type allowed : :class:`PermissionValue` All allowed permissions denied : :class:`PermissionValue` All denied permissions """ id = Field(snowflake) type = Field(enum(PermissionOverwriteType)) allow = Field(PermissionValue, cast=int) deny = Field(PermissionValue, cast=int) channel_id = Field(snowflake) @classmethod def create_for_channel(cls, channel, entity, allow=0, deny=0): from disco.types.guild import Role ptype = PermissionOverwriteType.ROLE if isinstance( entity, Role) else PermissionOverwriteType.MEMBER return cls( client=channel.client, id=entity.id, type=ptype, allow=allow, deny=deny, channel_id=channel.id, ).save() @property def compiled(self): value = PermissionValue() value -= self.deny value += self.allow return value def save(self, **kwargs): self.client.api.channels_permissions_modify(self.channel_id, self.id, self.allow.value or 0, self.deny.value or 0, self.type.name, **kwargs) return self def delete(self, **kwargs): self.client.api.channels_permissions_delete(self.channel_id, self.id, **kwargs)
class MessageActivity(SlottedModel): """ The activity of a Rich Presence-related chat embed. Attributes ---------- type : `MessageActivityType` The type of message activity. party_id : str The party id from a Rich Presence event. """ type = Field(enum(MessageActivityType)) party_id = Field(text)
class WebhooksUpdate(GatewayEvent): """ Sent when a channels webhooks are updated. Attributes ----- channel_id : snowflake The channel ID this webhooks update is for. guild_id : snowflake The guild ID this webhooks update is for. """ channel_id = Field(snowflake) guild_id = Field(snowflake)
class ChannelPinsUpdate(GatewayEvent): """ Sent when a channel's pins are updated. Attributes ----- channel_id : snowflake ID of the channel where pins where updated. last_pin_timestap : datetime The time the last message was pinned. """ channel_id = Field(snowflake) last_pin_timestamp = Field(lazy_datetime)
class Emoji(SlottedModel): id = Field(snowflake) name = Field(text) def __eq__(self, other): if isinstance(other, Emoji): return self.id == other.id and self.name == other.name raise NotImplementedError def to_string(self): if self.id: return '{}:{}'.format(self.name, self.id) return self.name
class GuildEmojisUpdate(GatewayEvent): """ Sent when a guild's emojis are updated. Attributes ----- guild_id : snowflake The ID of the guild the emojis are being updated in. emojis : list[:class:`disco.types.guild.Emoji`] The new set of emojis for the guild """ guild_id = Field(snowflake) emojis = Field(listof(Emoji))
class MessageDelete(GatewayEvent): """ Sent when a message is deleted. Attributes ----- id : snowflake The ID of message being deleted. channel_id : snowflake The ID of the channel the message was deleted in. """ id = Field(snowflake) channel_id = Field(snowflake)
class MessageDeleteBulk(GatewayEvent): """ Sent when multiple messages are deleted from a channel. Attributes ----- channel_id : snowflake The channel the messages are being deleted in. ids : list[snowflake] List of messages being deleted in the channel. """ channel_id = Field(snowflake) ids = Field(listof(snowflake))
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)
class PresenceUpdate(GatewayEvent): """ Sent when a user's presence is updated. Attributes ----- presence : :class:`disco.types.user.Presence` The updated presence object. guild_id : snowflake The guild this presence update is for. roles : list[snowflake] List of roles the user from the presence is part of. """ guild_id = Field(snowflake) roles = Field(listof(snowflake))
class VoiceServerUpdate(GatewayEvent): """ Sent when a voice server is updated. Attributes ----- token : str The token for the voice server. endpoint : str The endpoint for the voice server. guild_id : snowflake The guild ID this voice server update is for. """ token = Field(str) endpoint = Field(str) guild_id = Field(snowflake)
class TypingStart(GatewayEvent): """ Sent when a user begins typing in a channel. Attributes ----- channel_id : snowflake The ID of the channel where the user is typing. user_id : snowflake The ID of the user who is typing. timestamp : datetime When the user started typing. """ channel_id = Field(snowflake) user_id = Field(snowflake) timestamp = Field(lazy_datetime)
class MessageEmbedFooter(SlottedModel): """ A footer for the `MessageEmbed`. Attributes ---------- text : str The contents of the footer. icon_url : str The URL for the footer icon. proxy_icon_url : str A proxy URL for the footer icon, set by Discord. """ text = Field(text) icon_url = Field(text) proxy_icon_url = Field(text)