allow notification toggle, notifications still don't work
This commit is contained in:
parent
30d2deb2c7
commit
d55e9cb850
|
@ -1,11 +1,19 @@
|
|||
use super::{Error, Context};
|
||||
use crate::{config::CORE_CFG, db::user::set_notify};
|
||||
|
||||
#[poise::command(slash_command, prefix_command, dm_only)]
|
||||
pub async fn notify(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Turn notifications on or off"] toggle: bool,
|
||||
) -> Result<(), Error> {
|
||||
let response = format!("Notifications are now {}", toggle);
|
||||
let mut response = format!("Notifications are now {}", toggle);
|
||||
|
||||
if CORE_CFG.get().unwrap().hash_ids {
|
||||
response = "Notifications are disabled on this guild.".to_string();
|
||||
} else {
|
||||
set_notify(&ctx.author().id.as_u64(), toggle);
|
||||
}
|
||||
|
||||
ctx.say(response).await?;
|
||||
Ok(())
|
||||
}
|
|
@ -95,7 +95,7 @@ pub fn get_user_by_id(user_id: &u64) -> Option<User> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn regen_fake_id(user_id: &u64, new_fake_id: i64, new_pic_idx: i32) {
|
||||
pub fn set_fake_id(user_id: &u64, new_fake_id: i64, new_pic_idx: i32) {
|
||||
use crate::db::schema::user::dsl::*;
|
||||
let conn = connect();
|
||||
if conn.is_none() {
|
||||
|
@ -113,7 +113,67 @@ pub fn regen_fake_id(user_id: &u64, new_fake_id: i64, new_pic_idx: i32) {
|
|||
|
||||
match sql {
|
||||
Err(e) => {
|
||||
log(LogLevel::Error, "db", "regen_fake_id", format!("SQL Error: {:?}", e).as_str());
|
||||
log(LogLevel::Error, "db", "set_fake_id", format!("SQL Error: {:?}", e).as_str());
|
||||
return Err(e);
|
||||
}
|
||||
Ok(_) => {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_user_by_fake_id(user_id: &u64) -> Option<User> {
|
||||
use crate::db::schema::user::dsl::*;
|
||||
let conn = connect();
|
||||
if conn.is_none() {
|
||||
return None
|
||||
}
|
||||
let mut conn = conn.unwrap();
|
||||
|
||||
let res = conn.transaction(|c| {
|
||||
let sql = user.filter(fake_id.eq(*user_id as i64))
|
||||
.select(User::as_select())
|
||||
.load::<User>(c);
|
||||
|
||||
match sql {
|
||||
Err(e) => {
|
||||
log(LogLevel::Error, "db", "get_user_by_id", format!("SQL Error: {:?}", e).as_str());
|
||||
return Err(e);
|
||||
}
|
||||
Ok(usr) => {
|
||||
if usr.len() > 0 {
|
||||
return Ok(Some(usr[0].clone()))
|
||||
}
|
||||
return Ok(None)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
match res {
|
||||
Ok(u) => return u,
|
||||
Err(_) => return None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_notify(user_id: &u64, is_notify: bool) {
|
||||
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 _ = conn.transaction(|c| {
|
||||
let sql = update(user)
|
||||
.filter(discord_id.eq(uid))
|
||||
.set(should_notify.eq(is_notify))
|
||||
.execute(c);
|
||||
|
||||
match sql {
|
||||
Err(e) => {
|
||||
log(LogLevel::Error, "db", "set_notify", format!("SQL Error: {:?}", e).as_str());
|
||||
return Err(e);
|
||||
}
|
||||
Ok(_) => {
|
||||
|
|
|
@ -41,7 +41,7 @@ pub async fn handle_msg(ctx: &serenity::Context, msg: &serenity::Message) -> Res
|
|||
let fid: i64 = rand::thread_rng().gen_range(10000000..=99999999);
|
||||
let idx = rand::thread_rng().gen_range(0..cfg.pictures.len());
|
||||
log(LogLevel::Info, "event_handlers", "handle_msg", format!("Regenerate fake ID {}", fid).as_str());
|
||||
regen_fake_id(&msg.author.id.0, fid, idx as i32);
|
||||
set_fake_id(&msg.author.id.0, fid, idx as i32);
|
||||
usr.fake_id = fid;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue