summaryrefslogtreecommitdiff
path: root/src/handler/reactboard.rs
diff options
context:
space:
mode:
authorseth <[email protected]>2023-11-27 21:37:52 -0500
committerseth <[email protected]>2023-12-01 07:12:49 -0500
commitdb52e639b85d79bed870020aec7a045851ca5ee3 (patch)
treeb5895e3c219260e07d39149fa2f2215f8c9b95aa /src/handler/reactboard.rs
parent47b69d937ed944aaa41fa80661cdfa9ec72246ca (diff)
feat: add reactboard
Diffstat (limited to 'src/handler/reactboard.rs')
-rw-r--r--src/handler/reactboard.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/handler/reactboard.rs b/src/handler/reactboard.rs
new file mode 100644
index 0000000..36f8361
--- /dev/null
+++ b/src/handler/reactboard.rs
@@ -0,0 +1,66 @@
+use crate::Error;
+use crate::{settings::Settings, utils};
+use log::*;
+use poise::serenity_prelude::{Context, Message, MessageReaction, Reaction};
+
+pub async fn handle(ctx: &Context, reaction: &Reaction, settings: &Settings) -> Result<(), Error> {
+ let msg = match reaction.message(&ctx.http).await {
+ Ok(msg) => msg,
+ Err(why) => {
+ warn!("couldn't get message of reaction! {}", why);
+ return Err(Box::new(why));
+ }
+ };
+
+ if let Some(matched) = msg
+ .clone()
+ .reactions
+ .into_iter()
+ .find(|r| r.reaction_type == reaction.emoji)
+ {
+ send_to_reactboard(ctx, &matched, &msg, settings).await?;
+ } else {
+ warn!(
+ "couldn't find any matching reactions for {} in {}",
+ reaction.emoji.as_data(),
+ msg.id
+ )
+ }
+
+ Ok(())
+}
+
+async fn send_to_reactboard(
+ ctx: &Context,
+ reaction: &MessageReaction,
+ msg: &Message,
+ settings: &Settings,
+) -> Result<(), Error> {
+ if !settings.can_use_reaction(reaction) {
+ info!("reaction {} can't be used!", reaction.reaction_type);
+ return Ok(());
+ }
+
+ if reaction.count == settings.reactboard_requirement.unwrap_or(5) {
+ let embed = utils::resolve_message_to_embed(ctx, msg).await;
+
+ settings
+ .reactboard_target
+ .send_message(&ctx.http, |m| {
+ m.allowed_mentions(|am| am.empty_parse())
+ .content(format!(
+ "{} **#{}**",
+ reaction.reaction_type, reaction.count
+ ))
+ .set_embed(embed)
+ })
+ .await?;
+ } else {
+ info!(
+ "not putting message {} on reactboard, not enough reactions",
+ msg.id
+ )
+ }
+
+ Ok(())
+}