diff --git a/src/commands/tags.rs b/src/commands/tags.rs index 677a0bb..861c455 100644 --- a/src/commands/tags.rs +++ b/src/commands/tags.rs @@ -70,8 +70,8 @@ pub async fn tag(ctx: &Context, msg: &Message, args: Args) -> CommandResult { pub async fn tadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let query: String = args.raw().collect::>().join(" "); let queries = query.splitn(2, " ").collect::>(); - if queries.len() != 2 { - msg.reply(ctx, "Please use the proper syntax: `,tadd `") + if queries.len() != 2 && msg.attachments.len() == 0 { + msg.reply(ctx, "Please use the proper syntax: `,tadd ` or attach something") .await?; return Ok(()); } @@ -95,8 +95,12 @@ pub async fn tadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult { "INSERT INTO tags(name, value, owner) VALUES('{}','{}', '{}')", queries[0], format!( - "{}\n{}", - queries[1], + "{}{}", + if queries.len() == 2 { + format!("{}{}", queries[1], '\n') + } else { + "".to_string() + }, msg.attachments .iter() .map(|x| x.url.clone()) @@ -151,8 +155,8 @@ pub async fn trm(ctx: &Context, msg: &Message, args: Args) -> CommandResult { pub async fn tedit(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let query: String = args.raw().collect::>().join(" "); let queries = query.splitn(2, " ").collect::>(); - if queries.len() != 2 { - msg.reply(ctx, "Please use the proper syntax\n`,tedit `") + if queries.len() != 2 && msg.attachments.len() == 0 { + msg.reply(ctx, "Please use the proper syntax or attach something\n`,tedit `") .await?; return Ok(()); } @@ -178,8 +182,12 @@ pub async fn tedit(ctx: &Context, msg: &Message, args: Args) -> CommandResult { format!( "UPDATE tags SET value='{}' WHERE name='{}'", format!( - "{}\n{}", - queries[1], + "{}{}", + if queries.len() == 2 { + format!("{}{}", queries[1], '\n') + } else { + "".to_string() + }, msg.attachments .iter() .map(|x| x.url.clone()) @@ -190,7 +198,8 @@ pub async fn tedit(ctx: &Context, msg: &Message, args: Args) -> CommandResult { ) .as_str(), &[], - ).await?; + ) + .await?; msg.reply(ctx, "Changed the value if it existed").await?; Ok(()) }