aboutsummaryrefslogtreecommitdiff
path: root/src/scope.rs
blob: 8ff55fc2da00c32f6e1bc4a1a8337d72a7f04900 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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,
        })
    }
}