Add initial toml support

This commit is contained in:
Yash Karandikar 2021-12-27 13:49:54 -06:00
parent b74e46ec97
commit f2f3d2aae5
Signed by: karx
GPG Key ID: A794DA2529474BA5
4 changed files with 13 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target
config.toml

1
Cargo.lock generated
View File

@ -175,6 +175,7 @@ dependencies = [
"irc",
"serenity",
"tokio",
"toml",
]
[[package]]

View File

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.52"
irc = "0.15"
toml = "0.5"
[dependencies.tokio]
version = "1.15.0"

View File

@ -1,4 +1,4 @@
use std::{env, sync::Arc};
use std::{env, sync::Arc, fs::File, io::Read};
use serenity::{
async_trait,
@ -18,6 +18,8 @@ use irc::{
proto::Command,
};
use toml::Value;
struct Handler;
#[async_trait]
@ -81,7 +83,13 @@ impl TypeMapKey for SenderKey {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let token = env::var("DISCORD_TOKEN").expect("DISCORD_TOKEN not set");
let filename = env::args().nth(1).expect("No filename was provided!");
let mut data = String::new();
File::open(filename)?.read_to_string(&mut data)?;
let value = data.parse::<Value>()?;
let token = value["token"].as_str().expect("No token provided!").to_string();
let mut discord_client = DiscordClient::builder(&token)
.event_handler(Handler)