|
| 1 | +use std::borrow::Cow; |
| 2 | + |
1 | 3 | use crate::{ |
2 | 4 | commands::{respond_embed, respond_err, respond_ok}, |
3 | 5 | structures::{Embeddable, Snippet}, |
4 | 6 | Context, Error, |
5 | 7 | }; |
6 | | -use ::serenity::futures::{Stream, StreamExt}; |
7 | 8 | use poise::serenity_prelude::{ |
8 | | - self as serenity, futures, CreateAttachment, CreateEmbed, CreateInteractionResponse, |
| 9 | + self as serenity, CreateAttachment, CreateEmbed, CreateInteractionResponse, |
9 | 10 | CreateInteractionResponseMessage, |
10 | 11 | }; |
11 | 12 |
|
12 | 13 | #[allow(clippy::unused_async)] |
13 | 14 | async fn autocomplete_snippet<'a>( |
14 | | - ctx: Context<'a>, |
| 15 | + ctx: Context<'_>, |
15 | 16 | partial: &'a str, |
16 | | -) -> impl Stream<Item = String> + 'a { |
17 | | - let snippet_list: Vec<String> = { |
18 | | - ctx.data() |
19 | | - .state |
20 | | - .read() |
21 | | - .unwrap() |
22 | | - .snippets |
23 | | - .iter() |
24 | | - .map(Snippet::format_output) |
25 | | - .collect() |
26 | | - }; |
| 17 | +) -> serenity::CreateAutocompleteResponse<'a> { |
| 18 | + let snippet_list: Vec<_> = ctx |
| 19 | + .data() |
| 20 | + .state |
| 21 | + .read() |
| 22 | + .unwrap() |
| 23 | + .snippets |
| 24 | + .iter() |
| 25 | + .map(Snippet::format_output) |
| 26 | + .filter(|name| name.to_lowercase().contains(&partial.to_lowercase())) |
| 27 | + .map(serenity::AutocompleteChoice::from) |
| 28 | + .collect(); |
27 | 29 |
|
28 | | - futures::stream::iter(snippet_list).filter(move |name| { |
29 | | - futures::future::ready(name.to_lowercase().contains(&partial.to_lowercase())) |
30 | | - }) |
| 30 | + serenity::CreateAutocompleteResponse::new().set_choices(snippet_list) |
31 | 31 | } |
32 | 32 |
|
33 | 33 | /// Show a snippet |
@@ -282,12 +282,12 @@ async fn remove_snippet_confirm(ctx: &Context<'_>, snippet: &Snippet) -> Result< |
282 | 282 | let delete_id = format!("{ctx_id}cancel"); |
283 | 283 | let cancel_id = format!("{ctx_id}delete"); |
284 | 284 |
|
285 | | - let components = serenity::CreateActionRow::Buttons(vec![ |
| 285 | + let components = serenity::CreateActionRow::Buttons(Cow::Owned(vec![ |
286 | 286 | serenity::CreateButton::new(&cancel_id).label("Cancel"), |
287 | 287 | serenity::CreateButton::new(&delete_id) |
288 | 288 | .label("Delete") |
289 | 289 | .style(serenity::ButtonStyle::Danger), |
290 | | - ]); |
| 290 | + ])); |
291 | 291 |
|
292 | 292 | let builder: poise::CreateReply = poise::CreateReply::default() |
293 | 293 | .content(format!( |
|
0 commit comments