chaz
chaz copied to clipboard
Respond to direct mentions
feels more natural to me than !chaz
. The client will autocomplete the mention, and you can do "@chaz respond please" without stepping on the whole command system ('!chaz respond' would be parsed as a command instead).
This depends on a headjack change to pass the full event back (to get at the mentions):
diff --git a/src/lib.rs b/src/lib.rs
index 73ad967..4cf4e4b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -368,7 +368,7 @@ impl Bot {
/// Useful for bots that want to act more like chatbots, having some response to every message
pub fn register_text_handler<F, Fut>(&self, callback: F)
where
- F: FnOnce(OwnedUserId, String, Room) -> Fut + Send + 'static + Clone + Sync,
+ F: FnOnce(OwnedUserId, String, Room, OriginalSyncRoomMessageEvent) -> Fut + Send + 'static + Clone + Sync,
Fut: std::future::Future<Output = Result<(), ()>> + Send + 'static,
{
let client = self.client.as_ref().expect("client not initialized");
@@ -381,7 +381,7 @@ impl Bot {
if room.state() != RoomState::Joined {
return;
}
- let MessageType::Text(text_content) = &event.content.msgtype else {
+ let MessageType::Text(text_content) = &event.content.msgtype.clone() else {
return;
};
if !is_allowed(allow_list, event.sender.as_str(), &username) {
@@ -393,7 +393,7 @@ impl Bot {
if is_command(&command_prefix, body) {
return;
}
- if let Err(e) = callback(event.sender.clone(), body.to_string(), room).await {
+ if let Err(e) = callback(event.sender.clone(), body.to_string(), room, event.clone()).await {
error!("Error responding to: {}\nError: {:?}", body, e);
}
},