diff --git a/src/bot.rs b/src/bot.rs index 3db22c6..1a4010a 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -3,7 +3,7 @@ use crate::ExecutorConnection; use async_trait::async_trait; use fancy_regex::{Captures, Regex}; use std::collections::HashMap; -use tokio::sync::{Mutex, mpsc}; +use tokio::sync::{mpsc, Mutex}; fn dissect<'a>(prefixes: &[String], str: &'a str) -> Option<(&'a str, Option<&'a str>)> { for prefix in prefixes { @@ -12,7 +12,7 @@ fn dissect<'a>(prefixes: &[String], str: &'a str) -> Option<(&'a str, Option<&'a Some((&str[..o], Some(&str[o + 1..]))) } else { Some((str, None)) - } + }; } } None @@ -108,7 +108,13 @@ impl anyhow::Result<()>> Bot { Ok(()) } - pub async fn handle_message(&self, origin: String, author: String, content: String, _cancel_handle: mpsc::Sender<()>) { + pub async fn handle_message( + &self, + origin: String, + author: String, + content: String, + _cancel_handle: mpsc::Sender<()>, + ) { if let Err(e) = self.handle_message_inner(&origin, &author, &content).await { let _err = (self.sendmsg)(origin.into(), format!("Error: {}", e)); } diff --git a/src/config.rs b/src/config.rs index f452637..24fcdda 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,4 @@ -use std::{net::SocketAddr, collections::HashMap}; +use std::{collections::HashMap, net::SocketAddr}; use serde::Deserialize; @@ -8,7 +8,7 @@ pub struct UberConfig { pub irc: IrcConfig, pub spotify: Option, pub bot: BotConfig, - pub web: Option + pub web: Option, } #[derive(Deserialize)] @@ -39,5 +39,5 @@ pub struct BotConfig { #[derive(Deserialize)] pub struct HttpConfig { pub listen: SocketAddr, - pub webhooks: HashMap + pub webhooks: HashMap, } diff --git a/src/database.rs b/src/database.rs index 2c9a481..baf3524 100644 --- a/src/database.rs +++ b/src/database.rs @@ -99,7 +99,10 @@ impl DbExecutor { query: String, limit: usize, ) -> rusqlite::Result> { - let (quotes, oid) = self.yield_quotes_oid("select oid,quote,username from quotes where quote match ? order by oid asc limit ?", params![query, limit])?; + let (quotes, oid) = self.yield_quotes_oid( + "select oid,quote,username from quotes where quote match ? order by oid asc limit ?", + params![query, limit], + )?; searches.insert(user, (query, oid)); Ok(quotes) } diff --git a/src/main.rs b/src/main.rs index 81818d8..20ab02a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use fancy_regex::Regex; use std::str::FromStr; use std::sync::Arc; -use std::{thread, process}; use std::{env, fs}; +use std::{process, thread}; use crate::bot::Bot; use crate::commands::eval::Eval; @@ -22,19 +22,19 @@ use irc::client::{Client, ClientStream}; use irc::proto::{ChannelExt, Command, Prefix}; use rspotify::Credentials; use tokio::select; -use tokio::sync::{broadcast, mpsc}; use tokio::sync::mpsc::unbounded_channel; +use tokio::sync::{broadcast, mpsc}; use tracing::Level; use crate::config::UberConfig; use crate::database::{DbExecutor, ExecutorConnection}; -mod web; mod bot; mod commands; mod config; mod database; mod history; +mod web; #[cfg(unix)] async fn terminate_signal() { @@ -112,7 +112,10 @@ async fn main() -> anyhow::Result<()> { let http_task = cfg.web.map(|http| { let http_ctx = ctx.subscribe(); - let context = HttpContext { cfg: http, sendmsg: sf.clone() }; + let context = HttpContext { + cfg: http, + sendmsg: sf.clone(), + }; tokio::spawn(async move { if let Err(e) = web::run(context, http_ctx).await { tracing::error!("Fatal error in web service: {}", e); @@ -185,10 +188,10 @@ async fn main() -> anyhow::Result<()> { Ok(()) } -async fn message_loop( - mut stream: ClientStream, - bot: Bot, -) -> anyhow::Result<()> where SF: Fn(String, String) -> anyhow::Result<()> + Send + Sync + 'static { +async fn message_loop(mut stream: ClientStream, bot: Bot) -> anyhow::Result<()> +where + SF: Fn(String, String) -> anyhow::Result<()> + Send + Sync + 'static, +{ let bot = Arc::new(bot); let (cancelled_send, mut cancelled_recv) = mpsc::channel::<()>(1); while let Some(message) = stream.next().await.transpose()? { @@ -201,7 +204,8 @@ async fn message_loop( let bot = bot.clone(); let cancelled_send = cancelled_send.clone(); tokio::spawn(async move { - bot.handle_message(origin, author, content, cancelled_send).await; + bot.handle_message(origin, author, content, cancelled_send) + .await; }); } else { tracing::warn!("Couldn't get the author for a message"); diff --git a/src/web/mod.rs b/src/web/mod.rs index a68e8b8..2faf867 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -1,9 +1,10 @@ use std::{convert::Infallible, sync::Arc}; use hyper::{ + body::to_bytes, header::HeaderValue, service::{make_service_fn, service_fn}, - Body, Request, Response, Server, StatusCode, body::to_bytes, + Body, Request, Response, Server, StatusCode, }; use tokio::sync::broadcast;