Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve usage #23

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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