mrsbfh

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

commit c1a889fa74ae6c1463d1f27b46beb9538036f8e0
parent 344f7a052108793703cf970712a1553d7390a9f0
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sat, 20 Mar 2021 18:57:57 +0100

fix: Make sure this works with stable toolchain

fixes #1

Diffstat:
Mexample-bot/Cargo.toml | 4++--
Mexample-bot/src/commands/hello_world.rs | 2++
Mmrsbfh-macros/src/lib.rs | 12++++++++----
Mmrsbfh-macros/src/utils.rs | 11+++++------
Mmrsbfh/Cargo.toml | 1-
Mmrsbfh/src/lib.rs | 1-
6 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/example-bot/Cargo.toml b/example-bot/Cargo.toml @@ -18,4 +18,5 @@ tracing-futures = "0.2.4" tokio = { version = "0.2", features = ["full"] } clap = "3.0.0-beta.2" async-trait = "0.1.41" -thiserror = "1.0" -\ No newline at end of file +thiserror = "1.0" +regex = "1.4.3" diff --git a/example-bot/src/commands/hello_world.rs b/example-bot/src/commands/hello_world.rs @@ -2,9 +2,11 @@ use crate::config::Config; use crate::errors::Error; use matrix_sdk::events::{room::message::MessageEventContent, AnyMessageEventContent}; use mrsbfh::commands::command; +use matrix_sdk::Client; #[command(help = "`!hello_world` - Prints \"hello world\".")] pub async fn hello_world<'a>( + _client: Client, mut tx: mrsbfh::Sender, _config: Config<'a>, _sender: String, diff --git a/mrsbfh-macros/src/lib.rs b/mrsbfh-macros/src/lib.rs @@ -101,6 +101,11 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream { #command::#help_command } }); + let mut help_format_string = String::from("{}"); + input.variants.iter().for_each(|_| { + help_format_string = format!("{}{}", help_format_string,"{}"); + }); + let bot_name = match get_arg( input.span(), @@ -128,14 +133,13 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream { let help_preamble = help_title + &description + commands_title; let code = quote! { - use mrsbfh::const_concat::*; - const HELP_MARKDOWN: &str = const_concat!(#help_preamble, #(#help_parts,)*); async fn help( mut tx: mrsbfh::Sender, ) -> Result<(), Error> { let options = mrsbfh::pulldown_cmark::Options::empty(); - let parser = mrsbfh::pulldown_cmark::Parser::new_ext(HELP_MARKDOWN, options); + let help_markdown = format!(#help_format_string, #help_preamble, #(#help_parts,)*); + let parser = mrsbfh::pulldown_cmark::Parser::new_ext(&help_markdown, options); let mut html = String::new(); mrsbfh::pulldown_cmark::html::push_html(&mut html, parser); let owned_html = html.to_owned(); @@ -143,7 +147,7 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream { mrsbfh::tokio::spawn(async move { let content = matrix_sdk::events::AnyMessageEventContent::RoomMessage( matrix_sdk::events::room::message::MessageEventContent::notice_html( - HELP_MARKDOWN, + &help_markdown, owned_html, ), ); diff --git a/mrsbfh-macros/src/utils.rs b/mrsbfh-macros/src/utils.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; -use syn::spanned::Spanned; use quote::quote; +use syn::spanned::Spanned; pub(crate) fn get_arg<'a>( input_span: proc_macro2::Span, @@ -34,7 +34,7 @@ pub(crate) fn get_arg<'a>( expected, arg ), ) - .to_compile_error(); + .to_compile_error(); Err(quote! {#error}.into()) } }; @@ -47,7 +47,7 @@ pub(crate) fn get_arg<'a>( expected, arg ), ) - .to_compile_error(); + .to_compile_error(); return Err(quote! {#error}.into()); } } @@ -58,6 +58,6 @@ pub(crate) fn get_arg<'a>( expected ), ) - .to_compile_error(); + .to_compile_error(); Err(quote! {#error}.into()) -} -\ No newline at end of file +} diff --git a/mrsbfh/Cargo.toml b/mrsbfh/Cargo.toml @@ -16,7 +16,6 @@ thiserror = "1.0" # Command macros mrsbfh-macros = {path = "../mrsbfh-macros", optional = true} -const-concat = {git = "https://github.com/Vurich/const-concat", rev = "f836e77a4ecadf6a11994340fdcbbdadcdc4906d"} tokio = { version = "0.2", features = ["full"] } tracing = "0.1" diff --git a/mrsbfh/src/lib.rs b/mrsbfh/src/lib.rs @@ -67,7 +67,6 @@ impl MatrixMessageExt for Sender { } } -pub use const_concat; pub use pulldown_cmark; pub use serde_yaml; pub use tokio;