feat: send category
This commit is contained in:
parent
18eba1d443
commit
e739c443ac
7 changed files with 53 additions and 13 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue