From bcd16dddb8cc3086a13524c79676f3a8bebbc524 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sat, 16 Dec 2017 08:39:36 -0800 Subject: Break up the model module The `model` module has historically been one giant module re-exporting all of the model types, which is somewhere around 100 types. This can be a lot to look at for a new user and somewhat overwhelming, especially with a large number of fine-grained imports from the module. The module is now neatly split up into submodules, mostly like it has been internally since the early versions of the library. The submodules are: - application - channel - error - event - gateway - guild - id - invite - misc - permissions - prelude - user - voice - webhook Each submodule contains types that are "owned" by the module. For example, the `guild` submodule contains, but not limited to, Emoji, AuditLogsEntry, Role, and Member. `channel` contains, but not limited to, Attachment, Embed, Message, and Reaction. Upgrade path: Instead of glob importing the models via `use serenity::model::*;`, instead glob import via the prelude: ```rust use serenity::model::prelude::*; ``` Instead of importing from the root model module: ```rust use serenity::model::{Guild, Message, OnlineStatus, Role, User}; ``` instead import from the submodules like so: ```rust use serenity::model::channel::Message; use serenity::model::guild::{Guild, Role}; use serenity::model::user::{OnlineStatus, User}; ``` --- src/model/application.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/model/application.rs (limited to 'src/model/application.rs') diff --git a/src/model/application.rs b/src/model/application.rs new file mode 100644 index 0000000..dca8e41 --- /dev/null +++ b/src/model/application.rs @@ -0,0 +1,84 @@ +//! Models about OAuth2 applications. + +use super::id::UserId; +use super::user::User; +use super::utils::default_true; + +/// Information about a user's application. An application does not necessarily +/// have an associated bot user. +#[derive(Clone, Debug, Deserialize)] +pub struct ApplicationInfo { + /// The bot user associated with the application. See [`BotApplication`] for + /// more information. + /// + /// [`BotApplication`]: struct.BotApplication.html + pub bot: Option, + /// Indicator of whether the bot is public. + /// + /// If a bot is public, anyone may invite it to their [`Guild`]. While a bot + /// is private, only the owner may add it to a guild. + /// + /// [`Guild`]: struct.Guild.html + #[serde(default = "default_true")] + pub bot_public: bool, + /// Indicator of whether the bot requires an OAuth2 code grant. + pub bot_require_code_grant: bool, + /// A description of the application, assigned by the application owner. + pub description: String, + /// A set of bitflags assigned to the application, which represent gated + /// feature flags that have been enabled for the application. + pub flags: Option, + /// A hash pointing to the application's icon. + /// + /// This is not necessarily equivalent to the bot user's avatar. + pub icon: Option, + /// The unique numeric Id of the application. + pub id: UserId, + /// The name assigned to the application by the application owner. + pub name: String, + /// A list of redirect URIs assigned to the application. + pub redirect_uris: Vec, + /// A list of RPC Origins assigned to the application. + pub rpc_origins: Vec, + /// The given secret to the application. + /// + /// This is not equivalent to the application's bot user's token. + pub secret: String, +} + +/// Information about an application with an application's bot user. +#[derive(Clone, Debug, Deserialize)] +pub struct BotApplication { + /// The unique Id of the bot user. + pub id: UserId, + /// A hash of the avatar, if one is assigned. + /// + /// Can be used to generate a full URL to the avatar. + pub avatar: Option, + /// Indicator of whether it is a bot. + #[serde(default)] + pub bot: bool, + /// The discriminator assigned to the bot user. + /// + /// While discriminators are not unique, the `username#discriminator` pair + /// is. + pub discriminator: u16, + /// The bot user's username. + pub name: String, + /// The token used to authenticate as the bot user. + /// + /// **Note**: Keep this information private, as untrusted sources can use it + /// to perform any action with a bot user. + pub token: String, +} + +/// Information about the current application and its owner. +#[derive(Clone, Debug, Deserialize)] +pub struct CurrentApplicationInfo { + pub description: String, + pub icon: Option, + pub id: UserId, + pub name: String, + pub owner: User, + #[serde(default)] pub rpc_origins: Vec, +} -- cgit v1.2.3