aboutsummaryrefslogtreecommitdiff
path: root/src/builder/get_messages.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-22 17:02:00 -0700
committerZeyla Hellyer <[email protected]>2017-05-22 17:02:00 -0700
commit9969be60cf320797c37b317da24d9a08fd5eafa5 (patch)
treef27bf7a57af95bbc11990b1edcea9cca99276964 /src/builder/get_messages.rs
parentReasonably derive Debug on items (diff)
downloadserenity-9969be60cf320797c37b317da24d9a08fd5eafa5.tar.xz
serenity-9969be60cf320797c37b317da24d9a08fd5eafa5.zip
Restructure modules
Modules are now separated into a fashion where the library can be used for most use cases, without needing to compile the rest. The core of serenity, with no features enabled, contains only the struct (model) definitions, constants, and prelude. Models do not have most functions compiled in, as that is separated into the `model` feature. The `client` module has been split into 3 modules: `client`, `gateway`, and `http`. `http` contains functions to interact with the REST API. `gateway` contains the Shard to interact with the gateway, requiring `http` for retrieving the gateway URL. `client` requires both of the other features and acts as an abstracted interface over both the gateway and REST APIs, handling the event loop. The `builder` module has been separated from `utils`, and can now be optionally compiled in. It and the `http` feature are required by the `model` feature due to a large number of methods requiring access to them. `utils` now contains a number of utilities, such as the Colour struct, the `MessageBuilder`, and mention parsing functions. Each of the original `ext` modules are still featured, with `cache` not requiring any feature to be enabled, `framework` requiring the `client`, `model`, and `utils`, and `voice` requiring `gateway`. In total the features and their requirements are: - `builder`: none - `cache`: none - `client`: `gateway`, `http` - `framework`: `client`, `model`, `utils` - `gateway`: `http` - `http`: none - `model`: `builder`, `http` - `utils`: none - `voice`: `gateway` The default features are `builder`, `cache`, `client`, `framework`, `gateway`, `model`, `http`, and `utils`. To help with forwards compatibility, modules have been re-exported from their original locations.
Diffstat (limited to 'src/builder/get_messages.rs')
-rw-r--r--src/builder/get_messages.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs
new file mode 100644
index 0000000..b9142a1
--- /dev/null
+++ b/src/builder/get_messages.rs
@@ -0,0 +1,75 @@
+use std::collections::BTreeMap;
+use ::model::MessageId;
+
+/// Builds a request for a request to the API to retrieve messages.
+///
+/// This can have 2 different sets of parameters. The first set is around where
+/// to get the messages:
+///
+/// - `after`
+/// - `around`
+/// - `before`
+/// - `most_recent`
+///
+/// These can not be mixed, and the first in the list alphabetically will be
+/// used. If one is not specified, `most_recent` will be used.
+///
+/// The fourth parameter is to specify the number of messages to retrieve. This
+/// does not _need_ to be called and defaults to a value of 50.
+///
+/// This should be used only for retrieving messages; see
+/// [`Client::get_messages`] for examples.
+///
+/// [`Client::get_messages`]: ../client/struct.Client.html#method.get_messages
+#[derive(Clone, Debug, Default)]
+pub struct GetMessages(pub BTreeMap<String, u64>);
+
+impl GetMessages {
+ /// Indicates to retrieve the messages after a specific message, given by
+ /// its Id.
+ pub fn after<M: Into<MessageId>>(mut self, message_id: M) -> Self {
+ self.0.insert("after".to_owned(), message_id.into().0);
+
+ self
+ }
+
+ /// Indicates to retrieve the messages _around_ a specific message in either
+ /// direction (before+after) the given message.
+ pub fn around<M: Into<MessageId>>(mut self, message_id: M) -> Self {
+ self.0.insert("around".to_owned(), message_id.into().0);
+
+ self
+ }
+
+ /// Indicates to retrieve the messages before a specific message, given by
+ /// its Id.
+ pub fn before<M: Into<MessageId>>(mut self, message_id: M) -> Self {
+ self.0.insert("before".to_owned(), message_id.into().0);
+
+ self
+ }
+
+ /// The maximum number of messages to retrieve for the query.
+ ///
+ /// If this is not specified, a default value of 50 is used.
+ ///
+ /// **Note**: This field is capped to 100 messages due to a Discord
+ /// limitation. If an amount larger than 100 is supplied, it will be
+ /// reduced.
+ pub fn limit(mut self, limit: u64) -> Self {
+ self.0.insert("limit".to_owned(), if limit > 100 {
+ 100
+ } else {
+ limit
+ });
+
+ self
+ }
+
+ /// This is a function that is here for completeness. You do not need to
+ /// call this - except to clear previous calls to `after`, `around`, and
+ /// `before` - as it is the default value.
+ pub fn most_recent(self) -> Self {
+ self
+ }
+}