Skip to content

Commit

Permalink
Introduce a separate data type for autocomplete interactions (serenit…
Browse files Browse the repository at this point in the history
…y-rs#1941)

The interaction payload for autocompletes is slightly different. It's
missing the `resolved` data map and reports only for the current
autocompleted option value the `focused` field and its value as a string.

The focused option value is modeled as an enum variant of `CommandDataOptionValue`.

```
enum CommandDataOptionValue {
    Autocomplete { name: String, kind: CommandOptionType, value: String },
}
```

The focused option value can be retrieved via `AutocompleteData::focused_option()`
from the `AutocompleteData::options` vector.
  • Loading branch information
nickelc authored and arqunis committed Sep 2, 2022
1 parent 5da380f commit c0ceb62
Show file tree
Hide file tree
Showing 2 changed files with 428 additions and 16 deletions.
10 changes: 0 additions & 10 deletions src/model/application/interaction/application_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,6 @@ pub struct CommandDataOption {
/// The resolved object of the given `value`, if there is one.
#[serde(default)]
pub resolved: Option<CommandDataOptionValue>,
/// For `Autocomplete` Interactions this will be `true` if
/// this option is currently focused by the user.
#[serde(default)]
pub focused: bool,
}

impl<'de> Deserialize<'de> for CommandDataOption {
Expand Down Expand Up @@ -641,18 +637,12 @@ impl<'de> Deserialize<'de> for CommandDataOption {
.map_err(DeError::custom)?
.unwrap_or_default();

let focused = match map.get("focused") {
Some(value) => value.as_bool().ok_or_else(|| DeError::custom("expected bool"))?,
None => false,
};

Ok(Self {
name,
value,
kind,
options,
resolved: None,
focused,
})
}
}
Expand Down
Loading

0 comments on commit c0ceb62

Please sign in to comment.