use std::sync::Arc;
use serenity::builder::{CreateActionRow, CreateButton, CreateMessage};
use serenity::model::application::ButtonStyle;
use serenity::model::id::ChannelId;
use uuid::Uuid;
use crate::utils::truncate_str;
pub(crate) const FOLLOWUP_PREFIX: &str = "followup:";
pub(crate) async fn render_suggestions(
http: &Arc<serenity::http::Http>,
state: &Arc<super::DiscordState>,
session_id: Uuid,
options: Vec<String>,
) {
if options.is_empty() {
return;
}
let channel_id = match state.session_channel(session_id).await {
Some(id) => id,
None => match state.owner_channel_id().await {
Some(id) => id,
None => return,
},
};
let followup_id = Uuid::new_v4().to_string();
let rows: Vec<CreateActionRow> = options
.iter()
.enumerate()
.collect::<Vec<_>>()
.chunks(5)
.map(|chunk| {
CreateActionRow::Buttons(
chunk
.iter()
.map(|(idx, opt)| {
CreateButton::new(format!("{FOLLOWUP_PREFIX}{followup_id}:{idx}"))
.label(truncate_str(opt, 80))
.style(ButtonStyle::Secondary)
})
.collect(),
)
})
.collect();
state.register_select(followup_id, options).await;
if let Err(e) = ChannelId::new(channel_id)
.send_message(
http,
CreateMessage::new()
.content("\u{1f4a1} Suggested next:")
.components(rows),
)
.await
{
tracing::warn!("Discord suggest_followups: send failed: {e}");
}
}