slopfixing config file snowflake issues

This commit is contained in:
legop3 2026-06-13 22:31:06 -04:00
parent 2301acccf9
commit 364870e041
3 changed files with 25 additions and 8 deletions

View file

@ -5,8 +5,8 @@ This is a slice of the code that powers [SIPcord](https://sipcord.net/) that you
This means you have to build the call routing backend yourself. I am including a `static-router` backend which you can use to map extensions in a TOML file like this This means you have to build the call routing backend yourself. I am including a `static-router` backend which you can use to map extensions in a TOML file like this
```toml ```toml
[extensions] [extensions]
1000 = { guild = 123456789012345620, channel = 987654321012345620 } 1000 = { guild = "123456789012345620", channel = "987654321012345620" }
2000 = { guild = 123456789012345620, channel = 111222333444555620 } 2000 = { guild = "123456789012345620", channel = "111222333444555620" }
``` ```
but if you want more fancy routing you have to build it. You can easily use sipcord-bridge as a library and provide your own routers by implementing the `Backend` trait. but if you want more fancy routing you have to build it. You can easily use sipcord-bridge as a library and provide your own routers by implementing the `Backend` trait.
@ -48,8 +48,8 @@ Create a `dialplan.toml` mapping extensions to Discord channels:
```toml ```toml
[extensions] [extensions]
1000 = { guild = 123456789012345678, channel = 987654321012345678 } 1000 = { guild = "123456789012345678", channel = "987654321012345678" }
2000 = { guild = 123456789012345678, channel = 111222333444555666 } 2000 = { guild = "123456789012345678", channel = "111222333444555666" }
``` ```
Each extension is what you'll dial from your SIP phone. Pick any numbers you like. Each extension is what you'll dial from your SIP phone. Pick any numbers you like.

View file

@ -8,8 +8,8 @@
//! Example `dialplan.toml`: //! Example `dialplan.toml`:
//! ```toml //! ```toml
//! [extensions] //! [extensions]
//! 1000 = { guild = 123456789012345678, channel = 987654321012345678 } //! 1000 = { guild = "123456789012345678", channel = "987654321012345678" }
//! 2000 = { guild = 123456789012345678, channel = 111222333444555666 } //! 2000 = { guild = "123456789012345678", channel = "111222333444555666" }
//! ``` //! ```
use std::collections::HashMap; use std::collections::HashMap;
@ -128,8 +128,8 @@ mod tests {
fn test_load_valid_dialplan() { fn test_load_valid_dialplan() {
let toml_content = r#" let toml_content = r#"
[extensions] [extensions]
1000 = { guild = 123456789012345678, channel = 987654321012345678 } 1000 = { guild = "123456789012345678", channel = "987654321012345678" }
2000 = { guild = 123456789012345678, channel = 111222333444555666 } 2000 = { guild = "123456789012345678", channel = "111222333444555666" }
"#; "#;
let dir = std::env::temp_dir().join("sipcord_test_dialplan"); let dir = std::env::temp_dir().join("sipcord_test_dialplan");
std::fs::create_dir_all(&dir).ok(); std::fs::create_dir_all(&dir).ok();

View file

@ -114,6 +114,12 @@ impl<'de> serde::Deserialize<'de> for Snowflake {
Ok(Snowflake(v)) Ok(Snowflake(v))
} }
fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Snowflake, E> {
u64::try_from(v)
.map(Snowflake)
.map_err(|_| E::custom("snowflake cannot be negative"))
}
fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Snowflake, E> { fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Snowflake, E> {
v.parse::<u64>().map(Snowflake).map_err(E::custom) v.parse::<u64>().map(Snowflake).map_err(E::custom)
} }
@ -178,4 +184,15 @@ mod tests {
let back: Snowflake = serde_json::from_str("\"80351110224678912\"").unwrap(); let back: Snowflake = serde_json::from_str("\"80351110224678912\"").unwrap();
assert_eq!(back.get(), 80_351_110_224_678_912); assert_eq!(back.get(), 80_351_110_224_678_912);
} }
#[test]
fn serde_from_toml_integer() {
#[derive(serde::Deserialize)]
struct Wrapper {
id: Snowflake,
}
let back: Wrapper = toml::from_str("id = 80351110224678912").unwrap();
assert_eq!(back.id.get(), 80_351_110_224_678_912);
}
} }