Make pedantic clippy shut the fuck up
This commit is contained in:
parent
2a0e805719
commit
55ba7e1217
35
src/bot.rs
35
src/bot.rs
|
@ -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(), handler.lock().await.execute(msg).await?);
|
||||||
}
|
}
|
||||||
return (self.sendmsg)(origin.into(), "Unknown command.".into());
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_message(&self, origin: &str, author: &str, content: &str) {
|
pub async fn handle_message(&self, origin: &str, author: &str, content: &str) {
|
||||||
if let Err(e) = self.handle_message_inner(origin, author, content).await {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ impl MessageHistory {
|
||||||
|
|
||||||
pub async fn last_msg(&self, user: &str) -> Option<String> {
|
pub async fn last_msg(&self, user: &str) -> Option<String> {
|
||||||
let map = self.map.read().await;
|
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>> {
|
pub async fn last_msgs(&self, user: &str, count: usize) -> Option<Vec<String>> {
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(clippy::module_name_repetitions)]
|
||||||
|
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -8,7 +10,7 @@ use std::thread;
|
||||||
use crate::bot::Bot;
|
use crate::bot::Bot;
|
||||||
use crate::commands::eval::Eval;
|
use crate::commands::eval::Eval;
|
||||||
use crate::commands::help::Help;
|
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::quotes::{Grab, Quot};
|
||||||
use crate::commands::sed::Sed;
|
use crate::commands::sed::Sed;
|
||||||
use crate::commands::spotify::Spotify;
|
use crate::commands::spotify::Spotify;
|
||||||
|
@ -99,6 +101,8 @@ async fn main() -> anyhow::Result<()> {
|
||||||
bot.add_command("help".into(), Help);
|
bot.add_command("help".into(), Help);
|
||||||
bot.add_command("waifu".into(), Waifu::default());
|
bot.add_command("waifu".into(), Waifu::default());
|
||||||
bot.add_command("owo".into(), Owo);
|
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("ev".into(), Eval::default());
|
||||||
bot.add_command("grab".into(), Grab);
|
bot.add_command("grab".into(), Grab);
|
||||||
bot.add_command("quot".into(), Quot);
|
bot.add_command("quot".into(), Quot);
|
||||||
|
@ -109,9 +113,9 @@ async fn main() -> anyhow::Result<()> {
|
||||||
if let Some(spotcfg) = cfg.spotify {
|
if let Some(spotcfg) = cfg.spotify {
|
||||||
let creds = Credentials::new(&spotcfg.client_id, &spotcfg.client_secret);
|
let creds = Credentials::new(&spotcfg.client_id, &spotcfg.client_secret);
|
||||||
let spotify = Spotify::new(creds).await?;
|
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 {
|
} 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()?);
|
bot.add_trigger(Regex::new(r"https?://[^\s/$.?#].\S*")?, Title::new()?);
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
|
@ -164,9 +168,9 @@ async fn message_loop<SF: Fn(String, String) -> anyhow::Result<()>>(
|
||||||
if origin.is_channel_name() {
|
if origin.is_channel_name() {
|
||||||
if let Some(author) = message.prefix.as_ref().and_then(|p| match p {
|
if let Some(author) = message.prefix.as_ref().and_then(|p| match p {
|
||||||
Prefix::Nickname(name, _, _) => Some(&name[..]),
|
Prefix::Nickname(name, _, _) => Some(&name[..]),
|
||||||
_ => None,
|
Prefix::ServerName(_) => None,
|
||||||
}) {
|
}) {
|
||||||
bot.handle_message(origin, author, &content).await
|
bot.handle_message(origin, author, &content).await;
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("Couldn't get the author for a message");
|
tracing::warn!("Couldn't get the author for a message");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue