|
1 | 1 | use crate::log_error;
|
2 | 2 | use crate::pair::pair;
|
3 |
| -use crate::types::{Context, Error}; |
4 |
| -use poise::futures_util::future::join_all; |
| 3 | +use crate::types::Context; |
| 4 | +use anyhow::Error; |
| 5 | +use poise::futures_util::future::{join_all, try_join_all}; |
5 | 6 |
|
6 | 7 | /// Send a message to each member of the pairing.
|
7 | 8 | #[poise::command(
|
@@ -60,38 +61,30 @@ pub async fn send_pairing(
|
60 | 61 | for pair in pairs {
|
61 | 62 | for user in &pair {
|
62 | 63 | let pairing: Vec<_> = pair.iter().filter(|u| *u != user).collect();
|
63 |
| - let pairing_str = if pairing.len() == 1 { |
64 |
| - // TODO: parallelize these async requests and check API ratelimiting |
65 |
| - // TODO: the display name should be whatever the server |
66 |
| - let pairing1 = pairing[0].to_user(&ctx).await?; |
67 |
| - format!( |
68 |
| - "<@{}> ({})", |
69 |
| - pairing1.id, |
70 |
| - pairing1.global_name.unwrap_or(pairing1.name) |
71 |
| - ) |
72 |
| - } else { |
73 |
| - let pairing1 = pairing[0].to_user(&ctx).await?; |
74 |
| - let pairing2 = pairing[1].to_user(&ctx).await?; |
75 |
| - format!( |
76 |
| - "<@{}> ({}) and <${}> ({})", |
77 |
| - pairing1.id, |
78 |
| - pairing1.global_name.unwrap_or(pairing1.name), |
79 |
| - pairing2.id, |
80 |
| - pairing2.global_name.unwrap_or(pairing2.name) |
81 |
| - ) |
82 |
| - }; |
| 64 | + let pairing_str = try_join_all(pairing.iter().map(|uid| { |
| 65 | + return async { |
| 66 | + let u = uid.to_user(&ctx).await?; |
| 67 | + Ok::<String, Error>(format!( |
| 68 | + "<@{}> ({})", |
| 69 | + u.id, |
| 70 | + u.global_name.unwrap_or(u.name) |
| 71 | + )) |
| 72 | + }; |
| 73 | + })) |
| 74 | + .await? |
| 75 | + .join(" and "); |
83 | 76 |
|
84 | 77 | let message_str = format!("Hey, thanks for joining ICSSC's Matchy Meetups. Your pairing \
|
85 |
| - for this round is with {pairing_str}! Please take this opportunity to reach out to them and \ |
| 78 | + for this round is here! Please take this opportunity to reach out to them and \ |
86 | 79 | schedule some time to hang out in the next two weeks. \
|
87 | 80 | Don't forget to send pics to https://discord.com/channels/760915616793755669/1199228930222194779 \
|
88 |
| - while you're there, and I hope you enjoy!\n\n\ |
89 |
| - \t\t\t \\- Jeffrey \n\n\ |
90 |
| - _(responses here will not be seen; please message Jeffrey directly if there are any issues)_"); |
| 81 | + while you're there, and I hope you enjoy!\n\ |
| 82 | + \t\t\t\t\t\t\t \\- Jeffrey \n\n\n\ |
| 83 | + **Your pairing is with:** {pairing_str}\n\n\ |
| 84 | + _(responses here will not be seen; please message Jeffrey directly if you have any questions)_"); |
91 | 85 | let _ = user
|
92 | 86 | .create_dm_channel(&ctx)
|
93 |
| - .await |
94 |
| - .unwrap() |
| 87 | + .await? |
95 | 88 | .say(&ctx, message_str)
|
96 | 89 | .await;
|
97 | 90 |
|
|
0 commit comments