forked from natto1784/singh3
add help messages and turn rust backtrace on
This commit is contained in:
@@ -50,11 +50,12 @@ EOF
|
||||
template {
|
||||
data = <<EOF
|
||||
{{with secret "kv/data/singh3/db"}}
|
||||
DB_URL="postgresql://singh3:{{.Data.data.pass}}@{{env "NOMAD_ADDR_db"}}/singh3"
|
||||
DB_URL="postgresql://singh3:{{.Data.data.pass}}@localhost:5432/singh3"
|
||||
{{end}}
|
||||
{{with secret "kv/data/singh3/discord"}}
|
||||
DISCORD_TOKEN="{{.Data.data.token}}"
|
||||
{{end}}
|
||||
RUST_BACKTRACE=1
|
||||
EOF
|
||||
destination = "${NOMAD_SECRETS_DIR}/data.env"
|
||||
env = true
|
||||
|
@@ -118,6 +118,10 @@ pub async fn add(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
#[command]
|
||||
pub async fn rm(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let query: String = args.raw().collect::<Vec<&str>>().join(" ");
|
||||
if query == "" {
|
||||
msg.reply(ctx, "remove what?").await?;
|
||||
return Ok(());
|
||||
}
|
||||
let data_read = ctx.data.read().await;
|
||||
let db = data_read
|
||||
.get::<crate::Database>()
|
||||
@@ -200,6 +204,10 @@ pub async fn ls(ctx: &Context, msg: &Message, _: Args) -> CommandResult {
|
||||
.expect("Expected Database in TypeMap.")
|
||||
.clone();
|
||||
let rows = db.query("select * from words", &[]).await?;
|
||||
if rows.is_empty() {
|
||||
msg.reply(ctx, "No words stored").await?;
|
||||
return Ok(());
|
||||
}
|
||||
msg.channel_id
|
||||
.send_message(ctx, |mut m| {
|
||||
let mut a: u32 = 1;
|
||||
|
34
src/main.rs
34
src/main.rs
@@ -6,8 +6,16 @@ use commands::minigames::*;
|
||||
use handler::Handler;
|
||||
use serenity::{
|
||||
client::bridge::gateway::ShardManager,
|
||||
framework::{standard::macros::group, StandardFramework},
|
||||
framework::{
|
||||
standard::{
|
||||
help_commands,
|
||||
macros::{group, help},
|
||||
Args, CommandGroup, CommandResult, HelpOptions,
|
||||
},
|
||||
StandardFramework,
|
||||
},
|
||||
http::Http,
|
||||
model::{channel::Message, id::UserId},
|
||||
prelude::*,
|
||||
};
|
||||
use std::{collections::HashSet, env, sync::Arc};
|
||||
@@ -35,6 +43,23 @@ struct Count;
|
||||
#[commands(challenge)]
|
||||
struct Minigames;
|
||||
|
||||
#[help]
|
||||
#[max_levenshtein_distance(2)]
|
||||
#[indention_prefix = "+"]
|
||||
#[lacking_role = "Nothing"]
|
||||
#[wrong_channel = "Strike"]
|
||||
async fn my_help(
|
||||
context: &Context,
|
||||
msg: &Message,
|
||||
args: Args,
|
||||
help_options: &'static HelpOptions,
|
||||
groups: &[&'static CommandGroup],
|
||||
owners: HashSet<UserId>,
|
||||
) -> CommandResult {
|
||||
let _ = help_commands::with_embeds(context, msg, args, help_options, groups, owners).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let token = env::var("DISCORD_TOKEN").expect("Token daal madarchod");
|
||||
@@ -53,6 +78,7 @@ async fn main() {
|
||||
|
||||
let framework = StandardFramework::new()
|
||||
.configure(|c| c.owners(owners).prefix(","))
|
||||
.help(&MY_HELP)
|
||||
.group(&GENERAL_GROUP)
|
||||
.group(&COUNT_GROUP)
|
||||
.group(&MINIGAMES_GROUP);
|
||||
@@ -66,6 +92,7 @@ async fn main() {
|
||||
|
||||
{
|
||||
let db_url: String = env::var("DB_URL").expect("DB_URL not found");
|
||||
println!("{}", db_url);
|
||||
let (db_client, conn) = tokio_postgres::connect(&db_url, tokio_postgres::NoTls)
|
||||
.await
|
||||
.expect("cant connect bha");
|
||||
@@ -75,7 +102,10 @@ async fn main() {
|
||||
}
|
||||
});
|
||||
let init_script = std::include_str!("../init.sql");
|
||||
db_client.batch_execute(init_script).await.expect("Couldn't run the init script");
|
||||
db_client
|
||||
.batch_execute(init_script)
|
||||
.await
|
||||
.expect("Couldn't run the init script");
|
||||
let mut data = client.data.write().await;
|
||||
data.insert::<Database>(Arc::new(db_client));
|
||||
data.insert::<ShardManagerContainer>(client.shard_manager.clone());
|
||||
|
Reference in New Issue
Block a user