Skip to content

Commit 763185e

Browse files
committed
fix(config): validate Discord webhook URL and update README instructions
1 parent d9ae1fc commit 763185e

2 files changed

Lines changed: 50 additions & 19 deletions

File tree

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,37 @@ rust-commit-tracker
5454

5555
## Configuration
5656

57-
On first run, the application creates `config.toml`. **Only the Discord webhook URL is required** - all other settings have sensible defaults.
57+
On first run, the application creates `config.toml` with sensible defaults. **Only the Discord webhook URL needs to be set** - everything else works out of the box.
5858

59-
### Required Configuration
59+
### Required: Discord Webhook
6060

6161
Edit `config.toml` and set your Discord webhook URL:
6262

6363
```toml
6464
[discord]
65-
webhook_url = "YOUR_DISCORD_WEBHOOK_URL" #Only required field
65+
webhook_url = "YOUR_DISCORD_WEBHOOK_URL" #Required: Replace with actual webhook
6666
```
6767

68-
### Full Configuration Reference
68+
### Optional: Customize Defaults
69+
70+
All other settings have working defaults but can be customized:
6971

7072
```toml
7173
[discord]
72-
webhook_url = "YOUR_DISCORD_WEBHOOK_URL" # Required: Your Discord webhook
73-
bot_name = "Rust Commit Tracker" # Optional: Bot display name
74-
bot_avatar_url = "https://i.imgur.com/on47Qk9.png" # Optional: Bot avatar
74+
bot_name = "Rust Commit Tracker" # Bot display name
75+
bot_avatar_url = "https://i.imgur.com/on47Qk9.png" # Bot avatar
7576

7677
[monitoring]
7778
commits_url = "https://commits.facepunch.com/?format=json" # API endpoint
78-
check_interval_secs = 50 # How often to check for new commits
79+
check_interval_secs = 50 # Check interval in seconds
7980

8081
[appearance]
81-
embed_color = "#CD412B" # Rust orange color for Discord embeds
82-
footer_icon_url = "https://i.imgur.com/on47Qk9.png"
82+
embed_color = "#CD412B" # Discord embed color (Rust orange)
83+
footer_icon_url = "https://i.imgur.com/on47Qk9.png" # Footer icon
8384

8485
[database]
85-
url = "sqlite:commits.db" # SQLite database location
86-
cleanup_keep_last = 1000 # Number of commits to retain in database
86+
url = "sqlite:commits.db" # Database file location
87+
cleanup_keep_last = 1000 # Number of commits to retain
8788
```
8889

8990
## Getting a Discord Webhook URL

src/core/config.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ pub struct DatabaseConfig {
4242
impl Config {
4343
pub fn load_or_create() -> Result<Self, Box<dyn Error>> {
4444
if Path::new(CONFIG_FILE).exists() {
45-
Self::load_from_file()
45+
let config = Self::load_from_file()?;
46+
config.validate()?;
47+
Ok(config)
4648
} else {
4749
Self::create_default_and_prompt()
4850
}
@@ -100,19 +102,47 @@ impl Config {
100102
println!("✅ Created '{}'", CONFIG_FILE);
101103
println!();
102104
println!("📝 Please edit the configuration file with your settings:");
103-
println!(" - Discord webhook URL");
104-
println!(" - Bot name and avatar");
105-
println!(" - Monitoring settings");
106-
println!(" - Database path (SQLite file url)");
105+
println!(" - Discord webhook URL (REQUIRED)");
106+
println!(" - Bot name and avatar (optional)");
107+
println!(" - Monitoring settings (optional)");
108+
println!(" - Database path (optional)");
107109
println!();
108110
print!("Press Enter when you've finished editing the config file...");
109111
io::stdout().flush()?;
110112

111113
let mut input = String::new();
112114
io::stdin().read_line(&mut input)?;
113115

114-
// Reload the config after user edits
115-
Self::load_from_file()
116+
// Reload and validate the config after user edits
117+
let config = Self::load_from_file()?;
118+
config.validate()?;
119+
Ok(config)
120+
}
121+
122+
pub fn validate(&self) -> Result<(), Box<dyn Error>> {
123+
// Check if webhook URL is still the placeholder
124+
if self.discord.webhook_url == "REPLACE_WITH_YOUR_DISCORD_WEBHOOK_URL"
125+
|| self.discord.webhook_url.trim().is_empty() {
126+
return Err(format!(
127+
"❌ Discord webhook URL not configured!\n\
128+
Please edit '{}' and set a valid Discord webhook URL.\n\
129+
You can get one from your Discord server settings → Integrations → Webhooks",
130+
CONFIG_FILE
131+
).into());
132+
}
133+
134+
// Basic webhook URL validation
135+
if !self.discord.webhook_url.starts_with("https://discord.com/api/webhooks/")
136+
&& !self.discord.webhook_url.starts_with("https://discordapp.com/api/webhooks/") {
137+
return Err(format!(
138+
"❌ Invalid Discord webhook URL format!\n\
139+
Expected: https://discord.com/api/webhooks/...\n\
140+
Got: {}",
141+
self.discord.webhook_url
142+
).into());
143+
}
144+
145+
Ok(())
116146
}
117147

118148
pub fn rust_color(&self) -> u32 {

0 commit comments

Comments
 (0)