From 8e732b34cae370705a46f7216cf21cd0fc837c5e Mon Sep 17 00:00:00 2001 From: natto1784 Date: Mon, 14 Feb 2022 09:18:55 +0530 Subject: [PATCH] added tcopy also renamed some commands + hclfmt the nomad file --- singh3.nomad | 39 ++++++++++++++++++++++++----------- src/commands/count.rs | 8 +++++--- src/commands/tags.rs | 48 +++++++++++++++++++++++++++++++++++++++++-- src/main.rs | 4 ++-- 4 files changed, 80 insertions(+), 19 deletions(-) diff --git a/singh3.nomad b/singh3.nomad index 4cd5da7..1d0bf6d 100644 --- a/singh3.nomad +++ b/singh3.nomad @@ -1,52 +1,66 @@ job "singh3" { - region = "global" - datacenters = [ "nazrin" ] - type = "service" + region = "global" + datacenters = ["nazrin"] + type = "service" + group "svc" { count = 1 + network { mode = "bridge" + port "db" { static = 5454 - to = 5432 + to = 5432 } } + vault { - policies = [ "singh3-policy" ] + policies = ["singh3-policy"] } + service { name = "singh3-db" port = "db" } + task "db" { template { data = < CommandResult { let query: String = args.raw().collect::>().join(" "); if query == "" { @@ -122,7 +122,8 @@ pub async fn cadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult { } #[command] -pub async fn crm(ctx: &Context, msg: &Message, args: Args) -> CommandResult { +#[aliases("crm")] +pub async fn cremove(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let query: String = args.raw().collect::>().join(" "); if query == "" { msg.reply(ctx, "remove what?").await?; @@ -246,7 +247,8 @@ macro_rules! make_terminal_components { } #[command] -pub async fn cls(ctx: &Context, msg: &Message, _: Args) -> CommandResult { +#[aliases("clist")] +pub async fn clist(ctx: &Context, msg: &Message, _: Args) -> CommandResult { let data_read = ctx.data.read().await; let db = data_read .get::() diff --git a/src/commands/tags.rs b/src/commands/tags.rs index 7193745..9481a18 100644 --- a/src/commands/tags.rs +++ b/src/commands/tags.rs @@ -121,7 +121,50 @@ pub async fn tadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult { } #[command] -pub async fn trm(ctx: &Context, msg: &Message, args: Args) -> CommandResult { +#[aliases("tcp")] +pub async fn tcopy(ctx: &Context, msg: &Message, args: Args) -> CommandResult { + let queries: Vec<&str> = args.raw().collect::>(); + if queries.len() != 2 { + msg.reply( + ctx, + "Please use the proper syntax: `,tcopy `", + ) + .await?; + return Ok(()); + } + let data_read = ctx.data.read().await; + let db = data_read + .get::() + .expect("Expected Database in TypeMap.") + .clone(); + let check_existense = db + .query( + format!("SELECT name FROM tags WHERE name='{}'", queries[0]).as_str(), + &[], + ) + .await?; + if check_existense.len() == 0 { + msg.reply(ctx, format!("This tag does not exist")).await?; + return Ok(()); + } + db.execute( + format!( + "INSERT INTO tags(name, value, owner) SELECT '{}', value, '{}' FROM tags WHERE name = '{}'", + queries[1], + msg.author.id.to_string(), + queries[0] + ) + .as_str(), + &[], + ) + .await?; + msg.reply(ctx, "Copied").await?; + Ok(()) +} + +#[command] +#[aliases("trm")] +pub async fn tremove(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let query: String = args.raw().collect::>().join(" "); if query == "" { msg.reply(ctx, "remove what?").await?; @@ -257,7 +300,8 @@ macro_rules! make_terminal_components { } #[command] -pub async fn tls(ctx: &Context, msg: &Message, _: Args) -> CommandResult { +#[aliases("tls")] +pub async fn tlist(ctx: &Context, msg: &Message, _: Args) -> CommandResult { let data_read = ctx.data.read().await; let db = data_read .get::() diff --git a/src/main.rs b/src/main.rs index 07cd4d4..410e722 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,11 +37,11 @@ impl TypeMapKey for Database { struct General; #[group] -#[commands(count, cadd, crm, cedit, cls)] +#[commands(count, cadd, cremove, cedit, clist)] struct Count; #[group] -#[commands(tag, tadd, trm, tedit, tls)] +#[commands(tag, tadd, tcopy, tremove, tedit, tlist)] pub struct Tags; #[group]