Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge v0.11.1 #758

Merged
merged 31 commits into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a7981cc
Simplify the brief description of `crate::stop`
Hirrolot Oct 7, 2022
6ebf51e
fix: Sync docs & comments with code
TmLev Oct 9, 2022
b3fe220
fix: Grammar & typos
TmLev Oct 9, 2022
a9739c7
fix: Spacing
TmLev Oct 9, 2022
643ef42
fix: Plural verb and better wording
TmLev Oct 9, 2022
aec777d
fix: No need for hyphens
TmLev Oct 9, 2022
0d4e662
Merge pull request #739 from teloxide/simplify-stop-doc
Hirrolot Oct 10, 2022
512e785
Merge pull request #743 from TmLev/master
WaffleLapkin Oct 10, 2022
7397729
Implement the `CommandRepl` trait
Hirrolot Oct 11, 2022
db30e9e
Use `Command::repl` in `README.md`
Hirrolot Oct 11, 2022
d90a9ff
Deprecate `BotCommands::ty` too
Hirrolot Oct 11, 2022
0fb9399
Make `CommandRepl`'s methods `#[must_use]`
Hirrolot Oct 15, 2022
d60a7d0
Mention graceful shutdown in the highlights
Hirrolot Oct 22, 2022
d75b465
Extend dialogue storages with RocksDB
xamgore Oct 22, 2022
f8b03ea
Merge pull request #752 from teloxide/update-readme-highlights
Hirrolot Oct 29, 2022
e7c5317
Rename `CommandRepl` => `CommandReplExt`
Hirrolot Oct 29, 2022
cb2298d
Merge pull request #746 from teloxide/command-repl
Hirrolot Oct 29, 2022
2b749ed
Link the PR to `CHANGELOG.md`
Hirrolot Oct 30, 2022
24f8476
Merge branch 'dev' into rocksdb-storage
Hirrolot Oct 30, 2022
926b8ef
Merge pull request #753 from xamgore/rocksdb-storage
Hirrolot Oct 30, 2022
e2f6fde
Update the feature set with `rocksdb-storage`
Hirrolot Oct 30, 2022
2f18b5f
Remove `,rust` from languages in `MIGRATION_GUIDE.md`
WaffleLapkin Oct 31, 2022
7287ffe
Add stop token changes to the migration guide
WaffleLapkin Oct 31, 2022
b2a4073
Merge pull request #754 from teloxide/document-rocksdb-feature
Hirrolot Oct 31, 2022
69d86d9
Don't list the `auto-send` feature in `README.md`
Hirrolot Oct 31, 2022
c9278e2
Merge pull request #755 from teloxide/migration_guide_fixes
WaffleLapkin Oct 31, 2022
3fd356e
Merge pull request #756 from teloxide/update-readme
Hirrolot Oct 31, 2022
b97c2c6
Release v0.11.1
Hirrolot Oct 31, 2022
08d2e4f
Update the migration guide version
Hirrolot Oct 31, 2022
bce24fd
Fix the version header (`CHANGELOG.md`)
Hirrolot Oct 31, 2022
42fc655
Merge pull request #757 from teloxide/release-v0.11.1
Hirrolot Oct 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## unreleased

## 0.11.1 - 2022-10-31

### Added

- The `rocksdb-storage` feature -- enables the RocksDB support ([PR #753](https://github.com/teloxide/teloxide/pull/753))
- `teloxide::dispatching::repls::CommandReplExt`, `teloxide::prelude::CommandReplExt` ([issue #740](https://github.com/teloxide/teloxide/issues/740))

### Deprecated

- `teloxide::dispatching::repls::{commands_repl, commands_repl_with_listener}`, `teloxide::utils::command::BotCommands::ty` (use `CommandReplExt` instead)

## 0.11.0 - 2022-10-07

### Changed
Expand Down Expand Up @@ -75,7 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix Api Unknown error (Can't parse entities) on message created with `utils::markdown::user_mention_or_link` if user full name contaiins some escapable symbols eg '.'
- Fix Api Unknown error (Can't parse entities) on message created with `utils::markdown::user_mention_or_link` if user full name contains some escapable symbols eg '.'

## 0.9.1 - 2022-05-27

Expand Down Expand Up @@ -188,7 +199,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `BotCommand::bot_commands` to obtain Telegram API commands ([issue 262](https://github.com/teloxide/teloxide/issues/262)).
- The `dispatching2` and `prelude2` modules. They presents a new dispatching model based on `dptree`.
- The `dispatching2` and `prelude2` modules. They present a new dispatching model based on `dptree`.

### Changed

Expand Down Expand Up @@ -265,7 +276,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Remove the `reqwest` dependency. It's not needed after the [teloxide-core] integration.
- A storage persistency bug ([issue 304](https://github.com/teloxide/teloxide/issues/304)).
- A storage persistence bug ([issue 304](https://github.com/teloxide/teloxide/issues/304)).
- Log errors from `Storage::{remove_dialogue, update_dialogue}` in `DialogueDispatcher` ([issue 302](https://github.com/teloxide/teloxide/issues/302)).
- Mark all the functions of `Storage` as `#[must_use]`.

Expand Down Expand Up @@ -371,7 +382,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Now methods which can send file to Telegram returns `tokio::io::Result<T>`. Early its could panic ([issue 216](https://github.com/teloxide/teloxide/issues/216)).
- Now methods which can send file to Telegram return `tokio::io::Result<T>`. Before that it could panic ([issue 216](https://github.com/teloxide/teloxide/issues/216)).
- If a bot wasn't triggered for several days, it stops responding ([issue 223](https://github.com/teloxide/teloxide/issues/223)).

## 0.2.0 - 2020-02-25
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "teloxide"
version = "0.11.0"
version = "0.11.1"
edition = "2021"
description = "An elegant Telegram bots framework for Rust"
repository = "https://github.com/teloxide/teloxide"
Expand All @@ -19,6 +19,7 @@ webhooks-axum = ["webhooks", "axum", "tower", "tower-http"]

sqlite-storage = ["sqlx"]
redis-storage = ["redis"]
rocksdb-storage = ["rocksdb"]
cbor-serializer = ["serde_cbor"]
bincode-serializer = ["bincode"]

Expand All @@ -42,6 +43,7 @@ full = [
"webhooks-axum",
"sqlite-storage",
"redis-storage",
"rocksdb-storage",
"cbor-serializer",
"bincode-serializer",
"macros",
Expand Down Expand Up @@ -92,6 +94,9 @@ sqlx = { version = "0.6", optional = true, default-features = false, features =
"sqlite",
] }
redis = { version = "0.21", features = ["tokio-comp"], optional = true }
rocksdb = { version = "0.19", optional = true, default-features = false, features = [
"lz4",
] }
serde_cbor = { version = "0.11", optional = true }
bincode = { version = "1.3", optional = true }
axum = { version = "0.5.13", optional = true }
Expand Down
46 changes: 36 additions & 10 deletions MIGRATION_GUIDE.md
@@ -1,19 +1,35 @@
This document describes breaking changes of `teloxide` crate, as well as the ways to update code.
Note that the list of required changes is not fully exhaustive and it may lack something in rare cases.

## 0.11 -> 0.11.1

### teloxide

We have introduced the new trait `CommandRepl` that replaces the old `commands_repl_(with_listener)` functions:

```diff
- teloxide::commands_repl(bot, answer, Command::ty())
+ Command::repl(bot, answer)
```

```diff
- teloxide::commands_repl_with_listener(bot, answer, listener, Command::ty())
+ Command::repl_with_listener(bot, answer, listener)
```

## 0.10 -> 0.11

### core

Requests can now be `.await`ed directly, without need of `.send()` or `AutoSend`.
If you previously used `AutoSend` adaptor, you can safely remove it:

```diff,rust
```diff
-let bot = Bot::from_env().auto_send();
+let bot = Bot::from_env();
```

```diff,rust
```diff
-async fn start(bot: AutoSend<Bot>, dialogue: MyDialogue, msg: Message) -> HandlerResult {
+async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult {
```
Expand Down Expand Up @@ -41,7 +57,7 @@ You may need to change code accordingly:
-let id: i32 = message.id;
+let id: MessageId = message.id;
```
```diff,rust
```diff
let (cid, mid): (ChatId, i32) = get_message_to_delete_from_db();
-bot.delete_message(cid, mid).await?;
+bot.delete_message(cid, MessageId(mid)).await?;
Expand All @@ -50,7 +66,7 @@ let (cid, mid): (ChatId, i32) = get_message_to_delete_from_db();
Note that at the same time `MessageId` is now a tuple struct.
If you've accessed its only field you'll need to change it too:

```diff,rust
```diff
-let MessageId { message_id } = bot.copy_message(dst_chat, src_chat, mid).await?;
+let MessageId(message_id) = bot.copy_message(dst_chat, src_chat, mid).await?;
save_to_db(message_id);
Expand All @@ -64,7 +80,7 @@ See `Sticker` documentation for more information about the new structure.

You can now write `Ok(())` instead of `respond(())` at the end of closures provided to RELPs:

```diff,rust
```diff
teloxide::repl(bot, |bot: Bot, msg: Message| async move {
bot.send_dice(msg.chat.id).await?;
- respond(())
Expand All @@ -75,11 +91,21 @@ teloxide::repl(bot, |bot: Bot, msg: Message| async move {

This is because REPLs now require the closure to return `RequestError` instead of a generic error type, so type inference works perfectly for a return value. If you use something other than `RequestError`, you can transfer your code to `teloxide::dispatching`, which still permits a generic error type.

"Stop tokens" were refactored, the trait is now removed and the types were renamed:

```diff
-use teloxide::dispatching::stop_token::{AsyncStopToken, AsyncStopFlag};
+use teloxide::stop::{StopToken, StopFlag, mk_stop_token};

-let (token, flag): (AsyncStopToken, AsyncStopFlag) = AsyncStopToken::new_pair();
+let (token, flag): (StopToken, StopFlag) = mk_stop_token();
```

### macros

`parse_with` now accepts a Rust _path_ to a custom parser function instead of a string:

```diff,rust
```diff
fn custom_parser(input: String) -> Result<(u8,), ParseError> {
todo!()
}
Expand All @@ -94,7 +120,7 @@ enum Command {

`rename` now only renames a command literally; use `rename_rule` to change the case of a command:

```diff,rust
```diff
#[derive(BotCommands)]
- #[command(rename = "lowercase", description = "These commands are supported:")]
+ #[command(rename_rule = "lowercase", description = "These commands are supported:")]
Expand Down Expand Up @@ -193,7 +219,7 @@ In order to make `Dispatcher` implement `Send`, `DispatcherBuilder::{default_han

v0.6 of teloxide introduces a new dispatching model based on the [chain of responsibility pattern]. To use it, you need to replace `prelude` with `prelude2` and `dispatching` with `dispatching2`. Instead of using old REPLs, you should now use `teloxide::repls2`.

The whole design is different than the previous one based on Tokio streams. In this section, we are only to address the most common usage scenarios.
The whole design is different from the previous one based on Tokio streams. In this section, we are only to address the most common usage scenarios.

First of all, now there are no streams. Instead of using streams, you use [`dptree`], which is a more suitable alternative for our purposes. Thus, if you previously used `Dispatcher::messages_handler`, now you should use `Update::filter_message()`, and so on.

Expand Down Expand Up @@ -237,7 +263,7 @@ List of changed types:

In teloxide `v0.4` (core `v0.2`) some API methods had wrong return types.
This made them practically unusable as they've always returned parsing error.
On the offchance you were using the methods, you may need to adjust types in your code.
On the off-chance you were using the methods, you may need to adjust types in your code.

List of changed return types:
- `get_chat_administrators`: `ChatMember` -> `Vec<ChatMember>`
Expand Down Expand Up @@ -324,7 +350,7 @@ List of renamed items:
#### Added `impl Clone` for {`CacheMe`, `DefaultParseMode`, `Throttle`}

Previously said bot adaptors were lacking `Clone` implementation.
To workaround this issue it was proposed to wrap bot in `Arc`.
To work around this issue it was proposed to wrap bot in `Arc`.
Now it's not required, so you can remove the `Arc`:

```diff
Expand Down
15 changes: 8 additions & 7 deletions README.md
@@ -1,4 +1,4 @@
> [v0.10 -> v0.11 migration guide >>](MIGRATION_GUIDE.md#010---011)
> [v0.11 -> v0.11.1 migration guide >>](MIGRATION_GUIDE.md#011---0111)

<div align="center">
<img src="./ICON.png" width="250"/>
Expand Down Expand Up @@ -29,12 +29,13 @@
[`dptree`]: https://github.com/teloxide/dptree
[chain of responsibility]: https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern

- **Feature-rich.** You can use both long polling and webhooks, configure an underlying HTTPS client, set a custom URL of a Telegram API server, and much more.
- **Feature-rich.** You can use both long polling and webhooks, configure an underlying HTTPS client, set a custom URL of a Telegram API server, do graceful shutdown, and much more.

- **Simple dialogues.** Our dialogues subsystem is simple and easy-to-use, and, furthermore, is agnostic of how/where dialogues are stored. For example, you can just replace a one line to achieve [persistence]. Out-of-the-box storages include [Redis] and [Sqlite].
- **Simple dialogues.** Our dialogues subsystem is simple and easy-to-use, and, furthermore, is agnostic of how/where dialogues are stored. For example, you can just replace a one line to achieve [persistence]. Out-of-the-box storages include [Redis], [RocksDB] and [Sqlite].

[persistence]: https://en.wikipedia.org/wiki/Persistence_(computer_science)
[Redis]: https://redis.io/
[RocksDB]: https://rocksdb.org/
[Sqlite]: https://www.sqlite.org

- **Strongly typed commands.** Define bot commands as an `enum` and teloxide will parse them automatically — just like JSON structures in [`serde-json`] and command-line arguments in [`structopt`].
Expand Down Expand Up @@ -72,7 +73,7 @@ $ rustup override set nightly
5. Run `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`:
```toml
[dependencies]
teloxide = { version = "0.11", features = ["macros", "auto-send"] }
teloxide = { version = "0.11", features = ["macros"] }
log = "0.4"
pretty_env_logger = "0.4"
tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] }
Expand All @@ -82,7 +83,7 @@ tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] }

### The dices bot

This bot replies with a dice throw to each received message:
This bot replies with a die throw to each received message:

[[`examples/throw_dice.rs`](examples/throw_dice.rs)]

Expand Down Expand Up @@ -131,7 +132,7 @@ async fn main() {

let bot = Bot::from_env();

teloxide::commands_repl(bot, answer, Command::ty()).await;
Command::repl(bot, answer).await;
}

#[derive(BotCommands, Clone)]
Expand Down Expand Up @@ -326,7 +327,7 @@ Feel free to propose your own bot to our collection!
- [`modos189/tg_blackbox_bot`](https://gitlab.com/modos189/tg_blackbox_bot) — Anonymous feedback for your Telegram project.
- [`0xNima/spacecraft`](https://github.com/0xNima/spacecraft) — Yet another telegram bot to downloading Twitter spaces.
- [`0xNima/Twideo`](https://github.com/0xNima/Twideo) — Simple Telegram Bot for downloading videos from Twitter via their links.
- [`mattrighetti/libgen-bot-rs`](https://github.com/mattrighetti/libgen-bot-rs) — Telgram bot to interface with libgen.
- [`mattrighetti/libgen-bot-rs`](https://github.com/mattrighetti/libgen-bot-rs) — Telegram bot to interface with libgen.
- [`zamazan4ik/npaperbot-telegram`](https://github.com/zamazan4ik/npaperbot-telegram) — Telegram bot for searching via C++ proposals.

<details>
Expand Down
6 changes: 3 additions & 3 deletions examples/admin.rs
Expand Up @@ -5,8 +5,8 @@ use teloxide::{prelude::*, types::ChatPermissions, utils::command::BotCommands};

// Derive BotCommands to parse text with a command into this enumeration.
//
// 1. rename = "lowercase" turns all the commands into lowercase letters.
// 2. `description = "..."` specifies a text before all the commands.
// 1. `rename_rule = "lowercase"` turns all the commands into lowercase letters.
// 2. `description = "..."` specifies a text before all the commands.
//
// That is, you can just call Command::descriptions() to get a description of
// your commands in this format:
Expand Down Expand Up @@ -60,7 +60,7 @@ async fn main() {

let bot = teloxide::Bot::from_env();

teloxide::commands_repl(bot, action, Command::ty()).await;
Command::repl(bot, action).await;
}

async fn action(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
Expand Down
2 changes: 1 addition & 1 deletion examples/command.rs
Expand Up @@ -7,7 +7,7 @@ async fn main() {

let bot = Bot::from_env();

teloxide::commands_repl(bot, answer, Command::ty()).await;
Command::repl(bot, answer).await;
}

#[derive(BotCommands, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion examples/db_remember.rs
Expand Up @@ -91,7 +91,7 @@ async fn got_number(
}
Command::Reset => {
dialogue.reset().await?;
bot.send_message(msg.chat.id, "Number resetted.").await?;
bot.send_message(msg.chat.id, "Number reset.").await?;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/dispatching_features.rs
Expand Up @@ -32,7 +32,7 @@ async fn main() {
.endpoint(simple_commands_handler),
)
.branch(
// Filter a maintainer by a used ID.
// Filter a maintainer by a user ID.
dptree::filter(|cfg: ConfigParameters, msg: Message| {
msg.from().map(|user| user.id == cfg.bot_maintainer).unwrap_or_default()
})
Expand Down
2 changes: 1 addition & 1 deletion examples/heroku_ping_pong.rs
Expand Up @@ -10,7 +10,7 @@
// heroku create --buildpack emk/rust
// ```
//
// To set buildpack for existing applicaton:
// To set buildpack for existing application:
//
// ```
// heroku buildpacks:set emk/rust
Expand Down
8 changes: 8 additions & 0 deletions src/dispatching/dialogue/storage.rs
Expand Up @@ -9,6 +9,9 @@ mod redis_storage;
#[cfg(feature = "sqlite-storage")]
mod sqlite_storage;

#[cfg(feature = "rocksdb-storage")]
mod rocksdb_storage;

use futures::future::BoxFuture;
use teloxide_core::types::ChatId;

Expand All @@ -25,6 +28,9 @@ use std::sync::Arc;
#[cfg(feature = "sqlite-storage")]
pub use sqlite_storage::{SqliteStorage, SqliteStorageError};

#[cfg(feature = "rocksdb-storage")]
pub use rocksdb_storage::{RocksDbStorage, RocksDbStorageError};

/// A storage with an erased error type.
pub type ErasedStorage<D> =
dyn Storage<D, Error = Box<dyn std::error::Error + Send + Sync>> + Send + Sync;
Expand All @@ -41,10 +47,12 @@ pub type ErasedStorage<D> =
///
/// - [`InMemStorage`] -- a storage based on [`std::collections::HashMap`].
/// - [`RedisStorage`] -- a Redis-based storage.
/// - [`RocksDbStorage`] -- a RocksDB-based persistent storage.
/// - [`SqliteStorage`] -- an SQLite-based persistent storage.
///
/// [`InMemStorage`]: crate::dispatching::dialogue::InMemStorage
/// [`RedisStorage`]: crate::dispatching::dialogue::RedisStorage
/// [`RocksDbStorage`]: crate::dispatching::dialogue::RocksDbStorage
/// [`SqliteStorage`]: crate::dispatching::dialogue::SqliteStorage
pub trait Storage<D> {
type Error;
Expand Down