From 11d12469fc1f01d81e72e61d4e4be56622f8d7e2 Mon Sep 17 00:00:00 2001 From: jude Date: Wed, 14 Oct 2020 11:52:09 +0100 Subject: [PATCH] warn when avatar path not real --- src/consts.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index b732961..81ef18d 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -6,10 +6,12 @@ pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX const THEME_COLOR_FALLBACK: u32 = 0x8fb677; -use std::{collections::HashSet, env, iter::FromIterator}; +use std::{collections::HashSet, env, iter::FromIterator, path::Path}; use regex::Regex; +use log::warn; + lazy_static! { pub static ref SUBSCRIPTION_ROLES: HashSet = HashSet::from_iter( env::var("SUBSCRIPTION_ROLES") @@ -53,5 +55,18 @@ lazy_static! { THEME_COLOR_FALLBACK, |inner| u32::from_str_radix(&inner, 16).unwrap_or(THEME_COLOR_FALLBACK) ); - pub static ref WEBHOOK_AVATAR: Option = env::var("WEBHOOK_AVATAR").ok(); + pub static ref WEBHOOK_AVATAR: Option = env::var("WEBHOOK_AVATAR") + .ok() + .map(|s| { + let p = Path::new(&s); + + if !p.exists() { + warn!("WEBHOOK_AVATAR path doesn't exist. Falling back"); + + None + } else { + Some(s) + } + }) + .flatten(); }