changed permission chekc to be more manual since built in one isnt working

This commit is contained in:
2020-10-11 18:56:27 +01:00
parent 7cfe62d18f
commit 09a7608429
5 changed files with 75 additions and 52 deletions

View File

@ -199,14 +199,14 @@ async fn restrict(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let role_opt = role_id.to_role_cached(&ctx).await;
if let Some(role) = role_opt {
if commands.is_empty() {
let _ = sqlx::query!(
"
let _ = sqlx::query!(
"
DELETE FROM command_restrictions WHERE role_id = (SELECT id FROM roles WHERE role = ?)
", role.id.as_u64())
.execute(&pool)
.await;
", role.id.as_u64())
.execute(&pool)
.await;
if commands.is_empty() {
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "restrict/disabled").await).await;
}
else {
@ -226,7 +226,12 @@ INSERT INTO command_restrictions (role_id, command) VALUES ((SELECT id FROM role
.await;
if res.is_err() {
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "restrict/failure").await).await;
println!("{:?}", res);
let content = user_data.response(&pool, "restrict/failure").await
.replacen("{command}", &command, 1);
let _ = msg.channel_id.say(&ctx, content).await;
}
}

View File

@ -30,6 +30,9 @@ use crate::{
MAX_TIME,
LOCAL_TIMEZONE,
CHARACTERS,
DAY,
HOUR,
MINUTE,
},
models::{
ChannelData,
@ -41,7 +44,6 @@ use crate::{
time_parser::TimeParser,
framework::SendIterator,
check_subscription_on_message,
shorthand_displacement, longhand_displacement
};
use chrono::{NaiveDateTime, offset::TimeZone};
@ -79,6 +81,29 @@ use regex::Regex;
use serde_json::json;
fn shorthand_displacement(seconds: u64) -> String {
let (hours, seconds) = seconds.div_rem(&HOUR);
let (minutes, seconds) = seconds.div_rem(&MINUTE);
format!("{:02}:{:02}:{:02}", hours, minutes, seconds)
}
fn longhand_displacement(seconds: u64) -> String {
let (days, seconds) = seconds.div_rem(&DAY);
let (hours, seconds) = seconds.div_rem(&HOUR);
let (minutes, seconds) = seconds.div_rem(&MINUTE);
let mut sections = vec![];
for (var, name) in [days, hours, minutes, seconds].iter().zip(["days", "hours", "minutes", "seconds"].iter()) {
if *var > 0 {
sections.push(format!("{} {}", var, name));
}
}
sections.join(", ")
}
#[command]
#[supports_dm(false)]
#[permission_level(Restricted)]
@ -357,7 +382,11 @@ LIMIT
user_data.timezone().timestamp(reminder.time as i64, 0).format("%Y-%m-%D %H:%M:%S").to_string()
},
TimeDisplayType::Relative => {
longhand_displacement(reminder.time as u64)
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap().as_secs();
longhand_displacement(reminder.time as u64 - now)
},
};
@ -793,6 +822,7 @@ async fn remind_command(ctx: &Context, msg: &Message, args: String, command: Rem
}
#[command]
#[permission_level(Managed)]
async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");