Skip to content

Commit 4451379

Browse files
committed
minor improvements
1 parent 6f606a6 commit 4451379

File tree

6 files changed

+47
-35
lines changed

6 files changed

+47
-35
lines changed

Cargo.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
1010
rand = "0.8.5"
1111
rand_chacha = "0.3.1"
1212
itertools = "0.13.0"
13+
redb = "2.2.0"
14+
anyhow = "1.0.91"

src/create_pairing.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::helpers::log_error;
22
use crate::pair::pair;
3-
use crate::types::{Context, Error};
3+
use crate::types::Context;
4+
use anyhow::Result;
45
use itertools::Itertools;
56
use poise::futures_util::future::join_all;
6-
77
/// Generate a potential pairing of users who have reacted to a message
88
#[poise::command(
99
slash_command,
@@ -18,8 +18,7 @@ pub async fn create_pairing(
1818
ctx: Context<'_>,
1919
#[description = "Link to a message with reactions -- a pairing will be made between users who reacted."]
2020
message_link: String,
21-
) -> Result<(), Error> {
22-
println!("{message_link}");
21+
) -> Result<()> {
2322
let message_id = message_link
2423
.split("/")
2524
.last()

src/helpers.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::types::{Data, Error};
1+
use crate::types::Data;
2+
use anyhow::Error;
23

34
pub async fn log_error(error: poise::FrameworkError<'_, Data, Error>) {
45
println!("Error: {:?}", error);
5-
}
6+
}

src/send_pairing.rs

+21-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::log_error;
22
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};
56

67
/// Send a message to each member of the pairing.
78
#[poise::command(
@@ -60,38 +61,30 @@ pub async fn send_pairing(
6061
for pair in pairs {
6162
for user in &pair {
6263
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 ");
8376

8477
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 \
8679
schedule some time to hang out in the next two weeks. \
8780
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)_");
9185
let _ = user
9286
.create_dm_channel(&ctx)
93-
.await
94-
.unwrap()
87+
.await?
9588
.say(&ctx, message_str)
9689
.await;
9790

src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1+
use anyhow::Error;
12
pub type Data = ();
2-
pub type Error = Box<dyn std::error::Error + Send + Sync>;
33
pub type Context<'a> = poise::Context<'a, Data, Error>;

0 commit comments

Comments
 (0)