Improvements and add bash script

This commit is contained in:
toast 2023-12-31 16:03:49 +11:00
parent 940d553c16
commit 045679df80
2 changed files with 9 additions and 9 deletions

3
run.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
export $(cat .env | xargs) && cargo run

View File

@ -1,6 +1,7 @@
mod commands; mod commands;
use poise::serenity_prelude::{self as serenity}; use poise::serenity_prelude::{self as serenity};
use std::env::var;
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
@ -16,12 +17,10 @@ async fn on_ready(
serenity::ChannelId(865673694184996888).send_message(&ctx.http, |m| m.embed(|e| serenity::ChannelId(865673694184996888).send_message(&ctx.http, |m| m.embed(|e|
e.color(COLOR) e.color(COLOR)
.thumbnail(ready.user.avatar_url().unwrap_or_default()) .thumbnail(ready.user.avatar_url().unwrap_or_default())
.author(|a| .author(|a| a.name(format!("{} is ready!", ready.user.name)))
a.name(format!("{} is ready!", ready.user.name))
)
)).await?; )).await?;
let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true); let register_commands = var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
if register_commands { if register_commands {
let builder = poise::builtins::create_application_commands(&framework.options().commands); let builder = poise::builtins::create_application_commands(&framework.options().commands);
@ -31,10 +30,8 @@ async fn on_ready(
}).await; }).await;
match commands { match commands {
Ok(cmdmap) => { Ok(cmdmap) => for command in cmdmap.iter() {
for command in cmdmap.iter() {
println!("Registered command globally: {}", command.name); println!("Registered command globally: {}", command.name);
}
}, },
Err(why) => println!("Error registering commands: {:?}", why) Err(why) => println!("Error registering commands: {:?}", why)
} }
@ -45,7 +42,7 @@ async fn on_ready(
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("Expected a \"DISCORD_TOKEN\" in the envvar but none was found"); let token = var("DISCORD_TOKEN").expect("Expected a \"DISCORD_TOKEN\" in the envvar but none was found");
let client = poise::Framework::builder().token(token) let client = poise::Framework::builder().token(token)
.intents(serenity::GatewayIntents::MESSAGE_CONTENT | serenity::GatewayIntents::GUILDS) .intents(serenity::GatewayIntents::MESSAGE_CONTENT | serenity::GatewayIntents::GUILDS)