Skip to content

Commit

Permalink
clippy part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
trueharuu committed Jun 26, 2024
1 parent 69665aa commit bd99388
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion assyst-core/src/command/fun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn findsong(ctxt: CommandCtxt<'_>, input: ImageUrl) -> anyhow::Result<
.await
.context("Failed to identify song")?;

if result.len() > 0 {
if !result.is_empty() {
let formatted = format!(
"**Title:** {}\n**Artist(s):** {}\n**YouTube Link:** <{}>",
result[0].title.clone(),
Expand Down
3 changes: 1 addition & 2 deletions assyst-core/src/command/misc/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub async fn help(ctxt: CommandCtxt<'_>, labels: Vec<Word>) -> anyhow::Result<()
let subcommands = command.subcommands();

match subcommands
.map(|x| x.iter().find(|y| y.0 == label).map(|z| z.1))
.flatten()
.and_then(|x| x.iter().find(|y| y.0 == label).map(|z| z.1))
{
Some(sc) => command = sc,
None => bail!(
Expand Down
2 changes: 1 addition & 1 deletion assyst-core/src/command/misc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub async fn exec(ctxt: CommandCtxt<'_>, script: Rest) -> anyhow::Result<()> {
examples = ["1"]
)]
pub async fn eval(ctxt: CommandCtxt<'_>, script: Rest) -> anyhow::Result<()> {
let result = fake_eval(&ctxt.assyst(), script.0, true, ctxt.data.message, Vec::new())
let result = fake_eval(ctxt.assyst(), script.0, true, ctxt.data.message, Vec::new())
.await
.context("Evaluation failed")?;

Expand Down
23 changes: 12 additions & 11 deletions assyst-core/src/command/misc/remind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ pub async fn list(ctxt: CommandCtxt<'_>) -> anyhow::Result<()> {
return Ok(());
}

let formatted = reminders
.iter()
.map(|reminder| {
format!(
"[#{}] {}: `{}`\n",
reminder.id,
format_discord_timestamp(reminder.timestamp as u64),
reminder.message
)
})
.collect::<String>();
let formatted = reminders.iter().fold(String::new(), |mut f, reminder| {
use std::fmt::Write;
writeln!(
f,
"[#{}] {}: `{}`",
reminder.id,
format_discord_timestamp(reminder.timestamp as u64),
reminder.message
)
.unwrap();
f
});

ctxt.reply(format!(":calendar: **Upcoming Reminders:**\n\n{formatted}"))
.await?;
Expand Down
4 changes: 2 additions & 2 deletions assyst-core/src/command/misc/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub async fn charge(ctxt: CommandCtxt<'_>, script: Codeblock, flags: ChargeFlags
"\nCompiler: {}\nExecutable: {}\nCommit Hash: {commit_hash}",
result.exit_code,
if let Some(b) = bin_result {
format!("{} (execution time {:?})", b.exit_code.to_string(), bin_time)
format!("{} (execution time {:?})", b.exit_code, bin_time)
} else {
"N/A".to_owned()
}
Expand Down Expand Up @@ -195,7 +195,7 @@ pub async fn dash(ctxt: CommandCtxt<'_>, script: Codeblock) -> anyhow::Result<()
EvalError::Exception(unrooted) => {
let fmt = format_value(unrooted.root(&mut scope), &mut scope);
if let Ok(f) = fmt {
format!("Exception: {}", f.to_string())
format!("Exception: {}", f)
} else {
format!("Exception: {:?}", fmt.unwrap_err())
}
Expand Down
2 changes: 1 addition & 1 deletion assyst-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'a> ParseCtxt<'a, RawMessageArgsIter<'a>> {
}

pub fn rest_all(&self, _: Label) -> String {
self.args.remainder().map(|x| x.to_owned()).unwrap_or(String::new())
self.args.remainder().map(|x| x.to_owned()).unwrap_or_default()
}
}

Expand Down
2 changes: 1 addition & 1 deletion assyst-core/src/rest/bad_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async fn translate_retry(
}

if let Some(data) = additional_data {
for (k, v) in data.into_iter() {
for (k, v) in data.iter() {
query_args.push((k, v.to_string()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion assyst-core/src/rest/cooltext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn burn_text(text: &str) -> anyhow::Result<Vec<u8>> {
.await?;

let url = cool_text_response.render_location;
let content = client.get(&url.replace("https", "http")).send().await?.bytes().await?;
let content = client.get(url.replace("https", "http")).send().await?.bytes().await?;

let mut hasher = DefaultHasher::new();
content.hash(&mut hasher);
Expand Down
2 changes: 1 addition & 1 deletion assyst-core/src/rest/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn fake_eval(
.post(format!("{}/eval", CONFIG.urls.eval))
.query(&[("returnBuffer", accept_image)])
.json(&FakeEvalBody {
code: code,
code,
data: Some(FakeEvalMessageData { args, message }),
})
.send()
Expand Down
2 changes: 1 addition & 1 deletion assyst-core/src/rest/r34.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::{bail, Context};
use rand::prelude::SliceRandom;
use serde::Deserialize;

static R34_URL: &'static str = "https://api.rule34.xxx/index.php?tags=";
static R34_URL: &str = "https://api.rule34.xxx/index.php?tags=";

#[derive(Deserialize, Clone)]
pub struct R34Result {
Expand Down
11 changes: 8 additions & 3 deletions assyst-core/src/rest/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ pub struct ApiResult {
}
impl ApiResult {
pub fn format(&self) -> &str {
if self.stdout == "" { &self.stderr } else { &self.stdout }
if self.stdout.is_empty() {
&self.stderr
} else {
&self.stdout
}
}
}

Expand Down Expand Up @@ -85,6 +89,7 @@ pub async fn godbolt(client: &Client, code: &str) -> Result<String, Error> {
.join("\n"))
}

#[allow(clippy::too_many_arguments)]
pub async fn request(
client: &Client,
path: &str,
Expand Down Expand Up @@ -152,7 +157,7 @@ pub fn prepend_code(code: &str) -> Cow<str> {
pub async fn run_miri(client: &Client, code: &str, channel: &str, opt: OptimizationLevel) -> Result<ApiResult, Error> {
let code = prepend_code(code);

miri(client, &*code, Some(channel), opt).await
miri(client, &code, Some(channel), opt).await
}

pub async fn run_clippy(
Expand All @@ -163,7 +168,7 @@ pub async fn run_clippy(
) -> Result<ApiResult, Error> {
let code = prepend_code(code);

clippy(client, &*code, Some(channel), opt).await
clippy(client, &code, Some(channel), opt).await
}

pub async fn run_binary(
Expand Down
16 changes: 6 additions & 10 deletions assyst-core/src/rest/web_media_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ pub async fn get_web_download_api_urls(assyst: ThreadSafeAssyst) -> anyhow::Resu
let test_urls = json
.iter()
.map(|entry: &InstancesQueryResult| {
if entry.protocol == "https" && entry.score >= TEST_SCORE_THRESHOLD {
format!("https://{}/api/json", entry.api)
} else if entry.api == "api.cobalt.tools" {
if (entry.protocol == "https" && entry.score >= TEST_SCORE_THRESHOLD) || (entry.api == "api.cobalt.tools") {
format!("https://{}/api/json", entry.api)
} else {
String::new()
Expand Down Expand Up @@ -193,7 +191,7 @@ pub async fn download_web_media(assyst: ThreadSafeAssyst, url: &str, opts: WebDo
req_result_url = Some(j.url.to_string());
break;
},
Err(e) => err = format!("Failed to deserialize download url: {}", e.to_string()),
Err(e) => err = format!("Failed to deserialize download url: {}", e),
}
} else {
let try_err = r.text().await;
Expand Down Expand Up @@ -224,24 +222,22 @@ pub async fn download_web_media(assyst: ThreadSafeAssyst, url: &str, opts: WebDo
break;
}
},
Err(d_e) => {
err = format!("Download request failed: {} (raw error: {})", d_e.to_string(), e)
},
Err(d_e) => err = format!("Download request failed: {} (raw error: {})", d_e, e),
}
},
Err(e) => err = format!("Failed to extract download request error: {}", e.to_string()),
Err(e) => err = format!("Failed to extract download request error: {}", e),
}
}
},
Err(e) => {
err = format!("Download request failed: {}", e.to_string());
err = format!("Download request failed: {}", e);
},
}
}

if let Some(r) = req_result_url {
let media = download_content(&assyst, &r, ABSOLUTE_INPUT_FILE_SIZE_LIMIT_BYTES, false).await?;
return Ok(media);
Ok(media)
} else if !err.is_empty() {
bail!("{err}");
} else {
Expand Down
4 changes: 2 additions & 2 deletions assyst-core/src/task/tasks/reminders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ async fn process_single_reminder(assyst: ThreadSafeAssyst, reminder: &Reminder)
}

async fn process_reminders(assyst: ThreadSafeAssyst, reminders: Vec<Reminder>) -> Result<(), anyhow::Error> {
if reminders.len() < 1 {
if reminders.is_empty() {
return Ok(());
}

for reminder in &reminders {
if let Err(e) = process_single_reminder(assyst.clone(), &reminder).await {
if let Err(e) = process_single_reminder(assyst.clone(), reminder).await {
err!("Failed to process reminder: {:?}", e);
}

Expand Down
4 changes: 2 additions & 2 deletions assyst-core/src/wsi_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ impl WsiHandler {
return Ok(p.tier as usize);
}

let user_tier2 = FreeTier2Requests::get_user_free_tier_2_requests(&*self.database_handler, user_id).await?;
let user_tier2 = FreeTier2Requests::get_user_free_tier_2_requests(&self.database_handler, user_id).await?;

if user_tier2.count > 0 {
user_tier2
.change_free_tier_2_requests(&*self.database_handler, -1)
.change_free_tier_2_requests(&self.database_handler, -1)
.await?;
Ok(2)
} else {
Expand Down
3 changes: 1 addition & 2 deletions assyst-database/src/model/reminder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl Reminder {
.bind(self.message_id)
.bind(&*self.message)
.execute(&handler.pool)
.await
.and_then(|_| Ok(()))
.await.map(|_| ())
}
}
2 changes: 1 addition & 1 deletion assyst-tag/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<'buf> DiagnosticBuilder<'buf> {
NoteKind::Note => {
out += &arrows.bold();
out += " ";
out += &message;
out += message;
},
}
},
Expand Down
4 changes: 2 additions & 2 deletions assyst-tag/src/subtags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pub fn set(parser: &mut Parser<'_>, (key, value): (String, String)) -> TResult<S
pub fn get(parser: &mut Parser<'_>, key: String) -> TResult<String> {
parser
.state()
.with_variables(|vars| -> TResult<String> { Ok(vars.get(&key).map(Clone::clone).unwrap_or_default()) })
.with_variables(|vars| -> TResult<String> { Ok(vars.get(&key).cloned().unwrap_or_default()) })
}

pub fn delete(parser: &mut Parser<'_>, key: String) -> TResult<String> {
Expand Down Expand Up @@ -373,7 +373,7 @@ pub fn sqrt(_: &mut Parser<'_>, arg: f64) -> TResult<String> {
}

pub fn e(_: &mut Parser<'_>, _: ()) -> TResult<String> {
Ok(std::f64::EPSILON.to_string())
Ok(f64::EPSILON.to_string())
}

pub fn pi(_: &mut Parser<'_>, _: ()) -> TResult<String> {
Expand Down

0 comments on commit bd99388

Please sign in to comment.