mrsbfh

Matrix-Rust-SDK-Bot-Framework-Helper
git clone git://archive.git.mtrnord.blog/MTRNord/mrsbfh.git
Log | Files | Refs | README

commit 70b49bdb0c61119e9a9a36ba049c664f4be34a6b
parent dcde58ee9bdd8a67e8a739e02a840af0d24574ab
Author: MTRNord <mtrnord1@gmail.com>
Date:   Thu,  4 Nov 2021 20:12:49 +0100

feat: Add room_id info to command handlers

Diffstat:
Mexample-bot/src/commands/hello_world.rs | 4+++-
Mmrsbfh-macros/src/lib.rs | 9+++++----
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/example-bot/src/commands/hello_world.rs b/example-bot/src/commands/hello_world.rs @@ -3,13 +3,15 @@ use crate::errors::Error; use matrix_sdk::events::{room::message::MessageEventContent, AnyMessageEventContent}; use mrsbfh::commands::command; use matrix_sdk::Client; +use matrix_sdk::identifiers::RoomId; #[command(help = "`!hello_world` - Prints \"hello world\".")] pub async fn hello_world<'a>( _client: Client, - mut tx: mrsbfh::Sender, + tx: mrsbfh::Sender, _config: Config<'a>, _sender: String, + _room_id: RoomId, mut _args: Vec<&str>, ) -> Result<(), Error> where diff --git a/mrsbfh-macros/src/lib.rs b/mrsbfh-macros/src/lib.rs @@ -80,10 +80,10 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream { quote! { #command_string => { - #command::#command(client, tx, config, sender, args).await + #command::#command(client, tx, config, sender, room_id, args).await }, #command_short => { - #command::#command(client, tx, config, sender, args).await + #command::#command(client, tx, config, sender, room_id, args).await }, } }); @@ -159,7 +159,7 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream { Ok(()) } - pub async fn match_command<'a>(cmd: &str, client: matrix_sdk::Client, config: Config<'a>, tx: mrsbfh::Sender, sender: String, args: Vec<&str>,) -> Result<(), Error> where Config<'a>: mrsbfh::config::Loader + Clone { + pub async fn match_command<'a>(cmd: &str, client: matrix_sdk::Client, config: Config<'a>, tx: mrsbfh::Sender, sender: String, room_id: matrix_sdk::identifiers::RoomId, args: Vec<&str>,) -> Result<(), Error> where Config<'a>: mrsbfh::config::Loader + Clone { match cmd { #(#commands)* "help" => { @@ -328,7 +328,7 @@ pub fn commands(_: TokenStream, input: TokenStream) -> TokenStream { let sender = event.sender.clone().to_string(); let (tx, mut rx) = mpsc::channel(100); - let room_id = room.room_id(); + let room_id = room.room_id().clone(); let cloned_config = self.config.clone(); let cloned_client = self.client.clone(); @@ -356,6 +356,7 @@ pub fn commands(_: TokenStream, input: TokenStream) -> TokenStream { cloned_config.clone(), tx, sender, + room_id, args, ) .await