Skip to content

Commit 2eda2f5

Browse files
committed
Actually generate .env and save config from v1
1 parent 0029648 commit 2eda2f5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/config.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,24 @@ impl ConfigLogic for File {
175175

176176
if let Ok(o) = old {
177177
info!("Converting old NOALBS config into v2");
178-
Config::from(o)
178+
179+
if std::fs::File::open(".env").is_err() {
180+
info!("Creating .env file");
181+
182+
let bot = o.twitch_chat.bot_username.to_lowercase();
183+
let oauth = o.twitch_chat.oauth.to_string();
184+
let env =
185+
format!("TWITCH_BOT_USERNAME={}\nTWITCH_BOT_OAUTH={}", bot, oauth);
186+
std::fs::write(".env", env.as_bytes())?;
187+
188+
std::env::set_var("TWITCH_BOT_USERNAME", bot);
189+
std::env::set_var("TWITCH_BOT_OAUTH", oauth);
190+
}
191+
192+
let c = Config::from(o);
193+
self.save(&c)?;
194+
195+
c
179196
} else {
180197
return Err(error::Error::Json(e));
181198
}
@@ -268,6 +285,8 @@ struct RtmpOld {
268285
#[serde(rename_all = "camelCase", default)]
269286
struct TwitchChat {
270287
channel: String,
288+
bot_username: String,
289+
oauth: String,
271290
enable: bool,
272291
prefix: String,
273292
enable_public_commands: bool,
@@ -440,6 +459,8 @@ impl Default for TwitchChat {
440459
fn default() -> Self {
441460
Self {
442461
channel: "715209".to_string(),
462+
bot_username: "715209".to_string(),
463+
oauth: "oauth:YOUR_OAUTH_HERE".to_string(),
443464
enable: true,
444465
prefix: "!".to_string(),
445466
enable_public_commands: true,

0 commit comments

Comments
 (0)