replace admin command branches returning RoomMessageEventContent

rename admin Command back to Context

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-04-06 23:41:58 +00:00 committed by Jade Ellis
parent fb3020d8da
commit 4f8fec7e5a
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
32 changed files with 903 additions and 1306 deletions

View file

@ -8,7 +8,7 @@ use crate::{Result, utils::camel_to_snake_string};
pub(super) fn command(mut item: ItemFn, _args: &[Meta]) -> Result<TokenStream> {
let attr: Attribute = parse_quote! {
#[conduwuit_macros::implement(crate::Command, params = "<'_>")]
#[conduwuit_macros::implement(crate::Context, params = "<'_>")]
};
item.attrs.push(attr);
@ -19,15 +19,16 @@ pub(super) fn command_dispatch(item: ItemEnum, _args: &[Meta]) -> Result<TokenSt
let name = &item.ident;
let arm: Vec<TokenStream2> = item.variants.iter().map(dispatch_arm).try_collect()?;
let switch = quote! {
#[allow(clippy::large_stack_frames)] //TODO: fixme
pub(super) async fn process(
command: #name,
context: &crate::Command<'_>
context: &crate::Context<'_>
) -> Result {
use #name::*;
#[allow(non_snake_case)]
Ok(match command {
match command {
#( #arm )*
})
}
}
};
@ -47,8 +48,7 @@ fn dispatch_arm(v: &Variant) -> Result<TokenStream2> {
let arg = field.clone();
quote! {
#name { #( #field ),* } => {
let c = Box::pin(context.#handler(#( #arg ),*)).await?;
Box::pin(context.write_str(c.body())).await?;
Box::pin(context.#handler(#( #arg ),*)).await
},
}
},
@ -58,15 +58,14 @@ fn dispatch_arm(v: &Variant) -> Result<TokenStream2> {
};
quote! {
#name ( #field ) => {
Box::pin(#handler::process(#field, context)).await?;
Box::pin(#handler::process(#field, context)).await
}
}
},
| Fields::Unit => {
quote! {
#name => {
let c = Box::pin(context.#handler()).await?;
Box::pin(context.write_str(c.body())).await?;
Box::pin(context.#handler()).await
},
}
},