rustfmt
This commit is contained in:
parent
e3ac4e7b23
commit
19191bf8f8
12
src/bot.rs
12
src/bot.rs
|
@ -3,7 +3,7 @@ use crate::ExecutorConnection;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use fancy_regex::{Captures, Regex};
|
use fancy_regex::{Captures, Regex};
|
||||||
use std::collections::HashMap;
|
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>)> {
|
fn dissect<'a>(prefixes: &[String], str: &'a str) -> Option<(&'a str, Option<&'a str>)> {
|
||||||
for prefix in prefixes {
|
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..])))
|
Some((&str[..o], Some(&str[o + 1..])))
|
||||||
} else {
|
} else {
|
||||||
Some((str, None))
|
Some((str, None))
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -108,7 +108,13 @@ impl<SF: Fn(String, String) -> anyhow::Result<()>> Bot<SF> {
|
||||||
Ok(())
|
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 {
|
if let Err(e) = self.handle_message_inner(&origin, &author, &content).await {
|
||||||
let _err = (self.sendmsg)(origin.into(), format!("Error: {}", e));
|
let _err = (self.sendmsg)(origin.into(), format!("Error: {}", e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{net::SocketAddr, collections::HashMap};
|
use std::{collections::HashMap, net::SocketAddr};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ pub struct UberConfig {
|
||||||
pub irc: IrcConfig,
|
pub irc: IrcConfig,
|
||||||
pub spotify: Option<SpotifyConfig>,
|
pub spotify: Option<SpotifyConfig>,
|
||||||
pub bot: BotConfig,
|
pub bot: BotConfig,
|
||||||
pub web: Option<HttpConfig>
|
pub web: Option<HttpConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -39,5 +39,5 @@ pub struct BotConfig {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct HttpConfig {
|
pub struct HttpConfig {
|
||||||
pub listen: SocketAddr,
|
pub listen: SocketAddr,
|
||||||
pub webhooks: HashMap<String, String>
|
pub webhooks: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,10 @@ impl DbExecutor {
|
||||||
query: String,
|
query: String,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
) -> rusqlite::Result<Vec<Quote>> {
|
) -> rusqlite::Result<Vec<Quote>> {
|
||||||
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));
|
searches.insert(user, (query, oid));
|
||||||
Ok(quotes)
|
Ok(quotes)
|
||||||
}
|
}
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -3,8 +3,8 @@
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{thread, process};
|
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
use std::{process, thread};
|
||||||
|
|
||||||
use crate::bot::Bot;
|
use crate::bot::Bot;
|
||||||
use crate::commands::eval::Eval;
|
use crate::commands::eval::Eval;
|
||||||
|
@ -22,19 +22,19 @@ use irc::client::{Client, ClientStream};
|
||||||
use irc::proto::{ChannelExt, Command, Prefix};
|
use irc::proto::{ChannelExt, Command, Prefix};
|
||||||
use rspotify::Credentials;
|
use rspotify::Credentials;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::sync::{broadcast, mpsc};
|
|
||||||
use tokio::sync::mpsc::unbounded_channel;
|
use tokio::sync::mpsc::unbounded_channel;
|
||||||
|
use tokio::sync::{broadcast, mpsc};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::config::UberConfig;
|
use crate::config::UberConfig;
|
||||||
use crate::database::{DbExecutor, ExecutorConnection};
|
use crate::database::{DbExecutor, ExecutorConnection};
|
||||||
|
|
||||||
mod web;
|
|
||||||
mod bot;
|
mod bot;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod config;
|
mod config;
|
||||||
mod database;
|
mod database;
|
||||||
mod history;
|
mod history;
|
||||||
|
mod web;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
async fn terminate_signal() {
|
async fn terminate_signal() {
|
||||||
|
@ -112,7 +112,10 @@ async fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let http_task = cfg.web.map(|http| {
|
let http_task = cfg.web.map(|http| {
|
||||||
let http_ctx = ctx.subscribe();
|
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 {
|
tokio::spawn(async move {
|
||||||
if let Err(e) = web::run(context, http_ctx).await {
|
if let Err(e) = web::run(context, http_ctx).await {
|
||||||
tracing::error!("Fatal error in web service: {}", e);
|
tracing::error!("Fatal error in web service: {}", e);
|
||||||
|
@ -185,10 +188,10 @@ async fn main() -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn message_loop<SF>(
|
async fn message_loop<SF>(mut stream: ClientStream, bot: Bot<SF>) -> anyhow::Result<()>
|
||||||
mut stream: ClientStream,
|
where
|
||||||
bot: Bot<SF>,
|
SF: Fn(String, String) -> anyhow::Result<()> + Send + Sync + 'static,
|
||||||
) -> anyhow::Result<()> where SF: Fn(String, String) -> anyhow::Result<()> + Send + Sync + 'static {
|
{
|
||||||
let bot = Arc::new(bot);
|
let bot = Arc::new(bot);
|
||||||
let (cancelled_send, mut cancelled_recv) = mpsc::channel::<()>(1);
|
let (cancelled_send, mut cancelled_recv) = mpsc::channel::<()>(1);
|
||||||
while let Some(message) = stream.next().await.transpose()? {
|
while let Some(message) = stream.next().await.transpose()? {
|
||||||
|
@ -201,7 +204,8 @@ async fn message_loop<SF>(
|
||||||
let bot = bot.clone();
|
let bot = bot.clone();
|
||||||
let cancelled_send = cancelled_send.clone();
|
let cancelled_send = cancelled_send.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
bot.handle_message(origin, author, content, cancelled_send).await;
|
bot.handle_message(origin, author, content, cancelled_send)
|
||||||
|
.await;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("Couldn't get the author for a message");
|
tracing::warn!("Couldn't get the author for a message");
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use std::{convert::Infallible, sync::Arc};
|
use std::{convert::Infallible, sync::Arc};
|
||||||
|
|
||||||
use hyper::{
|
use hyper::{
|
||||||
|
body::to_bytes,
|
||||||
header::HeaderValue,
|
header::HeaderValue,
|
||||||
service::{make_service_fn, service_fn},
|
service::{make_service_fn, service_fn},
|
||||||
Body, Request, Response, Server, StatusCode, body::to_bytes,
|
Body, Request, Response, Server, StatusCode,
|
||||||
};
|
};
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue