aboutsummaryrefslogtreecommitdiff
path: root/src/scope.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-12-03 13:48:37 -0800
committerZeyla Hellyer <[email protected]>2017-12-03 13:48:37 -0800
commitbc1870baa0ae1cf0f133c3f7009b11dab2c4f7b9 (patch)
tree2fdbdef751b2c67be6c7f6181a78d118b716cc43 /src/scope.rs
downloadoauth-master.tar.xz
oauth-master.zip
Initial commitHEADmaster
Diffstat (limited to 'src/scope.rs')
-rw-r--r--src/scope.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/scope.rs b/src/scope.rs
new file mode 100644
index 0000000..8ff55fc
--- /dev/null
+++ b/src/scope.rs
@@ -0,0 +1,77 @@
+use std::fmt::{Display, Formatter, Result as FmtResult};
+
+/// A Discord OAuth2 scope that can be granted.
+///
+/// If you require a scope that is not registered here, use [`Scope::Other`] and
+/// notify the library developers about the missing scope.
+///
+/// **Note**: The [`Scope::Bot`] and [`Scope::GuildsJoin`] scopes require you to
+/// have a bot account linked to your application. Also, in order to add a user
+/// to a guild, your bot has to already belong in that guild.
+///
+/// [`Scope::Bot`]: #variant.Bot
+/// [`Scope::GuildsJoin`]: #variant.GuildsJoin
+/// [`Scope::Other`]: #variant.Other
+#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
+pub enum Scope {
+ /// For OAuth2 bots, this puts the bot in the user's selected guild by
+ /// default.
+ Bot,
+ /// Allows the `/users/@me/connections` API endpoint to return linked
+ /// third-party accounts.
+ Connections,
+ /// Enables the `/users/@me` API endpoint to return an `email` field.
+ Email,
+ /// Allows the `/users/@me` API endpoint, without the `email` field.
+ Identify,
+ /// Allows the `/users/@me/guilds` API endpoint to return basic information
+ /// about all of a user's guilds.
+ Guilds,
+ /// Allows the `/invites/{code}` API endpoint to be used for joining users
+ /// to a guild.
+ GuildsJoin,
+ /// Allows your application to join users to a group DM.
+ GdmJoin,
+ /// For local RPC server API access, this allows you to read messages from
+ /// all cliuent channels.
+ ///
+ /// This is otherwise restricted to channels/guilds your application
+ /// creates.
+ MessagesRead,
+ /// For local RPC server access, this allows you to control a user's local
+ /// Discord client.
+ Rpc,
+ /// For local RPC server API access, this allows you to access the API as
+ /// the local user.
+ RpcApi,
+ /// For local RPC server API access, this allows you to receive
+ /// notifications pushed out to the user.
+ RpcNotificationsRead,
+ /// This generates a webhook that is returned in the OAuth token response
+ /// for authorization code grants.
+ WebhookIncoming,
+ /// A scope that does not have a matching enum variant.
+ Other(String),
+}
+
+impl Display for Scope {
+ fn fmt(&self, f: &mut Formatter) -> FmtResult {
+ use self::Scope::*;
+
+ f.write_str(match *self {
+ Bot => "bot",
+ Connections => "connections",
+ Email => "email",
+ Identify => "identify",
+ Guilds => "guilds",
+ GuildsJoin => "guilds.join",
+ GdmJoin => "gdm.join",
+ MessagesRead => "messages.read",
+ Rpc => "rpc",
+ RpcApi => "rpc.api",
+ RpcNotificationsRead => "rpc.notifications.read",
+ WebhookIncoming => "webhook.incoming",
+ Other(ref inner) => inner,
+ })
+ }
+}