Support UpdateKind::{MyChatMember, ChatMember}

This commit is contained in:
Temirkhan Myrzamadi 2021-03-17 23:36:51 +06:00
parent 0c39cc3f06
commit be7bec6fa9
5 changed files with 53 additions and 5 deletions

View file

@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow arbitrary error types to be returned from (sub)transitions ([issue 242](https://github.com/teloxide/teloxide/issues/242)).
- The `respond` function, a shortcut for `ResponseResult::Ok(())`.
- The `sqlite-storage` feature -- enables SQLite support.
- `Dispatcher::{my_chat_members_handler, chat_members_handler}`
[teloxide-core]: https://github.com/teloxide/teloxide-core
### Deprecated

View file

@ -36,7 +36,7 @@ macros = ["teloxide-macros"]
nightly = [] # currently used for `README.md` tests and building docs for `docsrs` to add `This is supported on feature="..." only.`
[dependencies]
teloxide-core = { git = "https://github.com/teloxide/teloxide-core.git", features = ["full"] }
teloxide-core = { version = "0.2", features = ["full"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }

View file

@ -9,8 +9,8 @@ use std::{fmt::Debug, sync::Arc};
use teloxide_core::{
requests::Requester,
types::{
CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll, PollAnswer,
PreCheckoutQuery, ShippingQuery, UpdateKind,
CallbackQuery, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll,
PollAnswer, PreCheckoutQuery, ShippingQuery, UpdateKind,
},
};
use tokio::sync::mpsc;
@ -61,6 +61,8 @@ pub struct Dispatcher<R> {
pre_checkout_queries_queue: Tx<R, PreCheckoutQuery>,
polls_queue: Tx<R, Poll>,
poll_answers_queue: Tx<R, PollAnswer>,
my_chat_members_queue: Tx<R, ChatMemberUpdated>,
chat_members_queue: Tx<R, ChatMemberUpdated>,
}
impl<R> Dispatcher<R>
@ -83,6 +85,8 @@ where
pre_checkout_queries_queue: None,
polls_queue: None,
poll_answers_queue: None,
my_chat_members_queue: None,
chat_members_queue: None,
}
}
@ -201,6 +205,24 @@ where
self
}
#[must_use]
pub fn my_chat_members_handler<H>(mut self, h: H) -> Self
where
H: DispatcherHandler<R, ChatMemberUpdated> + 'static + Send,
{
self.my_chat_members_queue = self.new_tx(h);
self
}
#[must_use]
pub fn chat_members_handler<H>(mut self, h: H) -> Self
where
H: DispatcherHandler<R, ChatMemberUpdated> + 'static + Send,
{
self.chat_members_queue = self.new_tx(h);
self
}
/// Starts your bot with the default parameters.
///
/// The default parameters are a long polling update listener and log all
@ -330,6 +352,22 @@ where
UpdateKind::PollAnswer
);
}
UpdateKind::MyChatMember(chat_member_updated) => {
send!(
&self.requester,
&self.my_chat_members_queue,
chat_member_updated,
UpdateKind::MyChatMember
);
}
UpdateKind::ChatMember(chat_member_updated) => {
send!(
&self.requester,
&self.chat_members_queue,
chat_member_updated,
UpdateKind::MyChatMember
);
}
}
}
})

View file

@ -34,7 +34,11 @@ where
Self: Stream<Item = UpdateWithCx<R, Message>>,
R: Send + 'static,
{
self.filter_map(|cx| async move { cx.update.text_owned().map(|text| (cx, text)) }).boxed()
self.filter_map(|cx| async move {
let text = cx.update.text().map(ToOwned::to_owned);
text.map(move |text| (cx, text))
})
.boxed()
}
fn commands<C, N>(self, bot_name: N) -> BoxStream<'static, (UpdateWithCx<R, Message>, C)>

View file

@ -15,7 +15,10 @@ pub use crate::{
pub use teloxide_core::{
adaptors::AutoSend,
requests::{Request, ResponseResult},
types::Message,
types::{
CallbackQuery, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll,
PollAnswer, PreCheckoutQuery, ShippingQuery,
},
};
#[doc(inline)]