Skip to content

Commit

Permalink
feat: update to twilight 0.15 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomairborne authored Feb 7, 2023
1 parent 53861c9 commit 6791b46
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To install `twilight-interactions`, add the following to your `Cargo.toml`:

```toml
[dependencies]
twilight-interactions = "0.14"
twilight-interactions = "0.15"
```

The crate's major version follows the version of the official twilight crates.
Expand Down
2 changes: 1 addition & 1 deletion twilight-interactions-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "twilight-interactions-derive"
version = "0.14.4"
version = "0.15.0"
description = "Macros and utilities to make Discord Interactions easy to use with Twilight."
categories = ["parsing", "config", "asynchronous"]
keywords = ["twilight", "discord", "slash-command"]
Expand Down
2 changes: 1 addition & 1 deletion twilight-interactions-derive/src/command/model/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl ChannelType {
"guild_forum" => Ok(Self::GuildForum),
invalid => Err(Error::new(
span,
format!("`{}` is not a valid channel type", invalid),
format!("`{invalid}` is not a valid channel type"),
)),
}
}
Expand Down
9 changes: 4 additions & 5 deletions twilight-interactions-derive/src/option/create_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ fn choice_variant(variant: &ParsedVariant) -> TokenStream {
};

quote! {
choices.push(::twilight_model::application::command::CommandOptionChoice::#type_path(
::twilight_model::application::command::CommandOptionChoiceData {
choices.push(
::twilight_model::application::command::CommandOptionChoice {
name: ::std::convert::From::from(#name),
name_localizations: #name_localizations,
value: #value,
}
));
value: ::twilight_model::application::command::CommandOptionChoiceValue::#type_path(#value),
});
}
}

Expand Down
14 changes: 4 additions & 10 deletions twilight-interactions-derive/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl NamedAttrs {
None => {
return Err(Error::new(
inner.path.span(),
format!("Invalid parameter name (expected {})", expected),
format!("Invalid parameter name (expected {expected})"),
))
}
};
Expand All @@ -132,7 +132,7 @@ impl NamedAttrs {
if !expected.contains(&*key) {
return Err(Error::new(
inner.path.span(),
format!("Invalid parameter name (expected {})", expected),
format!("Invalid parameter name (expected {expected})"),
));
}

Expand Down Expand Up @@ -228,20 +228,14 @@ pub fn parse_name(val: &AttrValue) -> Result<String> {
if !char.is_alphanumeric() && char != '-' && char != '_' {
return Err(Error::new(
span,
format!(
"Name must only contain word characters, found invalid character `{}`",
char
),
format!("Name must only contain word characters, found invalid character `{char}`"),
));
}

if char.to_lowercase().to_string() != char.to_string() {
return Err(Error::new(
span,
format!(
"Name must be in lowercase, found invalid character `{}`",
char
),
format!("Name must be in lowercase, found invalid character `{char}`"),
));
}
}
Expand Down
6 changes: 3 additions & 3 deletions twilight-interactions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "twilight-interactions"
version = "0.14.4"
version = "0.15.0"
description = "Macros and utilities to make Discord Interactions easy to use with Twilight."
categories = ["parsing", "config", "asynchronous"]
keywords = ["twilight", "discord", "slash-command"]
Expand All @@ -19,8 +19,8 @@ default = ["derive"]
derive = ["twilight-interactions-derive"]

[dependencies]
twilight-model = "0.14.1"
twilight-interactions-derive = { version = "=0.14.4", path = "../twilight-interactions-derive", optional = true }
twilight-model = "0.15.0"
twilight-interactions-derive = { version = "=0.15.0", path = "../twilight-interactions-derive", optional = true }

[package.metadata.docs.rs]
all-features = true
Expand Down
10 changes: 5 additions & 5 deletions twilight-interactions/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ impl Display for ParseOptionError {
match &self.kind {
ParseOptionErrorType::InvalidType(ty) => write!(f, "invalid type, found {}", ty.kind()),
ParseOptionErrorType::InvalidChoice(choice) => {
write!(f, "invalid choice value, found `{}`", choice)
write!(f, "invalid choice value, found `{choice}`")
}
ParseOptionErrorType::IntegerOutOfRange(val) => {
write!(f, "out of range integer, received `{}`", val)
write!(f, "out of range integer, received `{val}`")
}
ParseOptionErrorType::NumberOutOfRange(val) => {
write!(f, "out of range number, received `{}`", val)
write!(f, "out of range number, received `{val}`")
}
ParseOptionErrorType::StringLengthOutOfRange(val) => {
write!(f, "out of range string length, received `{}`", val)
write!(f, "out of range string length, received `{val}`")
}
ParseOptionErrorType::InvalidChannelType(kind) => {
write!(f, "invalid channel type, received `{}`", kind.name())
}
ParseOptionErrorType::LookupFailed(id) => write!(f, "failed to resolve `{}`", id),
ParseOptionErrorType::LookupFailed(id) => write!(f, "failed to resolve `{id}`"),
ParseOptionErrorType::UnknownField => write!(f, "unknown field"),
ParseOptionErrorType::UnknownSubcommand => write!(f, "unknown subcommand"),
ParseOptionErrorType::RequiredField => write!(f, "missing required field"),
Expand Down
56 changes: 28 additions & 28 deletions twilight-interactions/tests/choice_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use twilight_interactions::command::{
};
use twilight_model::application::{
command::{
CommandOption as TwilightCommandOption, CommandOptionChoice, CommandOptionChoiceData,
CommandOption as TwilightCommandOption, CommandOptionChoice, CommandOptionChoiceValue,
CommandOptionType,
},
interaction::application_command::CommandOptionValue,
Expand Down Expand Up @@ -79,21 +79,21 @@ fn test_command_option_string() {
autocomplete: Some(false),
channel_types: None,
choices: Some(vec![
CommandOptionChoice::String(CommandOptionChoiceData {
CommandOptionChoice {
name: "Dog".to_string(),
name_localizations: Some(HashMap::from([("en".to_string(), "Dog".to_string())])),
value: "dog".to_string(),
}),
CommandOptionChoice::String(CommandOptionChoiceData {
value: CommandOptionChoiceValue::String("dog".to_string()),
},
CommandOptionChoice {
name: "Cat".to_string(),
name_localizations: None,
value: "cat".to_string(),
}),
CommandOptionChoice::String(CommandOptionChoiceData {
value: CommandOptionChoiceValue::String("cat".to_string()),
},
CommandOptionChoice {
name: "Crab".to_string(),
name_localizations: None,
value: "crab".to_string(),
}),
value: CommandOptionChoiceValue::String("crab".to_string()),
},
]),
description: "description".to_string(),
description_localizations: None,
Expand Down Expand Up @@ -144,21 +144,21 @@ fn test_command_option_integer() {
autocomplete: Some(false),
channel_types: None,
choices: Some(vec![
CommandOptionChoice::Integer(CommandOptionChoiceData {
CommandOptionChoice {
name: "One".to_string(),
name_localizations: None,
value: 1,
}),
CommandOptionChoice::Integer(CommandOptionChoiceData {
value: CommandOptionChoiceValue::Integer(1),
},
CommandOptionChoice {
name: "Two".to_string(),
name_localizations: None,
value: 2,
}),
CommandOptionChoice::Integer(CommandOptionChoiceData {
value: CommandOptionChoiceValue::Integer(2),
},
CommandOptionChoice {
name: "Three".to_string(),
name_localizations: None,
value: 3,
}),
value: CommandOptionChoiceValue::Integer(3),
},
]),
description: "description".to_string(),
description_localizations: None,
Expand Down Expand Up @@ -209,21 +209,21 @@ fn test_command_option_number() {
autocomplete: Some(false),
channel_types: None,
choices: Some(vec![
CommandOptionChoice::Number(CommandOptionChoiceData {
CommandOptionChoice {
name: "One".to_string(),
name_localizations: None,
value: 1.0,
}),
CommandOptionChoice::Number(CommandOptionChoiceData {
value: CommandOptionChoiceValue::Number(1.0),
},
CommandOptionChoice {
name: "Half".to_string(),
name_localizations: None,
value: 0.5,
}),
CommandOptionChoice::Number(CommandOptionChoiceData {
value: CommandOptionChoiceValue::Number(0.5),
},
CommandOptionChoice {
name: "Quarter".to_string(),
name_localizations: None,
value: 0.25,
}),
value: CommandOptionChoiceValue::Number(0.25),
},
]),
description: "description".to_string(),
description_localizations: None,
Expand Down
3 changes: 2 additions & 1 deletion twilight-interactions/tests/command_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use twilight_model::{
application::interaction::application_command::{
CommandDataOption, CommandInteractionDataResolved, CommandOptionValue, InteractionMember,
},
guild::Permissions,
guild::{MemberFlags, Permissions},
id::Id,
user::User,
util::Timestamp,
Expand Down Expand Up @@ -62,6 +62,7 @@ fn test_command_model() {
communication_disabled_until: None,
pending: false,
permissions: Permissions::empty(),
flags: MemberFlags::empty(),
};

let user = User {
Expand Down

0 comments on commit 6791b46

Please sign in to comment.