add a few common used on_event handlers #6

Merged
sarah merged 6 commits from on_handlers into main 2022-07-22 16:39:32 +00:00
2 changed files with 7 additions and 4 deletions
Showing only changes of commit 1dc66709dd - Show all commits

View File

@ -1,11 +1,11 @@
[package]
name = "imp"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libcwtch = { path="./../libcwtch-rs"} #"0.3.2"
libcwtch = "0.4.0"
serde_json = "1.0"
chrono = "0.4.19"

View File

@ -12,9 +12,12 @@ It is in the very early prototype stage with one prototype use in the Cwtch [upd
Start with creating a `Behaviour` struct and populating it with your desired set of bot behaviours, then `imp::spawn` your bot with the behaviour.
Define a struct fulfilling the `imp::EventHandler` trait with all your custom event handling code.
To handle Cwtch events you can either
- Define a struct fulfilling the `imp::EventHandler::event_loop` function which has the capacity to support all the events libCwtch can emit
- Override specific `on_x_event` functions in `imp::EventHandler` such as `on_new_message_from_contact`
- This is newer and more will be defined in later versions
Finally, run the imp `my_imp.event_loop(Box::new(custom_event_handler));`
Finally, run the imp `my_imp.event_loop::<MyEventHandlerType>(update_bot.borrow_mut());`
## Examples