Skip to content

Commit

Permalink
feat: improve usage (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 authored Oct 27, 2024
1 parent 43e8f6a commit f487247
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/change-logger-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aionbot": patch:feat
---

Support change log level.
6 changes: 6 additions & 0 deletions .changes/event-as-any.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"aionbot-core": patch:feat
"aionbot-adapter-onebot": patch:feat
---

Add support for the `as_any` event type.
5 changes: 5 additions & 0 deletions .changes/export-in-aionbot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aionbot": patch:feat
---

Fix exports in aionbot package.
2 changes: 1 addition & 1 deletion .changes/fix-fmt.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"aionbot": patch
"aionbot": patch:feat
---

Fix formatting of the `lib.rs` file.
4 changes: 4 additions & 0 deletions crates/aionbot-adapter-onebot/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ impl Event for OnebotEvent {
Ok(())
})
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
}

impl OnebotEvent {
Expand Down
1 change: 1 addition & 0 deletions crates/aionbot-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ pub trait Event: Any + Send + Sync {
message.to_string()
)
}
fn as_any(&self) -> &dyn Any;
}
4 changes: 4 additions & 0 deletions crates/aionbot-macros/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
8 changes: 6 additions & 2 deletions crates/aionbot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit f487247

Please sign in to comment.