Skip to content

Commit

Permalink
Fix breakage caused by AsRef removal and error cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Jan 11, 2024
1 parent dad39fe commit 042072c
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 45 deletions.
54 changes: 25 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/advanced_cooldowns/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() {
})
.build();

let client = serenity::Client::builder(token, serenity::GatewayIntents::non_privileged())
let client = serenity::Client::builder(&token, serenity::GatewayIntents::non_privileged())
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/basic_structure/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn main() {
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/event_handler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() {
})
.build();

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/feature_showcase/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn main() {
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/fluent_localization/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn main() {
.setup(move |_, _, _| Box::pin(async move { Ok(Data { translations }) }))
.build();

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/help_generation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ async fn main() {
})
.build();

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/invocation_data/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn main() {
})
.build();

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;

Expand Down
2 changes: 1 addition & 1 deletion examples/manual_dispatch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn main() -> Result<(), Error> {
poise::set_qualified_names(&mut handler.options.commands); // some setup

let handler = std::sync::Arc::new(handler);
let mut client = serenity::Client::builder(token, intents)
let mut client = serenity::Client::builder(&token, intents)
.event_handler::<Handler>(handler.clone())
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn main() {
})
.build();

let client = serenity::ClientBuilder::new(token, intents)
let client = serenity::ClientBuilder::new(&token, intents)
.framework(framework)
.await;
client.unwrap().start().await.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions macros/src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn modal(input: syn::DeriveInput) -> Result<TokenStream, darling::Error> {
// Create modal parser code for this field
let ok_or = if required {
let error = format!("missing {}", field_ident);
Some(quote::quote! { .ok_or(#error)? })
Some(quote::quote! { .expect(#error) })
} else {
None
};
Expand All @@ -107,8 +107,8 @@ pub fn modal(input: syn::DeriveInput) -> Result<TokenStream, darling::Error> {
)
}

fn parse(mut data: serenity::ModalInteractionData) -> ::std::result::Result<Self, &'static str> {
Ok(Self { #( #parsers )* })
fn parse(mut data: serenity::ModalInteractionData) -> Self {
Self { #( #parsers )* }
}
}
}; }
Expand Down
6 changes: 2 additions & 4 deletions src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ async fn execute_modal_generic<
.create_response(ctx, serenity::CreateInteractionResponse::Acknowledge)
.await?;

Ok(Some(
M::parse(response.data.clone()).map_err(serenity::Error::Other)?,
))
Ok(Some(M::parse(response.data)))
}

/// Convenience function for showing the modal and waiting for a response.
Expand Down Expand Up @@ -184,7 +182,7 @@ pub trait Modal: Sized {
///
/// Returns an error if a field was missing. This should never happen, because Discord will only
/// let users submit when all required fields are filled properly
fn parse(data: serenity::ModalInteractionData) -> Result<Self, &'static str>;
fn parse(data: serenity::ModalInteractionData) -> Self;

/// Calls `execute_modal(ctx, None, None)`. See [`execute_modal`]
///
Expand Down

0 comments on commit 042072c

Please sign in to comment.