pub struct CommandHandler<'a, F: Future<Output = Result<GroupIteration>> + Send + 'static> {
pub prefix: Vec<char>,
pub command: &'a str,
pub callback: fn(Bot, Context) -> F,
pub allow_edited: bool,
pub allow_channel: bool,
}Fields§
§prefix: Vec<char>§command: &'a str§callback: fn(Bot, Context) -> F§allow_edited: bool§allow_channel: boolImplementations§
Source§impl<'a, F: Future<Output = Result<GroupIteration>> + Send + 'static> CommandHandler<'a, F>
impl<'a, F: Future<Output = Result<GroupIteration>> + Send + 'static> CommandHandler<'a, F>
Sourcepub fn new(command: &'a str, callback: fn(Bot, Context) -> F) -> Box<Self>
pub fn new(command: &'a str, callback: fn(Bot, Context) -> F) -> Box<Self>
Examples found in repository?
examples/echobot.rs (line 27)
11async fn main() {
12 let bot_token = match env::var("FERRIS_BOT_TOKEN") {
13 Ok(s) => s,
14 Err(err) => panic!("failed to start bot: {}", err),
15 };
16 // This function creates a new bot instance and the error is handled accordingly
17 let bot = match Bot::new(&bot_token, None).await {
18 Ok(bot) => bot,
19 Err(error) => panic!("failed to create bot: {}", error),
20 };
21
22 // dispatcher is a part of internal functionality of updater
23 // you may use it for adding handlers.
24 let mut dispatcher = &mut Dispatcher::new(&bot);
25
26 // add_handler method maps the provided handler in group 0 automatically
27 dispatcher.add_handler(CommandHandler::new("start", start));
28
29 // add_handler_to_group is used to map the provided handler to a group manually.
30 // note that handler groups are processed in ascending order.
31 dispatcher.add_handler_to_group(
32 MessageHandler::new(
33 echo,
34 // This will restrict our echo function to the messages which
35 // contain either text or a caption.
36 message::Text::filter().or(message::Caption::filter()),
37 ),
38 1,
39 );
40
41 let mut updater = Updater::new(&bot, dispatcher);
42
43 // This method will start long polling through the getUpdates method
44 updater.start_polling(true).await;
45}Trait Implementations§
Source§impl<F: Future<Output = Result<GroupIteration>> + Send + 'static> Clone for CommandHandler<'_, F>
impl<F: Future<Output = Result<GroupIteration>> + Send + 'static> Clone for CommandHandler<'_, F>
Source§impl<F: Future<Output = Result<GroupIteration>> + Send + 'static> Handler for CommandHandler<'_, F>
impl<F: Future<Output = Result<GroupIteration>> + Send + 'static> Handler for CommandHandler<'_, F>
fn check_update<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
bot: &'life1 Bot,
update: &'life2 Update,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_update<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
bot: &'life1 Bot,
context: &'life2 Context,
) -> Pin<Box<dyn Future<Output = Result<GroupIteration>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl<'a, F> Freeze for CommandHandler<'a, F>
impl<'a, F> RefUnwindSafe for CommandHandler<'a, F>
impl<'a, F> Send for CommandHandler<'a, F>
impl<'a, F> Sync for CommandHandler<'a, F>
impl<'a, F> Unpin for CommandHandler<'a, F>
impl<'a, F> UnsafeUnpin for CommandHandler<'a, F>
impl<'a, F> UnwindSafe for CommandHandler<'a, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more