mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
update docs for CommandFilter
This commit is contained in:
parent
eb430b0487
commit
583d021be7
4 changed files with 26 additions and 22 deletions
|
@ -7,8 +7,8 @@ use crate::{dispatching::Filter, types::Message};
|
|||
/// Examples:
|
||||
/// ```
|
||||
/// use teloxide::dispatching::filters::CommandFilter;
|
||||
/// CommandFilter::new("start"); // return true if text message starts with "/start"
|
||||
/// CommandFilter::with_prefix("!", "ban"); // return true if text message starts with "!ban"
|
||||
/// CommandFilter::new("start"); // filter will return true if text message starts with "/start"
|
||||
/// CommandFilter::with_prefix("!", "ban"); // filter will return true if text message starts with "!ban"
|
||||
/// ```
|
||||
pub struct CommandFilter {
|
||||
command: String,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
//! Update dispatching.
|
||||
|
||||
mod dispatchers;
|
||||
//mod dispatchers;
|
||||
pub mod error_handlers;
|
||||
pub mod filters;
|
||||
mod handler;
|
||||
pub mod updaters;
|
||||
|
||||
pub use dispatchers::filter::FilterDispatcher;
|
||||
//pub use dispatchers::filter::FilterDispatcher;
|
||||
pub use error_handlers::ErrorHandler;
|
||||
pub use filters::Filter;
|
||||
pub use handler::Handler;
|
||||
|
|
|
@ -146,23 +146,25 @@ pub fn polling(
|
|||
|
||||
stream::unfold(
|
||||
(allowed_updates, bot, 0),
|
||||
move |(mut allowed_updates, bot, mut offset)| async move {
|
||||
let mut req = bot.get_updates().offset(offset);
|
||||
req.timeout = timeout;
|
||||
req.limit = limit;
|
||||
req.allowed_updates = allowed_updates.take();
|
||||
move |(mut allowed_updates, bot, mut offset)| {
|
||||
async move {
|
||||
let mut req = bot.get_updates().offset(offset);
|
||||
req.timeout = timeout;
|
||||
req.limit = limit;
|
||||
req.allowed_updates = allowed_updates.take();
|
||||
|
||||
let updates = match req.send().await {
|
||||
Err(err) => vec![Err(err)],
|
||||
Ok(updates) => {
|
||||
if let Some(upd) = updates.last() {
|
||||
offset = upd.id + 1;
|
||||
let updates = match req.send().await {
|
||||
Err(err) => vec![Err(err)],
|
||||
Ok(updates) => {
|
||||
if let Some(upd) = updates.last() {
|
||||
offset = upd.id + 1;
|
||||
}
|
||||
updates.into_iter().map(Ok).collect::<Vec<_>>()
|
||||
}
|
||||
updates.into_iter().map(Ok).collect::<Vec<_>>()
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Some((stream::iter(updates), (allowed_updates, bot, offset)))
|
||||
Some((stream::iter(updates), (allowed_updates, bot, offset)))
|
||||
}
|
||||
},
|
||||
)
|
||||
.flatten()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{User, Message};
|
||||
use crate::types::{Message, User};
|
||||
|
||||
/// This object represents one special entity in a text message. For example,
|
||||
/// hashtags, usernames, URLs, etc.
|
||||
|
@ -42,14 +42,16 @@ pub enum MessageEntityKind {
|
|||
impl MessageEntity {
|
||||
pub fn text_from(&self, message: &Message) -> Option<String> {
|
||||
let text = message.text();
|
||||
Some(String::from(&text?[self.offset..self.offset+self.length]))
|
||||
Some(String::from(&text?[self.offset..self.offset + self.length]))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::types::{Chat, ChatKind, MessageKind, Sender, ForwardKind, MediaKind};
|
||||
use crate::types::{
|
||||
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn recursive_kind() {
|
||||
|
@ -111,7 +113,7 @@ mod tests {
|
|||
entities: vec![MessageEntity {
|
||||
kind: MessageEntityKind::Mention,
|
||||
offset: 3,
|
||||
length: 3
|
||||
length: 3,
|
||||
}],
|
||||
},
|
||||
reply_markup: None,
|
||||
|
|
Loading…
Add table
Reference in a new issue