Skip to main content

CommandHandler

Struct CommandHandler 

Source
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: bool

Implementations§

Source§

impl<'a, F: Future<Output = Result<GroupIteration>> + Send + 'static> CommandHandler<'a, F>

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Future<Output = Result<GroupIteration>> + Send + 'static> Handler for CommandHandler<'_, F>

Source§

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,

Source§

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>
where fn(Bot, Context) -> F: Freeze,

§

impl<'a, F> RefUnwindSafe for CommandHandler<'a, F>
where fn(Bot, Context) -> F: RefUnwindSafe,

§

impl<'a, F> Send for CommandHandler<'a, F>
where fn(Bot, Context) -> F: Send,

§

impl<'a, F> Sync for CommandHandler<'a, F>
where fn(Bot, Context) -> F: Sync,

§

impl<'a, F> Unpin for CommandHandler<'a, F>
where fn(Bot, Context) -> F: Unpin,

§

impl<'a, F> UnsafeUnpin for CommandHandler<'a, F>
where fn(Bot, Context) -> F: UnsafeUnpin,

§

impl<'a, F> UnwindSafe for CommandHandler<'a, F>
where fn(Bot, Context) -> F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more