improving the todo interface. switched up some of the dp.py include_strs to use cargo_manifest_dir

This commit is contained in:
jude 2020-10-17 02:10:36 +01:00
parent d10bf7ede6
commit 87a7c69b76
3 changed files with 53 additions and 14 deletions

View File

@ -2,6 +2,7 @@
<dictionary name="jude"> <dictionary name="jude">
<words> <words>
<w>reqwest</w> <w>reqwest</w>
<w>subcommand</w>
<w>todos</w> <w>todos</w>
<w>webhook</w> <w>webhook</w>
<w>webhooks</w> <w>webhooks</w>

View File

@ -1034,7 +1034,7 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
if let (Some(time_crop), Some(msg_crop)) = (time_crop_opt, msg_crop_opt) { if let (Some(time_crop), Some(msg_crop)) = (time_crop_opt, msg_crop_opt) {
let python_call = Command::new(&*PYTHON_LOCATION) let python_call = Command::new(&*PYTHON_LOCATION)
.arg("-c") .arg("-c")
.arg(include_str!("../../dp.py")) .arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py")))
.arg(time_crop) .arg(time_crop)
.arg(&user_data.timezone) .arg(&user_data.timezone)
.arg(&*LOCAL_TIMEZONE) .arg(&*LOCAL_TIMEZONE)
@ -1094,7 +1094,7 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let python_call = Command::new(&*PYTHON_LOCATION) let python_call = Command::new(&*PYTHON_LOCATION)
.arg("-c") .arg("-c")
.arg(include_str!("../../dp.py")) .arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py")))
.arg(&format!("1 {}", interval_str)) .arg(&format!("1 {}", interval_str))
.arg(&*LOCAL_TIMEZONE) .arg(&*LOCAL_TIMEZONE)
.arg(&*LOCAL_TIMEZONE) .arg(&*LOCAL_TIMEZONE)

View File

@ -17,6 +17,7 @@ use crate::{
SQLPool, SQLPool,
}; };
use sqlx::MySqlPool; use sqlx::MySqlPool;
use std::convert::TryFrom;
#[derive(Debug)] #[derive(Debug)]
struct TodoNotFound; struct TodoNotFound;
@ -240,6 +241,24 @@ enum SubCommand {
Clear, Clear,
} }
impl TryFrom<Option<&str>> for SubCommand {
type Error = ();
fn try_from(value: Option<&str>) -> Result<Self, Self::Error> {
match value {
Some("add") => Ok(SubCommand::Add),
Some("remove") => Ok(SubCommand::Remove),
Some("clear") => Ok(SubCommand::Clear),
None => Ok(SubCommand::View),
Some(_unrecognised) => Err(()),
}
}
}
impl ToString for SubCommand { impl ToString for SubCommand {
fn to_string(&self) -> String { fn to_string(&self) -> String {
match self { match self {
@ -252,6 +271,35 @@ impl ToString for SubCommand {
} }
} }
#[command]
#[permission_level(Managed)]
async fn todo_user(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let mut split = args.split(' ');
let target = TodoTarget {
user: msg.author.id,
guild: None,
channel: None,
};
let subcommand_opt = SubCommand::try_from(split.next());
if let Ok(subcommand) = subcommand_opt {
todo(
ctx,
msg,
target,
subcommand,
split.collect::<Vec<&str>>().join(" "),
)
.await;
} else {
show_help(&ctx, msg, Some(target)).await;
}
Ok(())
}
#[command] #[command]
#[permission_level(Managed)] #[permission_level(Managed)]
async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult { async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult {
@ -293,19 +341,9 @@ async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult
}; };
if let Some(target) = target_opt { if let Some(target) = target_opt {
let subcommand_opt = match split.next() { let subcommand_opt = SubCommand::try_from(split.next());
Some("add") => Some(SubCommand::Add),
Some("remove") => Some(SubCommand::Remove), if let Ok(subcommand) = subcommand_opt {
Some("clear") => Some(SubCommand::Clear),
None => Some(SubCommand::View),
Some(_unrecognised) => None,
};
if let Some(subcommand) = subcommand_opt {
todo( todo(
ctx, ctx,
msg, msg,