Merge branch 'dev' of https://github.com/teloxide/teloxide into fix_parse_command

This commit is contained in:
p0lunin 2020-02-23 14:13:28 +02:00
commit b5221d68a7
9 changed files with 76 additions and 15 deletions

View file

@ -1,7 +1,7 @@
# Contributing # Contributing
Before contributing, please read [our code style](https://github.com/teloxide/teloxide/blob/master/CODE_STYLE.md) and [the license](https://github.com/teloxide/teloxide/blob/master/LICENSE). Before contributing, please read [our code style](https://github.com/teloxide/teloxide/blob/master/CODE_STYLE.md) and [the license](https://github.com/teloxide/teloxide/blob/master/LICENSE).
To change the source code, fork this repository and work inside your own branch. Then send us a PR and wait for the CI to check everything. However, you'd better check changes first locally: To change the source code, fork this repository and work inside your own branch. Then send us a PR into the [dev](https://github.com/teloxide/teloxide/tree/dev) branch and wait for the CI to check everything. However, you'd better check changes first locally:
``` ```
cargo clippy --all --all-features --all-targets cargo clippy --all --all-features --all-targets

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2019 teloxide Copyright (c) 2019-2020 teloxide
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -51,7 +51,7 @@
$ export TELOXIDE_TOKEN=<Your token here> $ export TELOXIDE_TOKEN=<Your token here>
# Windows # Windows
$ set TELOXITE_TOKEN=<Your token here> $ set TELOXIDE_TOKEN=<Your token here>
``` ```
3. Be sure that you are up to date: 3. Be sure that you are up to date:
```bash ```bash
@ -280,13 +280,13 @@ The second one produces very strange compiler messages because of the `#[tokio::
## FAQ ## FAQ
### Where I can ask questions? ### Where I can ask questions?
[Issues](https://github.com/teloxide/teloxide/issues) is a good place for well-formed questions, for example, about the library design, enhancements, bug reports. But if you can't compile your bot due to compilation errors and need a quick help, feel free to ask in our official group: https://t.me/teloxide. [Issues](https://github.com/teloxide/teloxide/issues) is a good place for well-formed questions, for example, about the library design, enhancements, bug reports. But if you can't compile your bot due to compilation errors and need quick help, feel free to ask in our official group: https://t.me/teloxide.
### Why Rust? ### Why Rust?
Most programming languages have their own implementations of Telegram bots frameworks, so why not Rust? We think Rust provides enough good ecosystem and the language itself to be suitable for writing bots. Most programming languages have their own implementations of Telegram bots frameworks, so why not Rust? We think Rust provides enough good ecosystem and the language itself to be suitable for writing bots.
## Community bots ## Community bots
Feel free to push your own bot into our collection: https://github.com/teloxide/community-bots. Later you will be able to play with them right in our official chat: https://t.me/teloxide (coming soon...). Feel free to push your own bot into our collection: https://github.com/teloxide/community-bots. Later you will be able to play with them right in our official chat: https://t.me/teloxide.
## Contributing ## Contributing
See [CONRIBUTING.md](https://github.com/teloxide/teloxide/blob/master/CONTRIBUTING.md). See [CONRIBUTING.md](https://github.com/teloxide/teloxide/blob/master/CONTRIBUTING.md).

View file

@ -14,9 +14,7 @@ use futures::StreamExt;
use std::{fmt::Debug, sync::Arc}; use std::{fmt::Debug, sync::Arc};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::sync::Mutex; type Tx<Upd> = Option<mpsc::UnboundedSender<DispatcherHandlerCx<Upd>>>;
type Tx<Upd> = Option<Mutex<mpsc::UnboundedSender<DispatcherHandlerCx<Upd>>>>;
#[macro_use] #[macro_use]
mod macros { mod macros {
@ -37,10 +35,8 @@ async fn send<'a, Upd>(
Upd: Debug, Upd: Debug,
{ {
if let Some(tx) = tx { if let Some(tx) = tx {
if let Err(error) = tx if let Err(error) =
.lock() tx.send(DispatcherHandlerCx { bot: Arc::clone(&bot), update })
.await
.send(DispatcherHandlerCx { bot: Arc::clone(&bot), update })
{ {
log::error!( log::error!(
"The RX part of the {} channel is closed, but an update is \ "The RX part of the {} channel is closed, but an update is \
@ -103,7 +99,7 @@ impl Dispatcher {
let fut = h.handle(rx); let fut = h.handle(rx);
fut.await; fut.await;
}); });
Some(Mutex::new(tx)) Some(tx)
} }
#[must_use] #[must_use]

View file

@ -14,7 +14,7 @@
//! $ export TELOXIDE_TOKEN=<Your token here> //! $ export TELOXIDE_TOKEN=<Your token here>
//! //!
//! # Windows //! # Windows
//! $ set TELOXITE_TOKEN=<Your token here> //! $ set TELOXIDE_TOKEN=<Your token here>
//! ``` //! ```
//! //!
//! 3. Be sure that you are up to date: //! 3. Be sure that you are up to date:

View file

@ -71,7 +71,7 @@ mod tests {
assert_eq!(expected, kind); assert_eq!(expected, kind);
} }
else { else {
panic!("Этой херни здесь не должно быть"); panic!("Expected ApiErrorKind::TerminatedByOtherGetUpdates");
} }
} }
} }

View file

@ -113,6 +113,7 @@ pub enum MessageKind {
/// Specified message was pinned. Note that the Message object in this /// Specified message was pinned. Note that the Message object in this
/// field will not contain further `reply_to_message` fields even if it /// field will not contain further `reply_to_message` fields even if it
/// is itself a reply. /// is itself a reply.
#[serde(rename = "pinned_message")]
pinned: Box<Message>, pinned: Box<Message>,
}, },
Invoice { Invoice {

View file

@ -205,4 +205,46 @@ mod test {
assert!(serde_json::from_str::<Update>(text).is_ok()); assert!(serde_json::from_str::<Update>(text).is_ok());
} }
#[test]
fn pinned_message_works() {
let json = r#"{
"message": {
"chat": {
"id": -1001276785818,
"title": "teloxide dev",
"type": "supergroup",
"username": "teloxide_dev"
},
"date": 1582134655,
"from": {
"first_name": "Hirrolot",
"id": 408258968,
"is_bot": false,
"username": "hirrolot"
},
"message_id": 20225,
"pinned_message": {
"chat": {
"id": -1001276785818,
"title": "teloxide dev",
"type": "supergroup",
"username": "teloxide_dev"
},
"date": 1582134643,
"from": {
"first_name": "Hirrolot",
"id": 408258968,
"is_bot": false,
"username": "hirrolot"
},
"message_id": 20224,
"text": "Faster than a bullet"
}
},
"update_id": 845402291
}"#;
serde_json::from_str::<Update>(json).unwrap();
}
} }

22
teloxide-macros/LICENSE Normal file
View file

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2019-2020 teloxide
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.