mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-11 04:21:12 +01:00
fixes and added type safe arguments
This commit is contained in:
parent
801ee3a9c9
commit
0ef5a59a1a
4 changed files with 16 additions and 8 deletions
|
@ -40,7 +40,12 @@ impl Command {
|
||||||
} else {
|
} else {
|
||||||
"/"
|
"/"
|
||||||
};
|
};
|
||||||
String::from(prefix) + &self.name
|
if let Some(rule) = &global_parameters.rename_rule {
|
||||||
|
String::from(prefix) + &rename_by_rule(&self.name, rule.as_str())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String::from(prefix) + &self.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::attr::{Attr, BotCommandAttribute};
|
use crate::attr::{Attr, BotCommandAttribute};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CommandEnum {
|
pub struct CommandEnum {
|
||||||
pub prefix: Option<String>,
|
pub prefix: Option<String>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
|
|
||||||
use quote::quote;
|
use quote::{quote};
|
||||||
use syn::FieldsUnnamed;
|
use syn::FieldsUnnamed;
|
||||||
|
|
||||||
pub fn impl_parse_args_unnamed(data: &FieldsUnnamed) -> quote::__rt::TokenStream {
|
pub fn impl_parse_args_unnamed(data: &FieldsUnnamed) -> quote::__rt::TokenStream {
|
||||||
let iter = 0..data.unnamed.len();
|
let iter = 0..data.unnamed.len();
|
||||||
quote! {
|
let mut tokens = quote! {};
|
||||||
(#(FromStr::from_str(args.get(#iter)),)*)
|
for _ in iter {
|
||||||
|
tokens.extend(quote! { CommandArgument::parse(&mut args)?, });
|
||||||
}
|
}
|
||||||
|
quote! { (#tokens) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,8 @@ fn impl_descriptions(infos: &[Command], global: &CommandEnum) -> quote::__rt::To
|
||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
fn descriptions() -> &'static str {
|
fn descriptions() -> String {
|
||||||
std::concat!(#global_description #(#command, #description, '\n'),*)
|
std::concat!(#global_description #(#command, #description, '\n'),*).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ fn impl_parse(
|
||||||
where
|
where
|
||||||
N: Into<String>
|
N: Into<String>
|
||||||
{
|
{
|
||||||
let mut words = s.split_whitespace();
|
let mut words = s.splitn(2, ' ');
|
||||||
let mut splited = words.next()?.split('@');
|
let mut splited = words.next()?.split('@');
|
||||||
let command_raw = splited.next()?;
|
let command_raw = splited.next()?;
|
||||||
let bot = splited.next();
|
let bot = splited.next();
|
||||||
|
@ -133,7 +133,7 @@ fn impl_parse(
|
||||||
None => {}
|
None => {}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
let args: Vec<&str> = words.collect();
|
let mut args = words.next().unwrap_or("").to_string();
|
||||||
match command_raw {
|
match command_raw {
|
||||||
#(
|
#(
|
||||||
#matching_values => Some(Self::#variant_ident #variants_initialization),
|
#matching_values => Some(Self::#variant_ident #variants_initialization),
|
||||||
|
|
Loading…
Reference in a new issue