From d27797bc2a162f4e946ac9615986a9b8673781f6 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sun, 3 Mar 2024 01:35:20 -0300 Subject: [PATCH] NO OPTOUTS! --- .gitmodules | 2 +- src/app/mod.rs | 22 +++++++++++----------- src/bot.rs | 42 +++++++++++++++++++++--------------------- src/db/mod.rs | 16 ++++++++-------- src/main.rs | 2 +- src/web/handlers.rs | 32 ++++++++++++++++---------------- src/web/mod.rs | 2 +- 7 files changed, 59 insertions(+), 59 deletions(-) diff --git a/.gitmodules b/.gitmodules index e191ba6..b034f26 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "web"] path = web - url = https://github.com/boring-nick/justlog + url = https://git.nadeko.net/Fijxu/rustlog-web branch = frontend-only-new diff --git a/src/app/mod.rs b/src/app/mod.rs index ce3c370..8deb59e 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,7 +1,7 @@ pub mod cache; use self::cache::UsersCache; -use crate::{config::Config, db::delete_user_logs, error::Error, Result}; +use crate::{config::Config, error::Error, Result}; use anyhow::Context; use dashmap::DashSet; use std::{collections::HashMap, sync::Arc}; @@ -13,7 +13,7 @@ pub struct App { pub helix_client: HelixClient<'static, reqwest::Client>, pub token: Arc, pub users: UsersCache, - pub optout_codes: Arc>, + // pub optout_codes: Arc>, pub db: Arc, pub config: Arc, } @@ -113,17 +113,17 @@ impl App { } } - pub async fn optout_user(&self, user_id: &str) -> anyhow::Result<()> { - delete_user_logs(&self.db, user_id) - .await - .context("Could not delete logs")?; + // pub async fn optout_user(&self, user_id: &str) -> anyhow::Result<()> { + // delete_user_logs(&self.db, user_id) + // .await + // .context("Could not delete logs")?; - self.config.opt_out.insert(user_id.to_owned(), true); - self.config.save()?; - info!("User {user_id} opted out"); + // self.config.opt_out.insert(user_id.to_owned(), true); + // self.config.save()?; + // info!("User {user_id} opted out"); - Ok(()) - } + // Ok(()) + // } pub fn check_opted_out(&self, channel_id: &str, user_id: Option<&str>) -> Result<()> { if self.config.opt_out.contains_key(channel_id) { diff --git a/src/bot.rs b/src/bot.rs index 0db1a7e..9af3cc9 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -241,9 +241,9 @@ impl Bot { self.update_channels(client, &args, ChannelAction::Part) .await? } - "optout" => { - self.optout_user(&args, sender_login, sender_id).await?; - } + // "optout" => { + // self.optout_user(&args, sender_login, sender_id).await?; + // } _ => (), } } @@ -251,27 +251,27 @@ impl Bot { Ok(()) } - async fn optout_user( - &self, - args: &[&str], - sender_login: &str, - sender_id: &str, - ) -> anyhow::Result<()> { - let arg = args.first().context("No optout code provided")?; - if self.app.optout_codes.remove(*arg).is_some() { - self.app.optout_user(sender_id).await?; + // async fn optout_user( + // &self, + // args: &[&str], + // sender_login: &str, + // sender_id: &str, + // ) -> anyhow::Result<()> { + // let arg = args.first().context("No optout code provided")?; + // if self.app.optout_codes.remove(*arg).is_some() { + // self.app.optout_user(sender_id).await?; - Ok(()) - } else if self.check_admin(sender_login).is_ok() { - let user_id = self.app.get_user_id_by_name(arg).await?; + // Ok(()) + // } else if self.check_admin(sender_login).is_ok() { + // let user_id = self.app.get_user_id_by_name(arg).await?; - self.app.optout_user(&user_id).await?; + // self.app.optout_user(&user_id).await?; - Ok(()) - } else { - Err(anyhow!("Invalid optout code")) - } - } + // Ok(()) + // } else { + // Err(anyhow!("Invalid optout code")) + // } + // } async fn update_channels( &self, diff --git a/src/db/mod.rs b/src/db/mod.rs index 3cd94f1..132420f 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -254,14 +254,14 @@ pub async fn read_random_channel_line(db: &Client, channel_id: &str) -> Result Result<()> { - // info!("Deleting all logs for user {user_id}"); - // db.query("ALTER TABLE message DELETE WHERE user_id = ?") - // .bind(user_id) - // .execute() - // .await?; - Ok(()) -} +// pub async fn delete_user_logs(_db: &Client, _user_id: &str) -> Result<()> { +// // info!("Deleting all logs for user {user_id}"); +// // db.query("ALTER TABLE message DELETE WHERE user_id = ?") +// // .bind(user_id) +// // .execute() +// // .await?; +// Ok(()) +// } fn apply_limit_offset(query: &mut String, limit: Option, offset: Option) { if let Some(limit) = limit { diff --git a/src/main.rs b/src/main.rs index 8682a75..c3a13c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,7 +104,7 @@ async fn run(config: Config, db: clickhouse::Client) -> anyhow::Result<()> { users: UsersCache::default(), config: Arc::new(config), db: Arc::new(db), - optout_codes: Arc::default(), + // optout_codes: Arc::default(), }; let (bot_tx, bot_rx) = mpsc::channel(1); diff --git a/src/web/handlers.rs b/src/web/handlers.rs index 266aa38..44c894b 100644 --- a/src/web/handlers.rs +++ b/src/web/handlers.rs @@ -369,25 +369,25 @@ async fn random_user_line( Ok((no_cache_header(), logs)) } -pub async fn optout(app: State) -> Json { - let mut rng = thread_rng(); - let optout_code: String = (0..5).map(|_| rng.sample(Alphanumeric) as char).collect(); +// pub async fn optout(app: State) -> Json { +// let mut rng = thread_rng(); +// let optout_code: String = (0..5).map(|_| rng.sample(Alphanumeric) as char).collect(); - app.optout_codes.insert(optout_code.clone()); +// app.optout_codes.insert(optout_code.clone()); - { - let codes = app.optout_codes.clone(); - let optout_code = optout_code.clone(); - tokio::spawn(async move { - tokio::time::sleep(Duration::from_secs(60)).await; - if codes.remove(&optout_code).is_some() { - debug!("Dropping optout code {optout_code}"); - } - }); - } +// { +// let codes = app.optout_codes.clone(); +// let optout_code = optout_code.clone(); +// tokio::spawn(async move { +// tokio::time::sleep(Duration::from_secs(60)).await; +// if codes.remove(&optout_code).is_some() { +// debug!("Dropping optout code {optout_code}"); +// } +// }); +// } - Json(optout_code) -} +// Json(optout_code) +// } fn cache_header(secs: u64) -> TypedHeader { TypedHeader( diff --git a/src/web/mod.rs b/src/web/mod.rs index 852a1ff..167e57a 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -137,7 +137,7 @@ pub async fn run(app: App, mut shutdown_rx: ShutdownRx, bot_tx: Sender