Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreymeng committed Oct 31, 2024
1 parent 6f606a6 commit 4451379
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
rand = "0.8.5"
rand_chacha = "0.3.1"
itertools = "0.13.0"
redb = "2.2.0"
anyhow = "1.0.91"
7 changes: 3 additions & 4 deletions src/create_pairing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::helpers::log_error;
use crate::pair::pair;
use crate::types::{Context, Error};
use crate::types::Context;
use anyhow::Result;
use itertools::Itertools;
use poise::futures_util::future::join_all;

/// Generate a potential pairing of users who have reacted to a message
#[poise::command(
slash_command,
Expand All @@ -18,8 +18,7 @@ pub async fn create_pairing(
ctx: Context<'_>,
#[description = "Link to a message with reactions -- a pairing will be made between users who reacted."]
message_link: String,
) -> Result<(), Error> {
println!("{message_link}");
) -> Result<()> {
let message_id = message_link
.split("/")
.last()
Expand Down
5 changes: 3 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::types::{Data, Error};
use crate::types::Data;
use anyhow::Error;

pub async fn log_error(error: poise::FrameworkError<'_, Data, Error>) {
println!("Error: {:?}", error);
}
}
49 changes: 21 additions & 28 deletions src/send_pairing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::log_error;
use crate::pair::pair;
use crate::types::{Context, Error};
use poise::futures_util::future::join_all;
use crate::types::Context;
use anyhow::Error;
use poise::futures_util::future::{join_all, try_join_all};

/// Send a message to each member of the pairing.
#[poise::command(
Expand Down Expand Up @@ -60,38 +61,30 @@ pub async fn send_pairing(
for pair in pairs {
for user in &pair {
let pairing: Vec<_> = pair.iter().filter(|u| *u != user).collect();
let pairing_str = if pairing.len() == 1 {
// TODO: parallelize these async requests and check API ratelimiting
// TODO: the display name should be whatever the server
let pairing1 = pairing[0].to_user(&ctx).await?;
format!(
"<@{}> ({})",
pairing1.id,
pairing1.global_name.unwrap_or(pairing1.name)
)
} else {
let pairing1 = pairing[0].to_user(&ctx).await?;
let pairing2 = pairing[1].to_user(&ctx).await?;
format!(
"<@{}> ({}) and <${}> ({})",
pairing1.id,
pairing1.global_name.unwrap_or(pairing1.name),
pairing2.id,
pairing2.global_name.unwrap_or(pairing2.name)
)
};
let pairing_str = try_join_all(pairing.iter().map(|uid| {
return async {
let u = uid.to_user(&ctx).await?;
Ok::<String, Error>(format!(
"<@{}> ({})",
u.id,
u.global_name.unwrap_or(u.name)
))
};
}))
.await?
.join(" and ");

let message_str = format!("Hey, thanks for joining ICSSC's Matchy Meetups. Your pairing \
for this round is with {pairing_str}! Please take this opportunity to reach out to them and \
for this round is here! Please take this opportunity to reach out to them and \
schedule some time to hang out in the next two weeks. \
Don't forget to send pics to https://discord.com/channels/760915616793755669/1199228930222194779 \
while you're there, and I hope you enjoy!\n\n\
\t\t\t \\- Jeffrey \n\n\
_(responses here will not be seen; please message Jeffrey directly if there are any issues)_");
while you're there, and I hope you enjoy!\n\
\t\t\t\t\t\t\t \\- Jeffrey \n\n\n\
**Your pairing is with:** {pairing_str}\n\n\
_(responses here will not be seen; please message Jeffrey directly if you have any questions)_");
let _ = user
.create_dm_channel(&ctx)
.await
.unwrap()
.await?
.say(&ctx, message_str)
.await;

Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use anyhow::Error;
pub type Data = ();
pub type Error = Box<dyn std::error::Error + Send + Sync>;
pub type Context<'a> = poise::Context<'a, Data, Error>;

0 comments on commit 4451379

Please sign in to comment.