aboutsummaryrefslogtreecommitdiff
path: root/src/ext
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext')
-rw-r--r--src/ext/cache/mod.rs150
-rw-r--r--src/ext/framework/command.rs15
-rw-r--r--src/ext/framework/mod.rs32
-rw-r--r--src/ext/voice/audio.rs2
-rw-r--r--src/ext/voice/connection.rs18
-rw-r--r--src/ext/voice/threading.rs8
6 files changed, 34 insertions, 191 deletions
diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs
index 0981cf3..2272178 100644
--- a/src/ext/cache/mod.rs
+++ b/src/ext/cache/mod.rs
@@ -244,7 +244,7 @@ impl Cache {
pub fn all_guilds(&self) -> Vec<GuildId> {
self.guilds
.values()
- .map(|s| s.id)
+ .map(|g| g.id)
.chain(self.unavailable_guilds.iter().cloned())
.collect()
}
@@ -259,7 +259,7 @@ impl Cache {
guild.id
})
- .collect::<Vec<_>>()
+ .collect::<Vec<GuildId>>()
}
/// Retrieves a reference to a [`Call`] from the cache based on the
@@ -324,8 +324,9 @@ impl Cache {
/// let channel = match cache.get_guild_channel(message.channel_id) {
/// Some(channel) => channel,
/// None => {
- /// context.say("Could not find guild's channel data")
- /// .map_err(|why| println!("Error sending message: {:?}", why));
+ /// if let Err(why) = context.say("Could not find guild's channel data") {
+ /// println!("Error sending message: {:?}", why);
+ /// }
///
/// return;
/// },
@@ -406,7 +407,7 @@ impl Cache {
guild.members.get(&user_id.into())
}).and_then(|x| match x {
Some(x) => Some(x),
- _ => None,
+ None => None,
})
}
@@ -422,130 +423,6 @@ impl Cache {
}
}
- /// Update the cache according to the changes described in the given event.
- #[allow(cyclomatic_complexity)]
- #[allow(unneeded_field_pattern)]
- #[doc(hidden)]
- pub fn update(&mut self, event: &Event) {
- match *event {
- Event::CallCreate(ref event) => {
- self.update_with_call_create(event);
- },
- Event::CallDelete(ref event) => {
- self.update_with_call_delete(event);
- },
- Event::CallUpdate(ref event) => {
- self.update_with_call_update(event, false);
- },
- Event::ChannelCreate(ref event) => {
- self.update_with_channel_create(event);
- },
- Event::ChannelDelete(ref event) => {
- self.update_with_channel_delete(event);
- },
- Event::ChannelPinsUpdate(ref event) => {
- self.update_with_channel_pins_update(event);
- },
- Event::ChannelRecipientAdd(ref event) => {
- self.update_with_channel_recipient_add(event);
- },
- Event::ChannelRecipientRemove(ref event) => {
- self.update_with_channel_recipient_remove(event);
- },
- Event::ChannelUpdate(ref event) => {
- self.update_with_channel_update(event);
- },
- Event::GuildCreate(ref event) => {
- self.update_with_guild_create(event);
- },
- Event::GuildDelete(ref event) => {
- self.update_with_guild_delete(event);
- },
- Event::GuildEmojisUpdate(ref event) => {
- self.update_with_guild_emojis_update(event);
- },
- Event::GuildMemberAdd(ref event) => {
- self.update_with_guild_member_add(event);
- },
- Event::GuildMemberRemove(ref event) => {
- self.update_with_guild_member_remove(event);
- },
- Event::GuildMemberUpdate(ref event) => {
- self.update_with_guild_member_update(event);
- },
- Event::GuildMembersChunk(ref event) => {
- self.update_with_guild_members_chunk(event);
- },
- Event::GuildRoleCreate(ref event) => {
- self.update_with_guild_role_create(event);
- },
- Event::GuildRoleDelete(ref event) => {
- self.update_with_guild_role_delete(event);
- },
- Event::GuildRoleUpdate(ref event) => {
- self.update_with_guild_role_update(event);
- },
- Event::GuildSync(ref event) => {
- self.update_with_guild_sync(event);
- },
- Event::GuildUnavailable(ref event) => {
- self.update_with_guild_unavailable(event);
- },
- Event::GuildUpdate(ref event) => {
- self.update_with_guild_update(event);
- },
- Event::PresencesReplace(ref event) => {
- self.update_with_presences_replace(event);
- },
- Event::PresenceUpdate(ref event) => {
- self.update_with_presence_update(event);
- },
- Event::Ready(ref event) => {
- self.update_with_ready(event);
- },
- Event::RelationshipAdd(ref event) => {
- self.update_with_relationship_add(event);
- },
- Event::RelationshipRemove(ref event) => {
- self.update_with_relationship_remove(event);
- },
- Event::UserGuildSettingsUpdate(ref event) => {
- self.update_with_user_guild_settings_update(event);
- },
- Event::UserNoteUpdate(ref event) => {
- self.update_with_user_note_update(event);
- },
- Event::UserSettingsUpdate(ref event) => {
- self.update_with_user_settings_update(event, false);
- },
- Event::UserUpdate(ref event) => {
- self.update_with_user_update(event);
- },
- Event::VoiceStateUpdate(ref event) => {
- self.update_with_voice_state_update(event);
- },
- Event::ChannelPinsAck(_) |
- Event::FriendSuggestionCreate(_) |
- Event::FriendSuggestionDelete(_) |
- Event::GuildBanAdd(_) |
- Event::GuildBanRemove(_) |
- Event::GuildIntegrationsUpdate(_) |
- Event::MessageAck(_) |
- Event::MessageCreate(_) |
- Event::MessageDelete(_) |
- Event::MessageDeleteBulk(_) |
- Event::MessageUpdate(_) |
- Event::ReactionAdd(_) |
- Event::ReactionRemove(_) |
- Event::ReactionRemoveAll(_) |
- Event::Resumed(_) |
- Event::TypingStart(_) |
- Event::VoiceServerUpdate(_) |
- Event::WebhookUpdate(_) |
- Event::Unknown(_) => {},
- }
- }
-
#[doc(hidden)]
pub fn update_with_call_create(&mut self, event: &CallCreateEvent) {
match self.calls.entry(event.call.channel_id) {
@@ -604,12 +481,10 @@ impl Cache {
guild.channels.insert(channel.id, channel.clone())
});
- let ch = match ch {
- Some(Some(ch)) => Some(ch),
+ match ch {
+ Some(Some(ch)) => Some(Channel::Guild(ch)),
_ => None,
- };
-
- ch.map(Channel::Guild)
+ }
},
}
}
@@ -695,7 +570,8 @@ impl Cache {
let dest = e.get_mut();
if group.recipients.is_empty() {
- let recipients = mem::replace(&mut dest.recipients, HashMap::new());
+ let recipients = mem::replace(&mut dest.recipients,
+ HashMap::new());
dest.clone_from(group);
@@ -1075,8 +951,8 @@ impl Cache {
let finding = call.voice_states
.get_mut(&event.voice_state.user_id);
- if let Some(grp_state) = finding {
- grp_state.clone_from(&event.voice_state);
+ if let Some(group_state) = finding {
+ group_state.clone_from(&event.voice_state);
return;
}
diff --git a/src/ext/framework/command.rs b/src/ext/framework/command.rs
index e0a4616..46338a1 100644
--- a/src/ext/framework/command.rs
+++ b/src/ext/framework/command.rs
@@ -1,5 +1,5 @@
use std::sync::Arc;
-use super::{CommandType, Configuration};
+use super::Configuration;
use ::client::Context;
use ::model::Message;
@@ -8,15 +8,14 @@ pub type Command = Fn(&Context, &Message, Vec<String>) + Send + Sync;
#[doc(hidden)]
pub type InternalCommand = Arc<Command>;
-pub fn positions(content: &str, conf: &Configuration)
- -> Option<(Vec<usize>, CommandType)> {
+pub fn positions(content: &str, conf: &Configuration) -> Option<Vec<usize>> {
if let Some(ref prefix) = conf.prefix {
// Find out if they were mentioned. If not, determine if the prefix
// was used. If not, return None.
- let (mut positions, kind) = if let Some(mention_end) = find_mention_end(content, conf) {
- (vec![mention_end], CommandType::Mention)
+ let mut positions = if let Some(mention_end) = find_mention_end(content, conf) {
+ vec![mention_end]
} else if content.starts_with(prefix) {
- (vec![prefix.len()], CommandType::Prefix)
+ vec![prefix.len()]
} else {
return None;
};
@@ -29,7 +28,7 @@ pub fn positions(content: &str, conf: &Configuration)
positions.insert(0, pos + 1);
}
- Some((positions, kind))
+ Some(positions)
} else if conf.on_mention.is_some() {
match find_mention_end(content, conf) {
Some(mention_end) => {
@@ -39,7 +38,7 @@ pub fn positions(content: &str, conf: &Configuration)
positions.insert(0, mention_end + 1);
}
- Some((positions, CommandType::Mention))
+ Some(positions)
},
None => None,
}
diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs
index e79bd18..a470550 100644
--- a/src/ext/framework/mod.rs
+++ b/src/ext/framework/mod.rs
@@ -125,34 +125,6 @@ macro_rules! command {
};
}
-/// The type of command being received.
-///
-/// The [`Mention`] variant is emitted if the bot is being commanded via a
-/// mention (`<@USER_ID>` or `<@!USER_ID>`). This can only be emitted if
-/// [`Configuration::on_mention`] is set to `true`.
-///
-/// The [`Prefix`] variant is emitted if a message starts with the prefix set
-/// via [`Configuration::prefix`].
-///
-/// [`Mention`]: #variant.Mention
-/// [`Prefix`]: #variant.Prefix
-// This is public due to being leaked by [`command::positions`], which is used
-// in [`Framework::dispatch`]. It therefore is hidden from the docs, due to
-// having no use to users.
-//
-// [`Framework::dispatch`]: struct.Framework.html#method.dispatch
-// [`command::positions`]: command/fn.positions.html
-#[derive(Clone, Copy, Debug)]
-#[doc(hidden)]
-pub enum CommandType {
- /// This is emitted if the bot is being commanded via a mention
- /// (`<@USER_ID>` or `<@!USER_ID>`). This can only be emitted if
- /// [`Configuration::on_mention`] is set to `true`.
- Mention,
- None,
- Prefix,
-}
-
/// A utility for easily managing dispatches to commands.
///
/// Refer to the [module-level documentation] for more information.
@@ -214,7 +186,6 @@ impl Framework {
pub fn configure<F>(mut self, f: F) -> Self
where F: FnOnce(Configuration) -> Configuration {
self.configuration = f(self.configuration);
- self.initialized = true;
self
}
@@ -224,7 +195,7 @@ impl Framework {
let res = command::positions(&message.content, &self.configuration);
let positions = match res {
- Some((positions, _kind)) => positions,
+ Some(positions) => positions,
None => return,
};
@@ -358,7 +329,6 @@ impl Framework {
where F: Fn(&Context, &Message) -> bool + Send + Sync + 'static,
S: Into<String> {
self.checks.insert(command.into(), Arc::new(check));
- self.initialized = true;
self
}
diff --git a/src/ext/voice/audio.rs b/src/ext/voice/audio.rs
index 814cd69..ea8c87a 100644
--- a/src/ext/voice/audio.rs
+++ b/src/ext/voice/audio.rs
@@ -1,5 +1,3 @@
-use ::model::UserId;
-
pub const HEADER_LEN: usize = 12;
pub const SAMPLE_RATE: u32 = 48000;
diff --git a/src/ext/voice/connection.rs b/src/ext/voice/connection.rs
index 8f1821d..f88a3ff 100644
--- a/src/ext/voice/connection.rs
+++ b/src/ext/voice/connection.rs
@@ -26,7 +26,7 @@ use websocket::stream::WebSocketStream;
use ::internal::prelude::*;
use ::internal::ws_impl::{ReceiverExt, SenderExt};
use ::internal::Timer;
-use ::model::VoiceEvent;
+use ::model::event::VoiceEvent;
enum ReceiverStatus {
Udp(Vec<u8>),
@@ -165,11 +165,11 @@ impl Connection {
}
#[allow(unused_variables)]
- pub fn update(&mut self,
- source: &mut Option<Box<AudioSource>>,
- receiver: &mut Option<Box<AudioReceiver>>,
- audio_timer: &mut Timer)
- -> Result<()> {
+ pub fn cycle(&mut self,
+ source: &mut Option<Box<AudioSource>>,
+ receiver: &mut Option<Box<AudioReceiver>>,
+ audio_timer: &mut Timer)
+ -> Result<()> {
let mut buffer = [0i16; 960 * 2];
let mut packet = [0u8; 512];
let mut nonce = secretbox::Nonce([0; 24]);
@@ -230,7 +230,7 @@ impl Connection {
try!(self.sender.send_json(&payload::build_keepalive()));
}
- // Send the UDP keepalive if it's time
+ // Send UDP keepalive if it's time
if self.audio_timer.check() {
let mut bytes = [0; 4];
try!((&mut bytes[..]).write_u32::<BigEndian>(self.ssrc));
@@ -286,7 +286,7 @@ impl Connection {
nonce.0[..HEADER_LEN].clone_from_slice(&packet[..HEADER_LEN]);
- let extent = packet.len() - 16;
+ let sl_index = packet.len() - 16;
let buffer_len = if self.encoder_stereo {
960 * 2
} else {
@@ -294,7 +294,7 @@ impl Connection {
};
let len = try!(self.encoder.encode(&buffer[..buffer_len],
- &mut packet[HEADER_LEN..extent]));
+ &mut packet[HEADER_LEN..sl_index]));
let crypted = {
let slice = &packet[HEADER_LEN..HEADER_LEN + len];
secretbox::seal(slice, &nonce, &self.key)
diff --git a/src/ext/voice/threading.rs b/src/ext/voice/threading.rs
index bbbffd1..8d3599b 100644
--- a/src/ext/voice/threading.rs
+++ b/src/ext/voice/threading.rs
@@ -66,11 +66,11 @@ fn runner(rx: MpscReceiver<Status>) {
// another event.
let error = match connection.as_mut() {
Some(connection) => {
- let update = connection.update(&mut sender,
- &mut receiver,
- &mut timer);
+ let cycle = connection.cycle(&mut sender,
+ &mut receiver,
+ &mut timer);
- match update {
+ match cycle {
Ok(()) => false,
Err(why) => {
error!("[Voice] Error updating connection: {:?}", why);