Skip to content

Commit

Permalink
ci: apply clippy suggestions for rust 1.65.0 (#214)
Browse files Browse the repository at this point in the history
* ci: apply clippy suggestions for rust 1.65.0

* refactor: switch to let-else statements

* ci: move from rust 1.59 to 1.65

* refactor: revert connection.rs
  • Loading branch information
aquelemiguel authored Nov 7, 2022
1 parent 2a8e1f7 commit 437e8b2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Build
strategy:
matrix:
rust-version: ["1.59", "stable"]
rust-version: ["1.65", "stable"]
runs-on: ubuntu-latest
steps:
- name: Repository Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub async fn queue(
drop(handler);

let mut cib = message
.await_component_interactions(&ctx)
.await_component_interactions(ctx)
.timeout(Duration::from_secs(EMBED_TIMEOUT))
.build();

Expand Down
45 changes: 24 additions & 21 deletions src/handlers/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,34 @@ pub struct IdleHandler {
#[async_trait]
impl EventHandler for IdleHandler {
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
if let EventContext::Track(track_list) = ctx {
// looks like the track list isn't ordered here, so the first track in the list isn't
// guaranteed to be the first track in the actual queue, so search the entire list
let bot_is_playing = track_list
.iter()
.any(|track| matches!(track.0.playing, PlayMode::Play));

// if there's a track playing, then reset the counter
if bot_is_playing {
self.count.store(0, Ordering::Relaxed);
return None;
}
let EventContext::Track(track_list) = ctx else {
return None;
};

// looks like the track list isn't ordered here, so the first track in the list isn't
// guaranteed to be the first track in the actual queue, so search the entire list
let bot_is_playing = track_list
.iter()
.any(|track| matches!(track.0.playing, PlayMode::Play));

if self.count.fetch_add(1, Ordering::Relaxed) >= self.limit {
let guild_id = self.interaction.guild_id?;
// if there's a track playing, then reset the counter
if bot_is_playing {
self.count.store(0, Ordering::Relaxed);
return None;
}

if self.manager.remove(guild_id).await.is_ok() {
self.interaction
.channel_id
.say(&self.http, IDLE_ALERT)
.await
.unwrap();
}
if self.count.fetch_add(1, Ordering::Relaxed) >= self.limit {
let guild_id = self.interaction.guild_id?;

if self.manager.remove(guild_id).await.is_ok() {
self.interaction
.channel_id
.say(&self.http, IDLE_ALERT)
.await
.unwrap();
}
}

None
}
}
28 changes: 16 additions & 12 deletions src/handlers/serenity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ impl EventHandler for SerenityHandler {
}

async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
if let Interaction::ApplicationCommand(mut command) = interaction {
if let Err(err) = self.run_command(&ctx, &mut command).await {
self.handle_error(&ctx, &mut command, err).await
}
let Interaction::ApplicationCommand(mut command) = interaction else {
return;
};

if let Err(err) = self.run_command(&ctx, &mut command).await {
self.handle_error(&ctx, &mut command, err).await
}
}

Expand Down Expand Up @@ -351,14 +353,16 @@ impl SerenityHandler {
}

async fn self_deafen(&self, ctx: &Context, guild: Option<GuildId>, new: VoiceState) {
if let Ok(user) = ctx.http.get_current_user().await {
if user.id == new.user_id && !new.deaf {
guild
.unwrap()
.edit_member(&ctx.http, new.user_id, |n| n.deafen(true))
.await
.unwrap();
}
let Ok(user) = ctx.http.get_current_user().await else {
return;
};

if user.id == new.user_id && !new.deaf {
guild
.unwrap()
.edit_member(&ctx.http, new.user_id, |n| n.deafen(true))
.await
.unwrap();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sources/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn ffmpeg(mut source: Child, metadata: Metadata, pre_args: &[&str]) ->

let ffmpeg = Command::new("ffmpeg")
.args(pre_args)
.args(&ffmpeg_args)
.args(ffmpeg_args)
.stdin(taken_stdout)
.stderr(Stdio::null())
.stdout(Stdio::piped())
Expand Down
50 changes: 25 additions & 25 deletions src/sources/youtube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ impl YouTubeRestartable {
.spawn()
.unwrap();

if let Some(stdout) = &mut child.stdout {
let reader = BufReader::new(stdout);

let lines = reader.lines().flatten().map(|line| {
let entry: Value = serde_json::from_str(&line).unwrap();
entry
.get("webpage_url")
.unwrap()
.as_str()
.unwrap()
.to_string()
});

Some(lines.collect())
} else {
None
}
let Some(stdout) = &mut child.stdout else {
return None;
};

let reader = BufReader::new(stdout);

let lines = reader.lines().flatten().map(|line| {
let entry: Value = serde_json::from_str(&line).unwrap();
entry
.get("webpage_url")
.unwrap()
.as_str()
.unwrap()
.to_string()
});

Some(lines.collect())
}
}

Expand All @@ -98,12 +98,12 @@ where
async fn call_restart(&mut self, time: Option<Duration>) -> SongbirdResult<Input> {
let (yt, metadata) = ytdl(self.uri.as_ref()).await?;

if let Some(time) = time {
let ts = format!("{:.3}", time.as_secs_f64());
ffmpeg(yt, metadata, &["-ss", &ts]).await
} else {
ffmpeg(yt, metadata, &[]).await
}
let Some(time) = time else {
return ffmpeg(yt, metadata, &[]).await;
};

let ts = format!("{:.3}", time.as_secs_f64());
ffmpeg(yt, metadata, &["-ss", &ts]).await
}

async fn lazy_init(&mut self) -> SongbirdResult<(Option<Metadata>, Codec, Container)> {
Expand All @@ -130,7 +130,7 @@ async fn ytdl(uri: &str) -> Result<(Child, Metadata), SongbirdError> {
];

let mut yt = Command::new("yt-dlp")
.args(&ytdl_args)
.args(ytdl_args)
.stdin(Stdio::null())
.stderr(Stdio::piped())
.stdout(Stdio::piped())
Expand Down Expand Up @@ -179,7 +179,7 @@ async fn _ytdl_metadata(uri: &str) -> SongbirdResult<Metadata> {
];

let youtube_dl_output = TokioCommand::new("yt-dlp")
.args(&ytdl_args)
.args(ytdl_args)
.stdin(Stdio::null())
.output()
.await?;
Expand Down

0 comments on commit 437e8b2

Please sign in to comment.