diff options
| -rw-r--r-- | src/client/context.rs | 10 | ||||
| -rw-r--r-- | src/client/dispatch.rs | 4 | ||||
| -rw-r--r-- | src/ext/state/mod.rs | 14 | ||||
| -rw-r--r-- | src/model/channel.rs | 2 | ||||
| -rw-r--r-- | src/model/id.rs | 9 | ||||
| -rw-r--r-- | src/model/user.rs | 2 | ||||
| -rw-r--r-- | src/model/utils.rs | 4 |
7 files changed, 22 insertions, 23 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index cd3468f..53bc9e2 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -761,7 +761,7 @@ impl Context { let state = STATE.lock().unwrap(); let role = if let Some(role) = { - state.find_role(guild_id.0, role_id.0) + state.get_role(guild_id.0, role_id.0) } { role } else { @@ -821,8 +821,8 @@ impl Context { let channel_id = channel_id.into(); feature_state_enabled! {{ - if let Some(channel) = STATE.lock().unwrap().find_channel(channel_id) { - return Ok(channel.clone()) + if let Some(channel) = STATE.lock().unwrap().get_channel(channel_id) { + return Ok(channel.clone()); } }} @@ -836,7 +836,7 @@ impl Context { feature_state_enabled! {{ let state = STATE.lock().unwrap(); - if let Some(guild) = state.find_guild(guild_id) { + if let Some(guild) = state.get_guild(guild_id) { return Ok(guild.channels.clone()); } }} @@ -901,7 +901,7 @@ impl Context { feature_state_enabled! {{ let state = STATE.lock().unwrap(); - if let Some(member) = state.find_member(guild_id, user_id) { + if let Some(member) = state.get_member(guild_id, user_id) { return Ok(member.clone()); } }} diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index ad40497..8c10e75 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -255,7 +255,7 @@ fn handle_event(event: Event, feature_state! {{ let before = STATE.lock() .unwrap() - .find_channel(event.channel.id()); + .get_channel(event.channel.id()); update!(update_with_channel_update, event); thread::spawn(move || { @@ -413,7 +413,7 @@ fn handle_event(event: Event, // could fail under any circumstance. let after = STATE.lock() .unwrap() - .find_member(event.guild_id, event.user.id) + .get_member(event.guild_id, event.user.id) .unwrap() .clone(); diff --git a/src/ext/state/mod.rs b/src/ext/state/mod.rs index ce25e2a..637729c 100644 --- a/src/ext/state/mod.rs +++ b/src/ext/state/mod.rs @@ -109,11 +109,11 @@ impl State { .collect::<Vec<_>>() } - pub fn find_call<C: Into<ChannelId>>(&self, group_id: C) -> Option<&Call> { + pub fn get_call<C: Into<ChannelId>>(&self, group_id: C) -> Option<&Call> { self.calls.get(&group_id.into()) } - pub fn find_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> { + pub fn get_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> { let id = id.into(); for guild in self.guilds.values() { @@ -127,16 +127,16 @@ impl State { None } - pub fn find_guild<G: Into<GuildId>>(&self, id: G) -> Option<&LiveGuild> { + pub fn get_guild<G: Into<GuildId>>(&self, id: G) -> Option<&LiveGuild> { self.guilds.get(&id.into()) } - pub fn find_group<C: Into<ChannelId>>(&self, id: C) -> Option<&Group> { + pub fn get_group<C: Into<ChannelId>>(&self, id: C) -> Option<&Group> { self.groups.get(&id.into()) } - pub fn find_member<G, U>(&self, guild_id: G, user_id: U) - -> Option<&Member> where G: Into<GuildId>, U: Into<UserId> { + pub fn get_member<G, U>(&self, guild_id: G, user_id: U) -> Option<&Member> + where G: Into<GuildId>, U: Into<UserId> { self.guilds .get(&guild_id.into()) .map(|guild| { @@ -147,7 +147,7 @@ impl State { }) } - pub fn find_role<G, R>(&self, guild_id: G, role_id: R) -> Option<&Role> + pub fn get_role<G, R>(&self, guild_id: G, role_id: R) -> Option<&Role> where G: Into<GuildId>, R: Into<RoleId> { if let Some(guild) = self.guilds.get(&guild_id.into()) { guild.roles.get(&role_id.into()) diff --git a/src/model/channel.rs b/src/model/channel.rs index 07e6939..ddbd565 100644 --- a/src/model/channel.rs +++ b/src/model/channel.rs @@ -889,7 +889,7 @@ impl PublicChannel { /// optimized in the future. #[cfg(all(feature = "methods", feature = "state"))] pub fn guild(&self) -> Option<LiveGuild> { - STATE.lock().unwrap().find_guild(self.guild_id).cloned() + STATE.lock().unwrap().get_guild(self.guild_id).cloned() } /// Return a [`Mention`] which will link to this channel. diff --git a/src/model/id.rs b/src/model/id.rs index 8f925de..8c94dec 100644 --- a/src/model/id.rs +++ b/src/model/id.rs @@ -9,15 +9,15 @@ impl ChannelId { /// Search the state for the channel with the Id. #[cfg(feature="methods")] pub fn find(&self) -> Option<Channel> { - STATE.lock().unwrap().find_channel(*self) + STATE.lock().unwrap().get_channel(*self) } /// Search the state for the channel. If it can't be found, the channel is /// requested over REST. #[cfg(feature="methods")] pub fn get(&self) -> Result<Channel> { - if let Some(channel) = STATE.lock().unwrap().find_channel(*self) { - return Ok(channel); + if let Some(channel) = STATE.lock().unwrap().get_channel(*self) { + return Ok(channel.clone()); } http::get_channel(self.0) @@ -74,11 +74,10 @@ impl From<Emoji> for EmojiId { } impl GuildId { - /// Search the state for the guild. #[cfg(feature="methods")] pub fn find(&self) -> Option<LiveGuild> { - STATE.lock().unwrap().find_guild(*self).cloned() + STATE.lock().unwrap().get_guild(*self).cloned() } /// Requests the guild over REST. diff --git a/src/model/user.rs b/src/model/user.rs index e4699ce..efe41fd 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -118,7 +118,7 @@ impl User { feature_state! {{ let state = STATE.lock().unwrap(); - return state.find_role(guild_id, role_id).is_some(); + return state.get_role(guild_id, role_id).is_some(); } else { return true; }} diff --git a/src/model/utils.rs b/src/model/utils.rs index 92dfbd9..db39939 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -278,7 +278,7 @@ pub fn user_has_perms(channel_id: ChannelId, let state = STATE.lock().unwrap(); let current_user = &state.user; - let channel = match state.find_channel(channel_id) { + let channel = match state.get_channel(channel_id) { Some(channel) => channel, None => return Err(Error::Client(ClientError::ItemMissing)), }; @@ -290,7 +290,7 @@ pub fn user_has_perms(channel_id: ChannelId, Channel::Public(channel) => channel.guild_id, }; - let guild = match state.find_guild(guild_id) { + let guild = match state.get_guild(guild_id) { Some(guild) => guild, None => return Err(Error::Client(ClientError::ItemMissing)), }; |