Get ready for v0.4.0 (#347)

* Get ready for v0.4.0

* Export teloxide_macros as macros in lib.rs

* Use tokio v1.3 in README.md

* Return the feature 'macros' back

* Export teloxide_macros::teloxide in the prelude

* Document the 'macros' feature in README.md

* Update src/lib.rs

Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>

* Update src/prelude.rs

Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>

* Propagate features from teloxide-core

* teloxide-core = 0.2.1

* Fix CI

* Require teloxide-core/auto_send instead of teloxide/auto-send

* default-features = false (teloxide-core)

* Specify each teloxide-core feature separately

* Fix Cargo.toml

* JSON -> Json, CBOR -> Cbor

* Update Cargo.toml

Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>

Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>
This commit is contained in:
Hirrolot 2021-03-21 18:34:23 +06:00 committed by GitHub
parent 7bfc88ff33
commit 8522759e68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 159 additions and 102 deletions

View file

@ -1,4 +1,3 @@
on:
push:
branches: [ master ]
@ -8,8 +7,9 @@ on:
name: Continuous integration
jobs:
code-checks:
style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
@ -17,49 +17,65 @@ jobs:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy
- name: Cargo fmt
run: cargo +nightly fmt --all -- --check
- uses: actions-rs/toolchain@v1
components: rustfmt
- name: fmt
uses: actions-rs/cargo@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cargo clippy
run: cargo clippy --all --all-targets --all-features -- -D warnings
command: fmt
args: --all -- --check
test:
clippy:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
include:
- rust: stable
features: "--features \"redis-storage sqlite-storage cbor-serializer bincode-serializer frunk-\""
- rust: beta
features: "--features \"redis-storage sqlite-storage cbor-serializer bincode-serializer frunk-\""
- rust: nightly
features: "--all-features"
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy
- name: clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features -- -D warnings
test:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
include:
- rust: stable
features: "--features full"
- rust: beta
features: "--features full"
- rust: nightly
features: "--all-features"
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Build
- name: build
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose ${{ matrix.features }}
- name: Setup redis
run: |
sudo apt install redis-server
@ -67,7 +83,7 @@ jobs:
redis-server --port 7778 > /dev/null &
redis-server --port 7779 > /dev/null &
- name: Test
- name: test
uses: actions-rs/cargo@v1
with:
command: test

View file

@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [unreleased]
## [0.4.0] - 2021-03-19
### Added
- Integrate [teloxide-core].
- Allow arbitrary error types to be returned from (sub)transitions ([issue 242](https://github.com/teloxide/teloxide/issues/242)).
@ -24,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Hide `SubtransitionOutputType` from the docs.
### Changed
- Export `teloxide_macros::teloxide` in `prelude`.
- `dispatching::dialogue::serializer::{JSON -> Json, CBOR -> Cbor}`
- Allow `bot_name` be `N`, where `N: Into<String> + ...` in `commands_repl` & `commands_repl_with_listener`.
- 'Edit methods' (namely `edit_message_live_location`, `stop_message_live_location`, `edit_message_text`,
`edit_message_caption`, `edit_message_media` and `edit_message_reply_markup`) are split into common and inline

View file

@ -1,6 +1,6 @@
[package]
name = "teloxide"
version = "0.3.4"
version = "0.4.0"
edition = "2018"
description = "An elegant Telegram bots framework for Rust"
repository = "https://github.com/teloxide/teloxide"
@ -30,13 +30,36 @@ cbor-serializer = ["serde_cbor"]
bincode-serializer = ["bincode"]
frunk- = ["frunk"]
macros = ["teloxide-macros"]
nightly = [] # currently used for `README.md` tests and building docs for `docsrs` to add `This is supported on feature="..." only.`
native-tls = ["teloxide-core/native-tls"]
rustls = ["teloxide-core/rustls"]
auto-send = ["teloxide-core/auto_send"]
throttle = ["teloxide-core/throttle"]
cache-me = ["teloxide-core/cache_me"]
# currently used for `README.md` tests, building docs for `docsrs` to add `This is supported on feature="..." only.`,
# and for teloxide-core.
nightly = ["teloxide-core/nightly"]
full = [
"sqlite-storage",
"redis-storage",
"cbor-serializer",
"bincode-serializer",
"frunk",
"macros",
"teloxide-core/full",
"native-tls",
"rustls",
"auto-send",
"throttle",
"cache-me"
]
[dependencies]
teloxide-core = { version = "0.2", features = ["full"] }
teloxide-core = { version = "0.2.1", default-features = false }
teloxide-macros = { version = "0.4", optional = true }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
@ -68,8 +91,6 @@ serde_cbor = { version = "0.11", optional = true }
bincode = { version = "1.3", optional = true }
frunk = { version = "0.3", optional = true }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master", optional = true }
[dev-dependencies]
smart-default = "0.6.0"
rand = "0.8.3"

View file

@ -14,7 +14,7 @@
<img src="https://img.shields.io/crates/v/teloxide.svg">
</a>
<a href="https://core.telegram.org/bots/api">
<img src="https://img.shields.io/badge/API coverage-Up to 0.4.9 (inclusively)-green.svg">
<img src="https://img.shields.io/badge/API coverage-Up to 5.1 (inclusively)-green.svg">
</a>
<a href="https://t.me/teloxide">
<img src="https://img.shields.io/badge/official%20chat-t.me%2Fteloxide-blueviolet">
@ -79,13 +79,10 @@ $ rustup override set nightly
5. Run `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`:
```toml
[dependencies]
teloxide = "0.3"
teloxide-macros = "0.3"
teloxide = "0.4"
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "0.2.11", features = ["rt-threaded", "macros"] }
tokio = { version = "1.3", features = ["rt-threaded", "macros"] }
```
## API overview
@ -218,8 +215,12 @@ When a user sends a message to our bot and such a dialogue does not exist yet, a
pub struct StartState;
#[teloxide(subtransition)]
async fn start(_state: StartState, cx: TransitionIn<AutoSend<Bot>>, _ans: String) -> TransitionOut<Dialogue> {
cx.answer_str("Let's start! What's your full name?").await?;
async fn start(
_state: StartState,
cx: TransitionIn<AutoSend<Bot>>,
_ans: String,
) -> TransitionOut<Dialogue> {
cx.answer("Let's start! What's your full name?").await?;
next(ReceiveFullNameState)
}
```
@ -242,7 +243,7 @@ async fn receive_full_name(
cx: TransitionIn<AutoSend<Bot>>,
ans: String,
) -> TransitionOut<Dialogue> {
cx.answer_str("How old are you?").await?;
cx.answer("How old are you?").await?;
next(ReceiveAgeState::up(state, ans))
}
```
@ -269,11 +270,11 @@ async fn receive_age_state(
) -> TransitionOut<Dialogue> {
match ans.parse::<u8>() {
Ok(ans) => {
cx.answer_str("What's your location?").await?;
cx.answer("What's your location?").await?;
next(ReceiveLocationState::up(state, ans))
}
_ => {
cx.answer_str("Send me a number.").await?;
cx.answer("Send me a number.").await?;
next(state)
}
}
@ -301,7 +302,7 @@ async fn receive_location(
cx: TransitionIn<AutoSend<Bot>>,
ans: String,
) -> TransitionOut<Dialogue> {
cx.answer_str(format!("Full name: {}\nAge: {}\nLocation: {}", state.full_name, state.age, ans))
cx.answer(format!("Full name: {}\nAge: {}\nLocation: {}", state.full_name, state.age, ans))
.await?;
exit()
}
@ -330,10 +331,13 @@ async fn main() {
.await;
}
async fn handle_message(cx: UpdateWithCx<AudoSend<Bot>, Message>, dialogue: Dialogue) -> TransitionOut<Dialogue> {
match cx.update.text_owned() {
async fn handle_message(
cx: UpdateWithCx<AutoSend<Bot>, Message>,
dialogue: Dialogue,
) -> TransitionOut<Dialogue> {
match cx.update.text().map(ToOwned::to_owned) {
None => {
cx.answer_str("Send me a text message.").await?;
cx.answer("Send me a text message.").await?;
next(dialogue)
}
Some(ans) => dialogue.react(cx, ans).await,
@ -381,10 +385,21 @@ The second one produces very strange compiler messages due to the `#[tokio::main
- `cbor-serializer` -- enables the [CBOR] serializer for dialogues.
- `bincode-serializer` -- enables the [Bincode] serializer for dialogues.
- `frunk` -- enables [`teloxide::utils::UpState`], which allows mapping from a structure of `field1, ..., fieldN` to a structure of `field1, ..., fieldN, fieldN+1`.
- `macros` -- re-exports macros from [`teloxide-macros`].
- `native-tls` -- enables the [`native-tls`] TLS implementation (enabled by default).
- `rustls` -- enables the [`rustls`] TLS implementation.
- `auto-send` -- enables `AutoSend` bot adaptor.
- `cache-me` -- enables the `CacheMe` bot adaptor.
- `full` -- enables all the features except `nightly`.
- `nightly` -- enables nightly-only features (see the [teloxide-core's features]).
[CBOR]: https://en.wikipedia.org/wiki/CBOR
[Bincode]: https://github.com/servo/bincode
[`teloxide::utils::UpState`]: https://docs.rs/teloxide/latest/teloxide/utils/trait.UpState.html
[`teloxide-macros`]: https://github.com/teloxide/teloxide-macros
[`native-tls`]: https://docs.rs/native-tls
[`rustls`]: https://docs.rs/rustls
[teloxide-core's features]: https://docs.rs/teloxide-core/0.2.1/teloxide_core/#cargo-features
## FAQ
**Q: Where I can ask questions?**

View file

@ -7,10 +7,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { path = "../../", features = ["macros", "auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
teloxide = { path = "../../", features = ["macros"] }
[profile.release]
lto = true

View file

@ -7,19 +7,17 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.8"
pretty_env_logger = "0.4.0"
frunk = "0.3.1"
frunk_core = "0.3.1"
teloxide = { path = "../../", features = ["frunk", "macros", "auto-send"] }
futures = "0.3.5"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
teloxide = { path = "../../", features = ["frunk"] }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master" }
log = "0.4.8"
pretty_env_logger = "0.4.0"
derive_more = "0.99.9"
frunk = "0.3.1"
frunk_core = "0.3.1"
[profile.release]
lto = true

View file

@ -4,7 +4,7 @@ use crate::dialogue::states::{
ReceiveAgeState, ReceiveFullNameState, ReceiveLocationState, StartState,
};
use derive_more::From;
use teloxide_macros::Transition;
use teloxide::macros::Transition;
#[derive(Transition, From)]
pub enum Dialogue {

View file

@ -1,6 +1,5 @@
use crate::dialogue::{states::receive_location::ReceiveLocationState, Dialogue};
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Generic)]
pub struct ReceiveAgeState {

View file

@ -1,6 +1,5 @@
use crate::dialogue::{states::receive_age::ReceiveAgeState, Dialogue};
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Generic)]
pub struct ReceiveFullNameState;

View file

@ -1,6 +1,5 @@
use crate::dialogue::Dialogue;
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Generic)]
pub struct ReceiveLocationState {

View file

@ -1,6 +1,5 @@
use crate::dialogue::{states::ReceiveFullNameState, Dialogue};
use teloxide::prelude::*;
use teloxide_macros::teloxide;
pub struct StartState;

View file

@ -7,10 +7,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { path = "../../", features = ["auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
teloxide = { path = "../../" }
[profile.release]
lto = true

View file

@ -7,10 +7,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { path = "../../", features = ["auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
teloxide = { path = "../../" }
tokio-stream = "0.1.4"
# Used to setup a webhook

View file

@ -7,11 +7,11 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { path = "../../", features = ["auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
tokio-stream = "0.1.4"
teloxide = { path = "../../" }
# Used to setup a webhook
warp = "0.3.0"

View file

@ -5,14 +5,13 @@ authors = ["Maximilian Siling <mouse-art@ya.ru>"]
edition = "2018"
[dependencies]
# You can also choose "cbor-serializer" or built-in JSON serializer
teloxide = { path = "../../", features = ["redis-storage", "bincode-serializer", "macros", "auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
# You can also choose "cbor-serializer" or built-in JSON serializer
teloxide = { path = "../../", features = ["redis-storage", "bincode-serializer"] }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master" }
serde = "1.0.104"
futures = "0.3.5"

View file

@ -1,4 +1,4 @@
use teloxide_macros::Transition;
use teloxide::dispatching::dialogue::Transition;
use serde::{Deserialize, Serialize};

View file

@ -1,5 +1,4 @@
use teloxide::prelude::*;
use teloxide_macros::teloxide;
use super::states::*;

View file

@ -7,9 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { path = "../../", features = ["auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
tokio-stream = "0.1.3"
teloxide = { path = "../../" }
lazy_static = "1.4.0"

View file

@ -7,7 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { path = "../../", features = ["macros", "auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
teloxide = { path = "../../", features = ["macros"] }

View file

@ -5,14 +5,13 @@ authors = ["Maximilian Siling <mouse-art@ya.ru>", "Sergey Levitin <selevit@gmail
edition = "2018"
[dependencies]
# You can also choose "cbor-serializer" or built-in JSON serializer
teloxide = { path = "../../", features = ["sqlite-storage", "bincode-serializer", "redis-storage", "macros", "auto-send"] }
log = "0.4.8"
pretty_env_logger = "0.4.0"
tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] }
# You can also choose "cbor-serializer" or built-in JSON serializer
teloxide = { path = "../../", features = ["sqlite-storage", "bincode-serializer", "redis-storage"] }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master" }
serde = "1.0.104"
futures = "0.3.5"

View file

@ -7,13 +7,13 @@ mod transitions;
use states::*;
use teloxide::{
dispatching::dialogue::{serializer::JSON, SqliteStorage, Storage},
dispatching::dialogue::{serializer::Json, SqliteStorage, Storage},
prelude::*,
RequestError,
};
use thiserror::Error;
type StorageError = <SqliteStorage<JSON> as Storage<Dialogue>>::Error;
type StorageError = <SqliteStorage<Json> as Storage<Dialogue>>::Error;
#[derive(Debug, Error)]
enum Error {
@ -48,7 +48,7 @@ async fn main() {
let dialogue = dialogue.expect("std::convert::Infallible");
handle_message(cx, dialogue).await.expect("Something wrong with the bot!")
},
SqliteStorage::open("db.sqlite", JSON).await.unwrap(),
SqliteStorage::open("db.sqlite", Json).await.unwrap(),
))
.dispatch()
.await;

View file

@ -1,4 +1,4 @@
use teloxide_macros::Transition;
use teloxide::macros::Transition;
use serde::{Deserialize, Serialize};

View file

@ -1,5 +1,5 @@
use teloxide::prelude::*;
use teloxide_macros::teloxide;
use teloxide::macros::teloxide;
use super::states::*;

View file

@ -11,9 +11,9 @@ pub trait Serializer<D> {
}
/// The JSON serializer for memory storages.
pub struct JSON;
pub struct Json;
impl<D> Serializer<D> for JSON
impl<D> Serializer<D> for Json
where
D: Serialize + DeserializeOwned,
{
@ -34,12 +34,12 @@ where
#[cfg(feature = "cbor-serializer")]
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))]
pub struct CBOR;
pub struct Cbor;
#[cfg(feature = "cbor-serializer")]
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "cbor-serializer")))]
impl<D> Serializer<D> for CBOR
impl<D> Serializer<D> for Cbor
where
D: Serialize + DeserializeOwned,
{

View file

@ -182,11 +182,11 @@ where
for update in &updates {
if let Err((value, e)) = update {
log::error!(
"Cannot parse an update.\nError: {:?}\nValue: {}\n\
"Cannot parse an update.\nError: {:?}\nValue: {}\n\
This is a bug in teloxide-core, please open an issue here: \
https://github.com/teloxide/teloxide-core/issues.",
e,
value
e,
value
);
}
}

View file

@ -69,6 +69,11 @@ pub use teloxide_core::*;
#[cfg(feature = "macros")]
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
pub use teloxide_macros as macros;
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
#[cfg(feature = "macros")]
pub use teloxide_macros::teloxide;
#[cfg(all(feature = "nightly", doctest))]

View file

@ -12,14 +12,19 @@ pub use crate::{
respond,
};
pub use teloxide_core::{
adaptors::AutoSend,
types::{
CallbackQuery, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll,
PollAnswer, PreCheckoutQuery, ShippingQuery,
},
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
#[cfg(feature = "macros")]
pub use crate::teloxide;
pub use teloxide_core::types::{
CallbackQuery, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message, Poll, PollAnswer,
PreCheckoutQuery, ShippingQuery,
};
#[cfg(feature = "auto-send")]
pub use crate::adaptors::AutoSend;
#[doc(inline)]
pub use teloxide_core::prelude::*;

View file

@ -9,7 +9,7 @@ use teloxide::dispatching::dialogue::{RedisStorage, Serializer, Storage};
async fn test_redis_json() {
let storage = RedisStorage::open(
"redis://127.0.0.1:7777",
teloxide::dispatching::dialogue::serializer::JSON,
teloxide::dispatching::dialogue::serializer::Json,
)
.await
.unwrap();
@ -31,7 +31,7 @@ async fn test_redis_bincode() {
async fn test_redis_cbor() {
let storage = RedisStorage::open(
"redis://127.0.0.1:7779",
teloxide::dispatching::dialogue::serializer::CBOR,
teloxide::dispatching::dialogue::serializer::Cbor,
)
.await
.unwrap();

View file

@ -8,7 +8,7 @@ use teloxide::dispatching::dialogue::{Serializer, SqliteStorage, Storage};
#[tokio::test(flavor = "multi_thread")]
async fn test_sqlite_json() {
let storage =
SqliteStorage::open("./test_db1.sqlite", teloxide::dispatching::dialogue::serializer::JSON)
SqliteStorage::open("./test_db1.sqlite", teloxide::dispatching::dialogue::serializer::Json)
.await
.unwrap();
test_sqlite(storage).await;
@ -28,7 +28,7 @@ async fn test_sqlite_bincode() {
#[tokio::test(flavor = "multi_thread")]
async fn test_sqlite_cbor() {
let storage =
SqliteStorage::open("./test_db3.sqlite", teloxide::dispatching::dialogue::serializer::CBOR)
SqliteStorage::open("./test_db3.sqlite", teloxide::dispatching::dialogue::serializer::Cbor)
.await
.unwrap();
test_sqlite(storage).await;