Skip to content

Commit

Permalink
Support config for Discord API version
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Nelson committed Dec 9, 2020
1 parent 3f9f594 commit 53ccd34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/bin/proxy/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct Config {
pub redis: RedisConfig,
#[serde(default)]
pub amqp: AmqpConfig,
#[serde(default)]
pub discord: DiscordConfig,
#[serde(default, deserialize_with = "deserialize_duration")]
pub timeout: Option<Duration>,
}
Expand Down Expand Up @@ -56,6 +58,7 @@ impl Config {
"AMQP_EVENT" => self.amqp.event = v,
"AMQP_CANCELLATION_EVENT" => self.amqp.cancellation_event = v,
"TIMEOUT" => self.timeout = v.parse().ok(),
"DISCORD_API_VERSION" => self.discord.api_version = v.parse().expect("valid DISCORD_API_VERSION (u8)"),
_ => {}
}
}
Expand Down Expand Up @@ -127,3 +130,23 @@ impl Default for AmqpConfig {
}
}
}

#[derive(Debug, Deserialize)]
pub struct DiscordConfig {
#[serde(default = "DiscordConfig::default_api_version")]
pub api_version: u8,
}

impl DiscordConfig {
fn default_api_version() -> u8 {
return 6;
}
}

impl Default for DiscordConfig {
fn default() -> Self {
Self {
api_version: Self::default_api_version(),
}
}
}
2 changes: 1 addition & 1 deletion src/bin/proxy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn main() {
ratelimiter: Arc::new(ratelimiter),
api_base: "discord.com",
api_scheme: Scheme::HTTPS,
api_version: 6,
api_version: config.discord.api_version,
timeout: config.timeout.map(|d| d.into()),
});

Expand Down

0 comments on commit 53ccd34

Please sign in to comment.