aboutsummaryrefslogtreecommitdiff
path: root/src/model/voice.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-04-11 08:15:37 -0700
committerZeyla Hellyer <[email protected]>2017-04-11 10:52:43 -0700
commitf6b27eb39c042e6779edc2d5d4b6e6c27d133eaf (patch)
treea6169fee3bf9ea75391101577dcb2982e3daa388 /src/model/voice.rs
parentClippy lints + permission byte literals (diff)
downloadserenity-f6b27eb39c042e6779edc2d5d4b6e6c27d133eaf.tar.xz
serenity-f6b27eb39c042e6779edc2d5d4b6e6c27d133eaf.zip
Switch to using serde for deserialization
The current build system is rudimentary, incomplete, and rigid, offering little in the way of customizing decoding options. To solve this, switch to using serde-derive with custom Deserialization implementations. This allows very simple deserialization when special logic does not need to be applied, yet allows us to implement our own deserialization logic when required. The problem with the build system was that it built enums and structs from YAML files. This is not so good, because it requires creating a custom build system (which was rudimentary), creating "special struct configs" when logic needed to be ever so slightly extended (rigid), and if special logic needed to be applied, a custom deserialization method would have been needed to be made anyway (incomplete). To solve this, switch to serde-derive and implementing Deserialize ourselves where required. This reduces YAML definitions that might look like: ```yaml --- name: Group description: > A group channel, potentially including other users, separate from a [`Guild`]. [`Guild`]: struct.Guild.html fields: - name: channel_id description: The Id of the group channel. from: id type: ChannelId - name: icon description: The optional icon of the group channel. optional: true type: string - name: last_message_id description: The Id of the last message sent. optional: true type: MessageId - name: last_pin_timestamp description: Timestamp of the latest pinned message. optional: true type: string - name: name description: The name of the group channel. optional: true type: string - name: owner_id description: The Id of the group channel creator. type: UserId - name: recipients description: Group channel's members. custom: decode_users t: UserId, Arc<RwLock<User>> type: hashmap ``` to: ```rs /// A group channel - potentially including other [`User`]s - separate from a /// [`Guild`]. /// /// [`Guild`]: struct.Guild.html /// [`User`]: struct.User.html pub struct Group { /// The Id of the group channel. #[serde(rename="id")] pub channel_id: ChannelId, /// The optional icon of the group channel. pub icon: Option<String>, /// The Id of the last message sent. pub last_message_id: Option<MessageId>, /// Timestamp of the latest pinned message. pub last_pin_timestamp: Option<String>, /// The name of the group channel. pub name: Option<String>, /// The Id of the group owner. pub owner_id: UserId, /// A map of the group's recipients. #[serde(deserialize_with="deserialize_users")] pub recipients: HashMap<UserId, Arc<RwLock<User>>>, } ``` This is much simpler and does not have as much boilerplate. There should not be any backwards incompatible changes other than the old, public - yet undocumented (and hidden from documentation) - decode methods being removed. Due to the nature of this commit, field names may be incorrect, and will need to be corrected as deserialization errors are found.
Diffstat (limited to 'src/model/voice.rs')
-rw-r--r--src/model/voice.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/model/voice.rs b/src/model/voice.rs
new file mode 100644
index 0000000..10c74b2
--- /dev/null
+++ b/src/model/voice.rs
@@ -0,0 +1,36 @@
+use super::*;
+
+/// Information about an available voice region.
+#[derive(Clone, Debug, Deserialize)]
+pub struct VoiceRegion {
+ /// Whether it is a custom voice region, which is used for events.
+ pub custom: bool,
+ /// Whether it is a deprecated voice region, which you should avoid using.
+ pub deprecated: bool,
+ /// The internal Id of the voice region.
+ pub id: String,
+ /// A recognizable name of the location of the voice region.
+ pub name: String,
+ /// Whether the voice region is optimal for use by the current user.
+ pub optional: bool,
+ /// an example hostname.
+ pub sample_hostname: String,
+ /// An example port.
+ pub sample_port: u64,
+ /// Indicator of whether the voice region is only for VIP guilds.
+ pub vip: bool,
+}
+
+/// A user's state within a voice channel.
+#[derive(Clone, Debug, Deserialize)]
+pub struct VoiceState {
+ pub channel_id: Option<ChannelId>,
+ pub deaf: bool,
+ pub mute: bool,
+ pub self_deaf: bool,
+ pub self_mute: bool,
+ pub session_id: String,
+ pub suppress: bool,
+ pub token: Option<String>,
+ pub user_id: UserId,
+}