Skip to content

Commit

Permalink
add default config
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelDarley authored Jul 9, 2024
1 parent 1c93ef7 commit 2ba4f74
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "surreal_bot"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
authors = [
"Raphael Darley <[email protected]>",
Expand Down
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ impl Config {
json: builder.json?,
})
}

pub fn surrealdb_default() -> Config {
Config {
guild_id: GuildId(902568124350599239),
active_channel: ChannelId(1134233558785990706),
archive_channel: ChannelId(1175018599887421460),
ttl: Duration::from_secs(60 * 60 * 6),
timeout: Duration::from_secs(8),
pretty: true,
json: false,
}
}
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand Down
21 changes: 17 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serenity::prelude::*;
use dotenv::dotenv;
use std::env;
use std::path::Path;
use surreal_bot::config::Config;
use tracing::{error, info};

use surrealdb::engine::local::{Mem, RocksDb};
Expand All @@ -23,10 +24,22 @@ async fn main() -> Result<(), anyhow::Error> {
.init();

match env::var("CONFIG_DB_PATH") {
Ok(path) => {
let path = Path::new(&path);
DB.connect::<RocksDb>(path).await?;
}
Ok(path) => match path.to_lowercase().as_str() {
"default" => {
DB.connect::<Mem>(()).await?;
let config = Config::surrealdb_default();
let _: Option<Config> = DB
.create(("guild_config", config.guild_id.to_string()))
.content(config)
.await
.ok()
.flatten();
}
_ => {
let path = Path::new(&path);
DB.connect::<RocksDb>(path).await?;
}
},
Err(_) => {
DB.connect::<Mem>(()).await?;
}
Expand Down

0 comments on commit 2ba4f74

Please sign in to comment.