add user fake id regeneration
This commit is contained in:
parent
5b029f3f67
commit
0f25a2dfea
@ -1,5 +1,5 @@
|
|||||||
use diesel::{prelude::*, insert_into};
|
use diesel::{prelude::*, insert_into, update};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::{NaiveDateTime, Local};
|
||||||
use crate::{logging::{LogLevel, log}, db::{connect, get_hashed_uid}};
|
use crate::{logging::{LogLevel, log}, db::{connect, get_hashed_uid}};
|
||||||
|
|
||||||
#[derive(Insertable, Selectable, Queryable, Debug, Clone, Default)]
|
#[derive(Insertable, Selectable, Queryable, Debug, Clone, Default)]
|
||||||
@ -93,4 +93,32 @@ pub fn get_user_by_id(user_id: &u64) -> Option<User> {
|
|||||||
Ok(u) => return u,
|
Ok(u) => return u,
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn regen_fake_id(user_id: &u64, new_fake_id: i64) {
|
||||||
|
use crate::db::schema::user::dsl::*;
|
||||||
|
let conn = connect();
|
||||||
|
if conn.is_none() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let mut conn = conn.unwrap();
|
||||||
|
let uid: String = get_hashed_uid(user_id);
|
||||||
|
let now: NaiveDateTime = Local::now().naive_local();
|
||||||
|
|
||||||
|
let _ = conn.transaction(|c| {
|
||||||
|
let sql = update(user)
|
||||||
|
.filter(discord_id.eq(uid))
|
||||||
|
.set((fake_id.eq(new_fake_id), when_generated.eq(now)))
|
||||||
|
.execute(c);
|
||||||
|
|
||||||
|
match sql {
|
||||||
|
Err(e) => {
|
||||||
|
log(LogLevel::Error, "db", "regen_fake_id", format!("SQL Error: {:?}", e).as_str());
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
Ok(_) => {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ use serde::ser::StdError;
|
|||||||
use poise::serenity_prelude::ChannelId;
|
use poise::serenity_prelude::ChannelId;
|
||||||
use poise::serenity_prelude::{self as serenity};
|
use poise::serenity_prelude::{self as serenity};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
|
use chrono::{NaiveDateTime, Local};
|
||||||
|
|
||||||
use crate::{logging::{LogLevel, log}, config::CORE_CFG, db::user::*};
|
use crate::{logging::{LogLevel, log}, config::CORE_CFG, db::user::*};
|
||||||
|
|
||||||
@ -28,7 +29,20 @@ pub async fn handle_msg(ctx: &serenity::Context, msg: &serenity::Message) -> Res
|
|||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let usr = uusr.unwrap();
|
let mut usr = uusr.unwrap();
|
||||||
|
|
||||||
|
if usr.is_banned {
|
||||||
|
let _ = msg.reply(&ctx.http, "You have been banned from using this bot.");
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
let now: NaiveDateTime = Local::now().naive_local();
|
||||||
|
if usr.when_generated.timestamp() + 86400 < now.timestamp() {
|
||||||
|
let fid: i64 = rand::thread_rng().gen_range(10000000..=99999999);
|
||||||
|
log(LogLevel::Info, "event_handlers", "handle_msg", format!("Regenerate fake ID {}", fid).as_str());
|
||||||
|
regen_fake_id(&msg.author.id.0, fid);
|
||||||
|
usr.fake_id = fid;
|
||||||
|
}
|
||||||
|
|
||||||
let new_channel = ChannelId::from(cfg.channel);
|
let new_channel = ChannelId::from(cfg.channel);
|
||||||
let mut picture = cfg.pictures.choose(&mut rand::thread_rng()).unwrap();
|
let mut picture = cfg.pictures.choose(&mut rand::thread_rng()).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user