mirror of
https://github.com/ethanrusz/echbot.git
synced 2024-11-22 04:07:46 -05:00
Update team random setup
This commit is contained in:
parent
5d38b69f48
commit
b349263fd0
1 changed files with 31 additions and 29 deletions
|
@ -1,13 +1,15 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::{Context, Error};
|
|
||||||
use crate::serenity;
|
|
||||||
use poise::serenity_prelude::{Guild, Member, UserId, VoiceState};
|
|
||||||
use rand::seq::SliceRandom;
|
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
|
|
||||||
/// Return a string of pingable IDs from a slice of UserIds
|
use poise::serenity_prelude::{Guild, Member, UserId, VoiceState};
|
||||||
fn team_to_ping(team: &[&&UserId]) -> String {
|
use rand::seq::SliceRandom;
|
||||||
return team.iter().map(|o| format!("<@{}>", o.to_string())).collect::<Vec<String>>().join(", ");
|
|
||||||
|
use crate::{Context, Error};
|
||||||
|
use crate::serenity;
|
||||||
|
|
||||||
|
/// Return a string of pingable IDs from a slice of string UserIds
|
||||||
|
fn team_to_ping(team: &[&String]) -> String {
|
||||||
|
return team.iter().map(|o| format!("<@{}>", o)).collect::<Vec<String>>().join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Splits up players for custom matches
|
/// Splits up players for custom matches
|
||||||
|
@ -37,9 +39,8 @@ pub(crate) async fn team(
|
||||||
}
|
}
|
||||||
|
|
||||||
let uuid_team: u64 = ctx.id(); // Grab context ID for action row
|
let uuid_team: u64 = ctx.id(); // Grab context ID for action row
|
||||||
let users: Vec<&UserId> = Vec::from_iter(voice_states.keys()); // Get vec of PIDs
|
let users: Vec<String> = Vec::from_iter(voice_states.keys().map(|u| u.to_string())); // Get vec of PIDs
|
||||||
let players: Vec<&&UserId> = users.choose_multiple(
|
let players: Vec<&String> = users.choose_multiple(&mut rand::thread_rng(), size as usize * 2).collect(); // Pick players randomly into slice
|
||||||
&mut rand::thread_rng(), size as usize * 2).collect(); // Pick players randomly into slice
|
|
||||||
let (order, chaos) = players.split_at(players.len() / 2); // Split slice into two teams
|
let (order, chaos) = players.split_at(players.len() / 2); // Split slice into two teams
|
||||||
|
|
||||||
ctx.send(|f| f
|
ctx.send(|f| f
|
||||||
|
@ -61,30 +62,31 @@ pub(crate) async fn team(
|
||||||
|
|
||||||
while let Some(mci) = serenity::CollectComponentInteraction::new(ctx) // Handle the interaction
|
while let Some(mci) = serenity::CollectComponentInteraction::new(ctx) // Handle the interaction
|
||||||
.await {
|
.await {
|
||||||
let guild: Guild = ctx.guild().unwrap();
|
let guild: Guild = ctx.guild().unwrap(); // Grab guild from context
|
||||||
for user in chaos {
|
for user in chaos {
|
||||||
let member: Member = guild.member(ctx, UserId(*user.as_u64())).await?; // Get the member in the correct guild
|
let member: Member = guild.member(ctx, UserId(user.parse().unwrap())).await?; // Get the member in the correct guild
|
||||||
member.move_to_voice_channel(ctx, chaos_channel.id()).await?; // Move the member to the correct voice channel
|
member.move_to_voice_channel(ctx, chaos_channel.id()).await?; // Move the member to the correct voice channel
|
||||||
}
|
}
|
||||||
|
|
||||||
mci.create_interaction_response(ctx, |ir| { // Update embed
|
mci.create_interaction_response(ctx, |ir| { // Edit embed
|
||||||
ir.kind(serenity::InteractionResponseType::UpdateMessage).interaction_response_data(|f| f
|
ir.kind(serenity::InteractionResponseType::UpdateMessage)
|
||||||
.embed(|f| f
|
.interaction_response_data(|f| f
|
||||||
.title(format!("Custom {}v{} Teams", size, size))
|
.embed(|f| f
|
||||||
.description("VVGO VVW VVX")
|
.title(format!("Custom {}v{} Teams", size, size))
|
||||||
.field("Order", team_to_ping(order), false)
|
.description("VVGO VVW VVX")
|
||||||
.field("Chaos", team_to_ping(chaos), false)
|
.field("Order", team_to_ping(order), false)
|
||||||
.color(serenity::Colour::DARK_GREEN)
|
.field("Chaos", team_to_ping(chaos), false)
|
||||||
).components(|c| c // Create an action row with button
|
.color(serenity::Colour::DARK_GREEN)
|
||||||
.create_action_row(|a| a
|
).components(|c| c // Create an action row with button
|
||||||
.create_button(|b| b
|
.create_action_row(|a| a
|
||||||
.disabled(true) // with disabled button
|
.create_button(|b| b
|
||||||
.style(serenity::ButtonStyle::Primary)
|
.disabled(true) // with disabled button
|
||||||
.label("Quit Sibelius") // and new text
|
.style(serenity::ButtonStyle::Primary)
|
||||||
.custom_id(uuid_team) // Use the context ID as button ID
|
.label("Quit Sibelius") // and new text
|
||||||
|
.custom_id(uuid_team) // Use the context ID as button ID
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
))
|
|
||||||
}).await?;
|
}).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue