aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--definitions/structs/embed.yml6
-rw-r--r--definitions/structs/role.yml7
-rw-r--r--src/model/guild.rs10
-rw-r--r--src/model/mod.rs2
-rw-r--r--src/utils/builder/edit_role.rs2
-rw-r--r--src/utils/colour.rs11
6 files changed, 21 insertions, 17 deletions
diff --git a/definitions/structs/embed.yml b/definitions/structs/embed.yml
index 308562d..312bec9 100644
--- a/definitions/structs/embed.yml
+++ b/definitions/structs/embed.yml
@@ -7,10 +7,10 @@ fields:
optional: true
type: EmbedAuthor
- name: colour
- description: The color code of the embed.
+ description: The colour code of the embed.
from: color
- default: "0"
- type: u64
+ default: Colour::default()
+ type: Colour
- name: description
description: The description of the embed. This is the long string of text.
optional: true
diff --git a/definitions/structs/role.yml b/definitions/structs/role.yml
index 92f4d51..f3b0ffc 100644
--- a/definitions/structs/role.yml
+++ b/definitions/structs/role.yml
@@ -6,9 +6,10 @@ fields:
type: RoleId
- name: colour
from: color
- description: "The colour of the role in 0xRRGGBB format. Use `role.colour()`
- to retrieve an ergonomic color representation."
- type: u64
+ description: >
+ The colour of the role in 0xRRGGBB format. This is an ergonomic
+ representation of the inner value.
+ type: Colour
- name: hoist
description: "Whether the role is pinned above lesser roles, causing members
in the role to be seen above others."
diff --git a/src/model/guild.rs b/src/model/guild.rs
index 866cd19..1ab9bb3 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -17,7 +17,7 @@ use super::*;
use ::utils::builder::{EditGuild, EditMember, EditRole};
use ::client::{STATE, http};
use ::internal::prelude::*;
-use ::utils::{Colour, decode_array};
+use ::utils::decode_array;
impl From<Guild> for GuildContainer {
fn from(guild: Guild) -> GuildContainer {
@@ -919,14 +919,6 @@ impl PossibleGuild<Guild> {
}
impl Role {
- /// Generates a colour representation of the role. See
- /// [the documentation] on Colour for more information.
- ///
- /// [the documentation]: ../utils/struct.Colour.html
- pub fn colour(&self) -> Colour {
- Colour::new(self.colour as u32)
- }
-
/// Deletes the role.
///
/// **Note** Requires the [Manage Roles] permission.
diff --git a/src/model/mod.rs b/src/model/mod.rs
index fc226f9..f21da09 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -28,7 +28,7 @@ use self::utils::*;
use std::collections::HashMap;
use std::fmt;
use ::internal::prelude::*;
-use ::utils::decode_array;
+use ::utils::{Colour, decode_array};
// All of the enums and structs are imported here. These are built from the
// build script located at `./build.rs`.
diff --git a/src/utils/builder/edit_role.rs b/src/utils/builder/edit_role.rs
index f4fa7ef..d1e2c0e 100644
--- a/src/utils/builder/edit_role.rs
+++ b/src/utils/builder/edit_role.rs
@@ -37,7 +37,7 @@ impl EditRole {
/// Creates a new builder with the values of the given [`Role`].
pub fn new(role: &Role) -> Self {
EditRole(ObjectBuilder::new()
- .insert("color", role.colour)
+ .insert("color", role.colour.value)
.insert("hoist", role.hoist)
.insert("managed", role.managed)
.insert("mentionable", role.mentionable)
diff --git a/src/utils/colour.rs b/src/utils/colour.rs
index b9a3bf5..e2c70e6 100644
--- a/src/utils/colour.rs
+++ b/src/utils/colour.rs
@@ -1,4 +1,5 @@
use std::default::Default;
+use ::internal::prelude::*;
macro_rules! colour {
($struct_:ident; $($name:ident, $val:expr;)*) => {
@@ -49,6 +50,7 @@ macro_rules! colour {
/// [`Role`]: ../model/struct.Role.html
/// [`dark_teal`]: #method.dark_teal
/// [`get_g`]: #method.get_g
+#[derive(Clone, Copy, Debug)]
pub struct Colour {
/// The raw inner integer value of this Colour. This is worked with to
/// generate values such as the red component value.
@@ -63,6 +65,15 @@ impl Colour {
}
}
+ #[doc(hidden)]
+ pub fn decode(value: Value) -> Result<Colour> {
+ match value {
+ Value::U64(v) => Ok(Colour::new(v as u32)),
+ Value::I64(v) => Ok(Colour::new(v as u32)),
+ other => Err(Error::Decode("Expected valid colour", other)),
+ }
+ }
+
/// Returns the red RGB component of this Colour.
pub fn get_r(&self) -> u8 {
((self.value >> 16) & 255) as u8