From f48724774fec05548798a76ad7e93597fb24bec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= <46275354+fu050409@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:13:27 +0800 Subject: [PATCH] feat: improve usage (#23) --- .changes/change-logger-level.md | 5 +++++ .changes/event-as-any.md | 6 ++++++ .changes/export-in-aionbot.md | 5 +++++ .changes/fix-fmt.md | 2 +- crates/aionbot-adapter-onebot/src/event.rs | 4 ++++ crates/aionbot-core/src/event.rs | 1 + crates/aionbot-macros/tests/macros.rs | 4 ++++ crates/aionbot/src/lib.rs | 8 ++++++-- 8 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 .changes/change-logger-level.md create mode 100644 .changes/event-as-any.md create mode 100644 .changes/export-in-aionbot.md diff --git a/.changes/change-logger-level.md b/.changes/change-logger-level.md new file mode 100644 index 0000000..b6de4f6 --- /dev/null +++ b/.changes/change-logger-level.md @@ -0,0 +1,5 @@ +--- +"aionbot": patch:feat +--- + +Support change log level. diff --git a/.changes/event-as-any.md b/.changes/event-as-any.md new file mode 100644 index 0000000..02539ab --- /dev/null +++ b/.changes/event-as-any.md @@ -0,0 +1,6 @@ +--- +"aionbot-core": patch:feat +"aionbot-adapter-onebot": patch:feat +--- + +Add support for the `as_any` event type. diff --git a/.changes/export-in-aionbot.md b/.changes/export-in-aionbot.md new file mode 100644 index 0000000..0e9637e --- /dev/null +++ b/.changes/export-in-aionbot.md @@ -0,0 +1,5 @@ +--- +"aionbot": patch:feat +--- + +Fix exports in aionbot package. diff --git a/.changes/fix-fmt.md b/.changes/fix-fmt.md index 5fa5c0f..6ed14b9 100644 --- a/.changes/fix-fmt.md +++ b/.changes/fix-fmt.md @@ -1,5 +1,5 @@ --- -"aionbot": patch +"aionbot": patch:feat --- Fix formatting of the `lib.rs` file. diff --git a/crates/aionbot-adapter-onebot/src/event.rs b/crates/aionbot-adapter-onebot/src/event.rs index 64beaef..dbe5bd4 100644 --- a/crates/aionbot-adapter-onebot/src/event.rs +++ b/crates/aionbot-adapter-onebot/src/event.rs @@ -60,6 +60,10 @@ impl Event for OnebotEvent { Ok(()) }) } + + fn as_any(&self) -> &dyn std::any::Any { + self + } } impl OnebotEvent { diff --git a/crates/aionbot-core/src/event.rs b/crates/aionbot-core/src/event.rs index 41f3d40..b0ed0c8 100644 --- a/crates/aionbot-core/src/event.rs +++ b/crates/aionbot-core/src/event.rs @@ -51,4 +51,5 @@ pub trait Event: Any + Send + Sync { message.to_string() ) } + fn as_any(&self) -> &dyn Any; } diff --git a/crates/aionbot-macros/tests/macros.rs b/crates/aionbot-macros/tests/macros.rs index cf68f82..228019b 100644 --- a/crates/aionbot-macros/tests/macros.rs +++ b/crates/aionbot-macros/tests/macros.rs @@ -12,6 +12,10 @@ impl Event for ConcreteEvent { fn event_type(&self) -> &str { unimplemented!() } + + fn as_any(&self) -> &dyn std::any::Any { + self + } } #[register(router = "test_router")] diff --git a/crates/aionbot/src/lib.rs b/crates/aionbot/src/lib.rs index fb83a5c..f3ff7ee 100644 --- a/crates/aionbot/src/lib.rs +++ b/crates/aionbot/src/lib.rs @@ -1,10 +1,14 @@ +pub extern crate aionbot_core; +pub extern crate aionbot_macros; + pub use aionbot_core::prelude::*; +pub use aionbot_core::runtime::Builder; pub use aionbot_macros::register; use anyhow::Result; use colored::Colorize; -pub fn setup_logger() -> Result<()> { +pub fn setup_logger(log_level: log::LevelFilter) -> Result<()> { fern::Dispatch::new() .format(|out, message, record| { let level = record.level().as_str(); @@ -40,7 +44,7 @@ pub fn setup_logger() -> Result<()> { }; out.finish(format_args!("{}", fmt_string)) }) - .level(log::LevelFilter::Debug) + .level(log_level) .chain(std::io::stdout()) .apply()?; Ok(())