-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix deserialization of burst_colours on MessageReaction #2893
Fix deserialization of burst_colours on MessageReaction #2893
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not merging this as-is, we cannot duplicate logic like this. There must be a better way to do this.
I couldn't think of a nicer way at the time, It would probably involve the creation of another module (so that it doesn't reexport the function in serenity::all, or changing it carefully so it reexports everything but this function) alongside somehow handling the difference between the optional and non optional version. Do you have any suggestions in mind? |
Can this not go in |
I didn't think about moving it there to be fair, I don't think much, that only leaves one issue with one being an option and the other not. |
Would this pass? fn discord_colours_opt<'de, D>(deserializer: D) -> Result<Option<Vec<Colour>>, D::Error>
where
D: Deserializer<'de>,
{
let vec_str: Option<Vec<CowStr<'_>>> = Deserialize::deserialize(deserializer)?;
let Some(vec_str) = vec_str else { return Ok(None) };
if vec_str.is_empty() {
return Ok(None);
}
deserialize_colours::<D>(vec_str).map(Some)
}
fn discord_colours<'de, D>(deserializer: D) -> Result<Vec<Colour>, D::Error>
where
D: Deserializer<'de>,
{
let vec_str: Vec<CowStr<'_>> = Deserialize::deserialize(deserializer)?;
deserialize_colours::<D>(vec_str)
}
fn deserialize_colours<'de, D>(vec_str: Vec<CowStr<'_>>) -> Result<Vec<Colour>, D::Error>
where
D: Deserializer<'de>,
{
vec_str
.into_iter()
.map(|s| {
let s = s.0.strip_prefix('#').ok_or_else(|| DeError::custom("Invalid colour data"))?;
if s.len() != 6 {
return Err(DeError::custom("Invalid colour data length"));
}
u32::from_str_radix(s, 16)
.map(Colour::new)
.map_err(|_| DeError::custom("Invalid colour data"))
})
.collect()
} |
Sure |
Do I understand correctly, that 0.12.* won't work with reactions until this is merged?
at ctx.http
.get_message(reaction.channel_id.into(), message_id.into())
.await |
This is a 2 part fix, the 1st part was #2887. |
Can't wait :) I tried applying it myself and specifying git dependency, but some magic happens, and my shuttle app refuses to recognize |
573b50e
to
5457d3a
Compare
Hi, I'd just like to mention that a release with this fix would be much appreciated, also considering the number of duplicate issues of #2892 since people keep running into it. For now, I'm staying on 0.10 which still works but there have been some breaking API changes since then, so I presume not everyone would be happy to revert to that. |
@FichteFoll you can use a newer version, this issue was introduced in 0.12.2. |
Fixes #2892.