Make pedantic clippy shut the fuck up

This commit is contained in:
lemonsh 2022-07-17 20:27:20 +02:00
parent 2a0e805719
commit 55ba7e1217
3 changed files with 27 additions and 24 deletions

View file

@ -83,30 +83,29 @@ impl<SF: Fn(String, String) -> anyhow::Result<()>> Bot<SF> {
return (self.sendmsg)(origin.into(), handler.lock().await.execute(msg).await?);
}
return (self.sendmsg)(origin.into(), "Unknown command.".into());
} else {
for trigger in &self.triggers {
let captures = trigger.0.captures(content)?;
if let Some(captures) = captures {
let msg = Context {
author,
content: Some(content),
db: &self.db,
history: &self.history,
};
return (self.sendmsg)(
origin.into(),
trigger.1.lock().await.execute(msg, captures).await?,
);
}
}
self.history.add_message(author, content).await;
}
for trigger in &self.triggers {
let captures = trigger.0.captures(content)?;
if let Some(captures) = captures {
let msg = Context {
author,
content: Some(content),
db: &self.db,
history: &self.history,
};
return (self.sendmsg)(
origin.into(),
trigger.1.lock().await.execute(msg, captures).await?,
);
}
}
self.history.add_message(author, content).await;
Ok(())
}
pub async fn handle_message(&self, origin: &str, author: &str, content: &str) {
if let Err(e) = self.handle_message_inner(origin, author, content).await {
let _ = (self.sendmsg)(origin.into(), format!("Error: {}", e));
let _err = (self.sendmsg)(origin.into(), format!("Error: {}", e));
}
}
}

View file

@ -16,7 +16,7 @@ impl MessageHistory {
pub async fn last_msg(&self, user: &str) -> Option<String> {
let map = self.map.read().await;
map.get(user).and_then(|d| d.get(0)).map(|s| s.to_string())
map.get(user).and_then(|d| d.get(0)).map(ToString::to_string)
}
pub async fn last_msgs(&self, user: &str, count: usize) -> Option<Vec<String>> {

View file

@ -1,3 +1,5 @@
#![allow(clippy::module_name_repetitions)]
use fancy_regex::Regex;
use std::env;
use std::fs::File;
@ -8,7 +10,7 @@ use std::thread;
use crate::bot::Bot;
use crate::commands::eval::Eval;
use crate::commands::help::Help;
use crate::commands::leek::Owo;
use crate::commands::leek::{Leet, Mock, Owo};
use crate::commands::quotes::{Grab, Quot};
use crate::commands::sed::Sed;
use crate::commands::spotify::Spotify;
@ -99,6 +101,8 @@ async fn main() -> anyhow::Result<()> {
bot.add_command("help".into(), Help);
bot.add_command("waifu".into(), Waifu::default());
bot.add_command("owo".into(), Owo);
bot.add_command("leet".into(), Leet);
bot.add_command("mock".into(), Mock);
bot.add_command("ev".into(), Eval::default());
bot.add_command("grab".into(), Grab);
bot.add_command("quot".into(), Quot);
@ -109,9 +113,9 @@ async fn main() -> anyhow::Result<()> {
if let Some(spotcfg) = cfg.spotify {
let creds = Credentials::new(&spotcfg.client_id, &spotcfg.client_secret);
let spotify = Spotify::new(creds).await?;
bot.add_trigger(Regex::new(r"(?:https?|spotify):(?://open\.spotify\.com/)?(track|artist|album|playlist)[/:]([a-zA-Z0-9]*)")?, spotify);
bot.add_trigger(Regex::new(r"(?:https?|spotify):(?://open\.spotify\.com/)?(track|artist|album|playlist)[/:]([a-zA-Z\d]*)")?, spotify);
} else {
tracing::warn!("Spotify module is disabled, because the config is missing")
tracing::warn!("Spotify module is disabled, because the config is missing");
}
bot.add_trigger(Regex::new(r"https?://[^\s/$.?#].\S*")?, Title::new()?);
#[cfg(feature = "debug")]
@ -164,9 +168,9 @@ async fn message_loop<SF: Fn(String, String) -> anyhow::Result<()>>(
if origin.is_channel_name() {
if let Some(author) = message.prefix.as_ref().and_then(|p| match p {
Prefix::Nickname(name, _, _) => Some(&name[..]),
_ => None,
Prefix::ServerName(_) => None,
}) {
bot.handle_message(origin, author, &content).await
bot.handle_message(origin, author, &content).await;
} else {
tracing::warn!("Couldn't get the author for a message");
}