aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel.rs127
-rw-r--r--src/model/guild.rs21
-rw-r--r--src/model/id.rs8
-rw-r--r--src/model/user.rs11
4 files changed, 3 insertions, 164 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index b441e1f..7cd4077 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -17,13 +17,9 @@ use hyper::Client as HyperClient;
#[cfg(feature="methods")]
use serde_json::builder::ObjectBuilder;
#[cfg(feature="methods")]
-use std::fs::File;
-#[cfg(feature="methods")]
-use std::io::{Read, Write as IoWrite};
+use std::io::Read;
#[cfg(feature="methods")]
use std::mem;
-#[cfg(feature="methods")]
-use std::path::{Path, PathBuf};
#[cfg(all(feature="cache", feature="methods"))]
use super::utils;
@@ -124,71 +120,6 @@ impl Attachment {
Ok(bytes)
}
-
- /// Downloads the attachment, saving it to the provided directory path.
- /// Returns a path to the saved file.
- ///
- /// # Examples
- ///
- /// Download all of the attachments associated with a [`Message`] to a
- /// given folder:
- ///
- /// ```rust,no_run
- /// use serenity::Client;
- /// use std::env;
- /// use std::fs;
- ///
- /// // Make sure that the directory to store images in exists.
- /// fs::create_dir_all("./attachment_downloads")
- /// .expect("Error making directory");
- ///
- /// let token = env::var("DISCORD_TOKEN").expect("token in environment");
- /// let mut client = Client::login_bot(&token);
- ///
- /// client.on_message(|context, message| {
- /// for attachment in message.attachments {
- /// let dir = "./attachment_downloads";
- ///
- /// let _ = match attachment.download_to_directory(dir) {
- /// Ok(_saved_filepath) => {
- /// context.say(&format!("Saved {:?}", attachment.filename))
- /// },
- /// Err(why) => {
- /// println!("Error saving attachment: {:?}", why);
- /// context.say("Error saving attachment")
- /// },
- /// };
- /// }
- /// });
- ///
- /// client.on_ready(|_context, ready| {
- /// println!("{} is connected!", ready.user.name);
- /// });
- ///
- /// let _ = client.start();
- /// ```
- ///
- /// # Errors
- ///
- /// Returns an [`Error::Io`] when there is a problem reading the contents of
- /// the HTTP response, creating the file, or writing to the file.
- ///
- /// Returns an [`Error::Hyper`] when there is a problem retrieving the
- /// attachment.
- ///
- /// [`Error::Hyper`]: ../enum.Error.html#variant.Hyper
- /// [`Error::Io`]: ../enum.Error.html#variant.Io
- /// [`Message`]: struct.Message.html
- #[cfg(feature="methods")]
- pub fn download_to_directory<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf> {
- let bytes = self.download()?;
-
- let filepath: PathBuf = path.as_ref().join(&self.filename);
- let mut file = File::create(&filepath)?;
- file.write(&bytes)?;
-
- Ok(filepath)
- }
}
impl Channel {
@@ -592,41 +523,6 @@ impl Message {
}
}
- /// Retrieves the message author's member instance.
- ///
- /// **Note**: This will always return `None` for messages not sent in a
- /// [`Guild`].
- ///
- /// [`Guild`]: struct.Guild.html
- #[cfg(all(feature="cache", feature="methods"))]
- pub fn get_member(&self) -> Option<Member> {
- let cache = CACHE.read().unwrap();
-
- if let Some(ChannelRef::Guild(channel)) = cache.get_channel(self.channel_id) {
- if let Some(guild) = channel.guild_id.find() {
- if let Some(member) = guild.members.get(&self.author.id) {
- return Some(member.clone())
- }
- }
- }
-
- None
- }
-
- /// Retrieves the guild associated with this message.
- ///
- /// Returns `None` if the guild data does not exist in the cache, or if the
- /// message was not sent in a [`GuildChannel`].
- ///
- /// [`GuildChannel`]: struct.GuildChannel.html
- #[cfg(all(feature="cache", feature="methods"))]
- pub fn guild(&self) -> Option<Guild> {
- match self.guild_id().map(|x| CACHE.read().unwrap().get_guild(x).cloned()) {
- Some(Some(guild)) => Some(guild),
- _ => None,
- }
- }
-
/// Returns message content, but with user and role mentions replaced with
/// names and everyone/here mentions cancelled.
#[cfg(all(feature="cache", feature="methods"))]
@@ -654,19 +550,6 @@ impl Message {
.replace("@here", "@\u{200B}here")
}
- /// Retrieves the Id of the guild that the message was sent in, if sent in
- /// one.
- ///
- /// Returns `None` if the channel data or guild data does not exist in the
- /// cache.
- #[cfg(all(feature="cache", feature="methods"))]
- pub fn guild_id(&self) -> Option<GuildId> {
- match CACHE.read().unwrap().get_channel(self.channel_id) {
- Some(ChannelRef::Guild(channel)) => Some(channel.guild_id),
- _ => None,
- }
- }
-
/// True if message was sent using direct messages.
#[cfg(all(feature="cache", feature="methods"))]
pub fn is_private(&self) -> bool {
@@ -676,12 +559,6 @@ impl Message {
}
}
- /// True only if message was sent using a webhook.
- #[cfg(feature="methods")]
- pub fn is_webhook(&self) -> bool {
- self.webhook_id.is_some()
- }
-
/// Checks the length of a string to ensure that it is within Discord's
/// maximum message length limit.
///
@@ -1088,7 +965,7 @@ impl GuildChannel {
/// ```rust,ignore
/// channel.edit(|c| c
/// .name("test")
- /// .bitrate(71));
+ /// .bitrate(86400));
/// ```
#[cfg(feature="methods")]
pub fn edit<F>(&mut self, f: F) -> Result<()>
diff --git a/src/model/guild.rs b/src/model/guild.rs
index 7b8ed60..9b0c321 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -160,12 +160,6 @@ impl PartialGuild {
rest::edit_nickname(self.id.0, new_nickname)
}
- /// Finds a role by Id within the guild.
- #[cfg(feature="methods")]
- pub fn find_role<R: Into<RoleId>>(&self, role_id: R) -> Option<&Role> {
- self.roles.get(&role_id.into())
- }
-
/// Returns a formatted URL of the guild's icon, if the guild has an icon.
pub fn icon_url(&self) -> Option<String> {
self.icon.as_ref().map(|icon|
@@ -271,7 +265,7 @@ impl PartialGuild {
impl Guild {
#[cfg(all(feature="cache", feature="methods"))]
fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
- let member = match self.get_member(CACHE.read().unwrap().user.id) {
+ let member = match self.members.get(&CACHE.read().unwrap().user.id) {
Some(member) => member,
None => return Err(Error::Client(ClientError::ItemMissing)),
};
@@ -577,14 +571,6 @@ impl Guild {
rest::edit_nickname(self.id.0, new_nickname)
}
- /// Attempts to retrieve a [`GuildChannel`] with the given Id.
- ///
- /// [`GuildChannel`]: struct.GuildChannel.html
- pub fn get_channel<C: Into<ChannelId>>(&self, channel_id: C)
- -> Option<&GuildChannel> {
- self.channels.get(&channel_id.into())
- }
-
/// Retrieves the active invites for the guild.
///
/// **Note**: Requires the [Manage Guild] permission.
@@ -610,11 +596,6 @@ impl Guild {
rest::get_guild_invites(self.id.0)
}
- /// Attempts to retrieve the given user's member instance in the guild.
- pub fn get_member<U: Into<UserId>>(&self, user_id: U) -> Option<&Member> {
- self.members.get(&user_id.into())
- }
-
/// Retrieves the first [`Member`] found that matches the name - with an
/// optional discriminator - provided.
///
diff --git a/src/model/id.rs b/src/model/id.rs
index 9c2bb7a..17fd29c 100644
--- a/src/model/id.rs
+++ b/src/model/id.rs
@@ -88,14 +88,6 @@ impl GuildId {
rest::get_guild(self.0)
}
- /// Returns this Id as a `ChannelId`, which is useful when needing to use
- /// the guild Id to send a message to the default channel.
- #[cfg(feature="methods")]
- #[inline(always)]
- pub fn to_channel(&self) -> ChannelId {
- ChannelId(self.0)
- }
-
/// Retrieves the guild's webhooks.
///
/// **Note**: Requires the [Manage Webhooks] permission.
diff --git a/src/model/user.rs b/src/model/user.rs
index 253219a..8a2dd45 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -19,8 +19,6 @@ use serde_json::builder::ObjectBuilder;
use std::mem;
#[cfg(feature="methods")]
use super::Message;
-#[cfg(all(feature="cache", feature="methods"))]
-use super::Member;
#[cfg(feature="methods")]
use time::Timespec;
#[cfg(feature="methods")]
@@ -260,15 +258,6 @@ impl User {
}
}
- /// Gets the user's member instance for a guild.
- #[cfg(all(feature="cache", feature="methods"))]
- pub fn member<G>(&self, guild_id: G) -> Option<Member>
- where G: Into<GuildId> {
- let cache = CACHE.read().unwrap();
-
- cache.get_member(guild_id.into(), self.id).cloned()
- }
-
/// Returns a static formatted URL of the user's icon, if one exists.
///
/// This will always produce a WEBP image URL.