Skip to content

Commit

Permalink
Now writes the dist config file on when it can't fine a config. Also …
Browse files Browse the repository at this point in the history
…changed the dist config file to be more intuitive.
  • Loading branch information
sonicrules1234 committed Jan 31, 2022
1 parent a2bab71 commit fe21305
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sonicbot-matrix"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["Westly Ward <[email protected]>"]
description = "Matrix bot that you can write plugins for"
Expand Down
4 changes: 2 additions & 2 deletions config.yaml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
username: "examplebot"
username: "yourbotname"
server_name: "matrix.org"
host: "https://matrix.org"
password: "passwordhere"
password: "yourbotspassword"
initial_rooms:
- "#example:matrix.org"
- "#example2:matrix.org"
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Deserialize;

use std::io::Write;
#[derive(Clone, Debug, Deserialize)]
struct SonicbotConfig {
username: String,
Expand All @@ -12,6 +12,13 @@ struct SonicbotConfig {
}

fn main() {
let dist_config = include_str!("../config.yaml.dist");
if !std::path::Path::new("config.yaml").exists() {
eprintln!("Could not find config file (config.yaml). Creating blank config...\nPlease fill out config.yaml in the current directory.");
let mut f = std::fs::File::create("config.yaml").unwrap();
f.write_all(dist_config.as_bytes()).unwrap();
return;
}
let sonicbot_config: SonicbotConfig = serde_yaml::from_str(&std::fs::read_to_string("config.yaml").unwrap()).unwrap();
//println!("{:#?}", sonicbot_config);
let mut inst = sonicbot_matrix::SonicBot::new(sonicbot_config.host, sonicbot_config.username, sonicbot_config.server_name, true, sonicbot_config.prefix, sonicbot_config.owner);
Expand Down

0 comments on commit fe21305

Please sign in to comment.