feat: send category
All checks were successful
Build / Build (push) Successful in 2m0s
Build / docker (push) Successful in 1m23s

This commit is contained in:
파링 2026-01-06 11:58:55 +09:00
parent 18eba1d443
commit e739c443ac
Signed by: paring
SSH key fingerprint: SHA256:8uCHhCpn/gVOLEaTolmbub9kfM6XBxWkIWmHxUZoWWk
7 changed files with 53 additions and 13 deletions

View file

@ -3,6 +3,7 @@ use std::collections::HashMap;
use anyhow::anyhow;
use rhai::{Dynamic, Engine, Map, Scope};
use serde::Deserialize;
use tracing::debug;
#[derive(Debug, Deserialize, Clone)]
pub struct ReactionResult {
@ -15,7 +16,9 @@ pub fn check(
script: &str,
reactions: HashMap<String, i64>,
channel: String,
category: Option<String>,
) -> anyhow::Result<Option<ReactionResult>> {
debug!("script: {script}");
let mut engine = Engine::new();
engine.set_max_operations(1000);
engine.register_type::<ReactionResult>();
@ -45,10 +48,21 @@ pub fn check(
scope.set_value("reactions", Dynamic::from(emotes_input));
scope.set_value("channel", Dynamic::from(channel));
scope.set_value(
"category",
if let Some(value) = category {
Dynamic::from(value)
} else {
Dynamic::UNIT
},
);
let result: Dynamic = engine
.eval_with_scope(&mut scope, script)
.map_err(|e| anyhow!("{e:?}"))?;
debug!("result: {result:?}");
let result: Option<ReactionResult> = if result.is_unit() {
None
} else {