added tcopy
also renamed some commands + hclfmt the nomad file
This commit is contained in:
39
singh3.nomad
39
singh3.nomad
@@ -1,52 +1,66 @@
|
|||||||
job "singh3" {
|
job "singh3" {
|
||||||
region = "global"
|
region = "global"
|
||||||
datacenters = [ "nazrin" ]
|
datacenters = ["nazrin"]
|
||||||
type = "service"
|
type = "service"
|
||||||
|
|
||||||
group "svc" {
|
group "svc" {
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
network {
|
network {
|
||||||
mode = "bridge"
|
mode = "bridge"
|
||||||
|
|
||||||
port "db" {
|
port "db" {
|
||||||
static = 5454
|
static = 5454
|
||||||
to = 5432
|
to = 5432
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vault {
|
vault {
|
||||||
policies = [ "singh3-policy" ]
|
policies = ["singh3-policy"]
|
||||||
}
|
}
|
||||||
|
|
||||||
service {
|
service {
|
||||||
name = "singh3-db"
|
name = "singh3-db"
|
||||||
port = "db"
|
port = "db"
|
||||||
}
|
}
|
||||||
|
|
||||||
task "db" {
|
task "db" {
|
||||||
template {
|
template {
|
||||||
data = <<EOF
|
data = <<EOF
|
||||||
{{with secret "kv/data/singh3/db"}}{{.Data.data.pass}}{{end}}
|
{{with secret "kv/data/singh3/db"}}{{.Data.data.pass}}{{end}}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
destination = "${NOMAD_SECRETS_DIR}/db.pass"
|
destination = "${NOMAD_SECRETS_DIR}/db.pass"
|
||||||
}
|
}
|
||||||
|
|
||||||
driver = "docker"
|
driver = "docker"
|
||||||
|
|
||||||
config {
|
config {
|
||||||
image = "postgres:alpine"
|
image = "postgres:alpine"
|
||||||
ports = ["db"]
|
ports = ["db"]
|
||||||
volumes = [ "/var/lib/nomad-st/postgres-singh3:/var/lib/postgresql/data" ]
|
volumes = ["/var/lib/nomad-st/postgres-singh3:/var/lib/postgresql/data"]
|
||||||
}
|
}
|
||||||
|
|
||||||
env {
|
env {
|
||||||
POSTGRES_USER = "singh3"
|
POSTGRES_USER = "singh3"
|
||||||
POSTGRES_PASSWORD_FILE = "${NOMAD_SECRETS_DIR}/db.pass"
|
POSTGRES_PASSWORD_FILE = "${NOMAD_SECRETS_DIR}/db.pass"
|
||||||
POSTGRES_DB = "singh3"
|
POSTGRES_DB = "singh3"
|
||||||
}
|
}
|
||||||
|
|
||||||
resources {
|
resources {
|
||||||
cpu = 256
|
cpu = 256
|
||||||
memory = 128
|
memory = 128
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task "bot" {
|
task "bot" {
|
||||||
driver = "docker"
|
driver = "docker"
|
||||||
|
|
||||||
config {
|
config {
|
||||||
image = "natto17/singh3:latest"
|
image = "natto17/singh3:latest"
|
||||||
force_pull = true
|
force_pull = true
|
||||||
}
|
}
|
||||||
|
|
||||||
template {
|
template {
|
||||||
data = <<EOF
|
data = <<EOF
|
||||||
{{with secret "kv/data/singh3/db"}}
|
{{with secret "kv/data/singh3/db"}}
|
||||||
@@ -57,8 +71,9 @@ DISCORD_TOKEN="{{.Data.data.token}}"
|
|||||||
{{end}}
|
{{end}}
|
||||||
RUST_BACKTRACE=1
|
RUST_BACKTRACE=1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
destination = "${NOMAD_SECRETS_DIR}/data.env"
|
destination = "${NOMAD_SECRETS_DIR}/data.env"
|
||||||
env = true
|
env = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ use serenity::{
|
|||||||
use tokio_postgres::Row;
|
use tokio_postgres::Row;
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[aliases("kitna")]
|
#[aliases("kitna", "c")]
|
||||||
pub async fn count(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
pub async fn count(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||||
let query: String = args.raw().collect::<Vec<&str>>().join(" ");
|
let query: String = args.raw().collect::<Vec<&str>>().join(" ");
|
||||||
if query == "" {
|
if query == "" {
|
||||||
@@ -122,7 +122,8 @@ pub async fn cadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[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(" ");
|
let query: String = args.raw().collect::<Vec<&str>>().join(" ");
|
||||||
if query == "" {
|
if query == "" {
|
||||||
msg.reply(ctx, "remove what?").await?;
|
msg.reply(ctx, "remove what?").await?;
|
||||||
@@ -246,7 +247,8 @@ macro_rules! make_terminal_components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[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 data_read = ctx.data.read().await;
|
||||||
let db = data_read
|
let db = data_read
|
||||||
.get::<crate::Database>()
|
.get::<crate::Database>()
|
||||||
|
@@ -121,7 +121,50 @@ pub async fn tadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[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(" ");
|
let query: String = args.raw().collect::<Vec<&str>>().join(" ");
|
||||||
if query == "" {
|
if query == "" {
|
||||||
msg.reply(ctx, "remove what?").await?;
|
msg.reply(ctx, "remove what?").await?;
|
||||||
@@ -257,7 +300,8 @@ macro_rules! make_terminal_components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[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 data_read = ctx.data.read().await;
|
||||||
let db = data_read
|
let db = data_read
|
||||||
.get::<crate::Database>()
|
.get::<crate::Database>()
|
||||||
|
@@ -37,11 +37,11 @@ impl TypeMapKey for Database {
|
|||||||
struct General;
|
struct General;
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(count, cadd, crm, cedit, cls)]
|
#[commands(count, cadd, cremove, cedit, clist)]
|
||||||
struct Count;
|
struct Count;
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(tag, tadd, trm, tedit, tls)]
|
#[commands(tag, tadd, tcopy, tremove, tedit, tlist)]
|
||||||
pub struct Tags;
|
pub struct Tags;
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
|
Reference in New Issue
Block a user