puniyu_handler_command 0.8.9

puniyu 命令处理器,统一命令匹配、权限检查与执行分发流程
Documentation
use puniyu_core::config::friend_config;
use puniyu_cooldown::{CooldownRegistry, CooldownScope};
use puniyu_error::registry::Error;
use std::time::Duration;

pub(crate) fn set_cooldown(user_id: &str, bot_id: &str) -> Result<(), Error> {
	let friend_config = friend_config();
	let scope = CooldownScope::Friend { bot_id, user_id };
	let global_cd = friend_config.global().cd();
	if global_cd > 0 {
		CooldownRegistry::set_cooldown(&scope, Duration::from_millis(global_cd))?;
	}
	let friend_cd = friend_config.friend(user_id).cd();
	if friend_cd > 0 {
		CooldownRegistry::set_cooldown(&scope, Duration::from_millis(friend_cd))?;
	}

	Ok(())
}