From ab6f42d5e6355b63a458d581378b016541020ce8 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Sun, 7 Jan 2024 20:14:27 +0700 Subject: [PATCH] feat(user): add dotenvy .env easier for my life --- Cargo.lock | 1 + swordfish-user/Cargo.toml | 1 + swordfish-user/src/main.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22eb3c5..cb5c700 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2245,6 +2245,7 @@ dependencies = [ name = "swordfish-user" version = "0.1.0" dependencies = [ + "dotenvy", "serenity 0.13.0-alpha2", "swordfish-common", ] diff --git a/swordfish-user/Cargo.toml b/swordfish-user/Cargo.toml index 95253bf..369a0fc 100644 --- a/swordfish-user/Cargo.toml +++ b/swordfish-user/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +dotenvy = "0.15.7" serenity = { git = "https://github.com/nshout/serenity-self", version = "0.13.0-alpha2" } diff --git a/swordfish-user/src/main.rs b/swordfish-user/src/main.rs index 505e3b3..63bee4d 100644 --- a/swordfish-user/src/main.rs +++ b/swordfish-user/src/main.rs @@ -1,9 +1,9 @@ -use std::env; - +use dotenvy::dotenv; use serenity::all::{Embed, MessageUpdateEvent}; use serenity::async_trait; use serenity::model::channel::Message; use serenity::prelude::*; +use std::env; use swordfish_common::setup_logger; use swordfish_common::{constants, database, utils}; use swordfish_common::{debug, tokio}; @@ -181,6 +181,12 @@ impl EventHandler for Handler { #[tokio::main] async fn main() { + match dotenv() { + Ok(_) => {} + Err(why) => { + eprintln!("Failed to load .env: {:?}", why); + } + } // Login with a user token from the environment let log_level = env::var("LOG_LEVEL").unwrap_or("info".to_string()); setup_logger(log_level.as_str()).expect("Failed to setup logger");