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

@@ -2,51 +2,65 @@ job "singh3" {
region = "global"
datacenters = ["nazrin"]
type = "service"
group "svc" {
count = 1
network {
mode = "bridge"
port "db" {
static = 5454
to = 5432
}
}
vault {
policies = ["singh3-policy"]
}
service {
name = "singh3-db"
port = "db"
}
task "db" {
template {
data = <<EOF
{{with secret "kv/data/singh3/db"}}{{.Data.data.pass}}{{end}}
EOF
destination = "${NOMAD_SECRETS_DIR}/db.pass"
}
driver = "docker"
config {
image = "postgres:alpine"
ports = ["db"]
volumes = ["/var/lib/nomad-st/postgres-singh3:/var/lib/postgresql/data"]
}
env {
POSTGRES_USER = "singh3"
POSTGRES_PASSWORD_FILE = "${NOMAD_SECRETS_DIR}/db.pass"
POSTGRES_DB = "singh3"
}
resources {
cpu = 256
memory = 128
}
}
task "bot" {
driver = "docker"
config {
image = "natto17/singh3:latest"
force_pull = true
}
template {
data = <<EOF
{{with secret "kv/data/singh3/db"}}
@@ -57,6 +71,7 @@ DISCORD_TOKEN="{{.Data.data.token}}"
{{end}}
RUST_BACKTRACE=1
EOF
destination = "${NOMAD_SECRETS_DIR}/data.env"
env = true
}

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]