pub struct AutoReplyManager { /* private fields */ }Expand description
自动回复管理器
核心管理器,集成所有组件处理自动回复逻辑。
§字段说明
registry: 触发器注册表,管理所有已注册的触发器whitelist: 白名单管理器,控制哪些用户可以触发自动回复cooldown: 冷却追踪器,防止用户频繁触发keyword_matcher: 关键词匹配器,用于关键词触发类型group_activations: 群组激活配置,控制群组中的触发行为config_path: 配置文件路径
Implementations§
Source§impl AutoReplyManager
impl AutoReplyManager
Sourcepub fn should_reply(&mut self, message: &IncomingMessage) -> TriggerResult
pub fn should_reply(&mut self, message: &IncomingMessage) -> TriggerResult
检查消息是否应该触发自动回复
这是核心方法,按以下顺序检查:
- 白名单检查(Requirement 6.6)
- 群组激活检查(如果是群组消息)
- 冷却时间检查(Requirement 6.7)
- 触发器匹配(Requirements 6.1, 6.2, 6.3)
§参数
message- 入站消息
§返回值
TriggerResult::Triggered- 触发成功,包含触发器和上下文TriggerResult::Rejected- 触发被拒绝,包含拒绝原因TriggerResult::NoMatch- 无匹配触发器
§示例
ⓘ
let result = manager.should_reply(&message);
match result {
TriggerResult::Triggered { trigger, context } => {
// 处理触发
}
TriggerResult::Rejected { reason } => {
// 处理拒绝
}
TriggerResult::NoMatch => {
// 无匹配
}
}Sourcepub fn register_trigger(&mut self, trigger: AutoReplyTrigger)
pub fn register_trigger(&mut self, trigger: AutoReplyTrigger)
Sourcepub fn unregister_trigger(
&mut self,
trigger_id: &str,
) -> Option<AutoReplyTrigger>
pub fn unregister_trigger( &mut self, trigger_id: &str, ) -> Option<AutoReplyTrigger>
Sourcepub fn set_group_activation(&mut self, activation: GroupActivation)
pub fn set_group_activation(&mut self, activation: GroupActivation)
Sourcepub fn get_group_activation(&self, group_id: &str) -> Option<&GroupActivation>
pub fn get_group_activation(&self, group_id: &str) -> Option<&GroupActivation>
Sourcepub fn remove_group_activation(
&mut self,
group_id: &str,
) -> Option<GroupActivation>
pub fn remove_group_activation( &mut self, group_id: &str, ) -> Option<GroupActivation>
Sourcepub fn add_to_whitelist(&mut self, user_id: String)
pub fn add_to_whitelist(&mut self, user_id: String)
Sourcepub fn remove_from_whitelist(&mut self, user_id: &str) -> bool
pub fn remove_from_whitelist(&mut self, user_id: &str) -> bool
Sourcepub fn is_user_whitelisted(&self, user_id: &str) -> bool
pub fn is_user_whitelisted(&self, user_id: &str) -> bool
Sourcepub fn set_default_cooldown(&mut self, duration: Duration)
pub fn set_default_cooldown(&mut self, duration: Duration)
Sourcepub fn set_type_cooldown(
&mut self,
trigger_type: TriggerType,
duration: Duration,
)
pub fn set_type_cooldown( &mut self, trigger_type: TriggerType, duration: Duration, )
Sourcepub fn reset_user_cooldown(&mut self, user_id: &str)
pub fn reset_user_cooldown(&mut self, user_id: &str)
Sourcepub fn config_path(&self) -> &PathBuf
pub fn config_path(&self) -> &PathBuf
获取配置文件路径
Sourcepub async fn save_config(&self) -> Result<()>
pub async fn save_config(&self) -> Result<()>
保存配置
将当前配置保存到配置文件。
Sourcepub async fn reload_config(&mut self) -> Result<()>
pub async fn reload_config(&mut self) -> Result<()>
重新加载配置
从配置文件重新加载配置。
Sourcepub fn get_stats(&self) -> AutoReplyStats
pub fn get_stats(&self) -> AutoReplyStats
获取统计信息
返回自动回复管理器的各项统计数据。
§返回值
返回 AutoReplyStats 结构体,包含:
total_triggers: 已注册的触发器总数enabled_triggers: 已启用的触发器数量whitelist_size: 白名单中的用户数量group_activations: 群组激活配置数量
§示例
ⓘ
let stats = manager.get_stats();
println!("Total triggers: {}", stats.total_triggers);
println!("Enabled triggers: {}", stats.enabled_triggers);
println!("Whitelist size: {}", stats.whitelist_size);
println!("Group activations: {}", stats.group_activations);Auto Trait Implementations§
impl Freeze for AutoReplyManager
impl RefUnwindSafe for AutoReplyManager
impl Send for AutoReplyManager
impl Sync for AutoReplyManager
impl Unpin for AutoReplyManager
impl UnsafeUnpin for AutoReplyManager
impl UnwindSafe for AutoReplyManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestCreates a shared type from an unshared type.
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.