-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from GiganticMinecraft/feat/load-config
feat: コンフィグの読み込みロジックを追加
- Loading branch information
Showing
6 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
reactions: ["👍", "👎"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use anyhow::Context; | ||
use once_cell::sync::OnceCell; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fs::File; | ||
use std::io::BufReader; | ||
use tracing::log::info; | ||
|
||
#[derive(Default, Deserialize, Debug)] | ||
pub struct IdeaReactionConfig { | ||
pub reactions: Vec<String>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct IdeaReactionEnv { | ||
pub discord_api_token: String, | ||
pub target_channel_id: u64, | ||
pub target_guild_id: u64, | ||
pub target_webhook_id: u64, | ||
} | ||
|
||
pub fn load_config() -> anyhow::Result<IdeaReactionConfig> { | ||
let config: IdeaReactionConfig = serde_yaml::from_reader(BufReader::new( | ||
File::open("./assets/config.yaml").context("Failed to open config file")?, | ||
)) | ||
.context("Failed to parse config file")?; | ||
|
||
// TODO: このチェックを厳格化する | ||
if config.reactions.is_empty() { | ||
panic!("No reactions found in config file"); | ||
} | ||
|
||
info!("Loaded config: {:?}", config.reactions); | ||
Ok(config) | ||
} | ||
|
||
pub static ENV_CONFIG: OnceCell<IdeaReactionEnv> = OnceCell::new(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters