added tcopy

also renamed some commands + hclfmt the nomad file
This commit is contained in:
2022-02-14 09:18:55 +05:30
parent 5c911042be
commit 8e732b34ca
4 changed files with 80 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ use serenity::{
use tokio_postgres::Row;
#[command]
#[aliases("kitna")]
#[aliases("kitna", "c")]
pub async fn count(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let query: String = args.raw().collect::<Vec<&str>>().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::<Vec<&str>>().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::<crate::Database>()

View File

@@ -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::<Vec<&str>>();
if queries.len() != 2 {
msg.reply(
ctx,
"Please use the proper syntax: `,tcopy <original> <new>`",
)
.await?;
return Ok(());
}
let data_read = ctx.data.read().await;
let db = data_read
.get::<crate::Database>()
.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::<Vec<&str>>().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::<crate::Database>()

View File

@@ -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]