diff --git a/Cargo.toml b/Cargo.toml index 892b5022..97c0d8f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,9 @@ license = "MIT" exclude = ["media"] [features] -default = ["native-tls", "ctrlc_handler", "teloxide-core/default", "auto-send", "new-dispatching"] +default = ["native-tls", "ctrlc_handler", "teloxide-core/default", "auto-send", "dispatching2"] -old-dispatching = [] -new-dispatching = ["dptree"] +dispatching2 = ["dptree"] sqlite-storage = ["sqlx"] redis-storage = ["redis"] diff --git a/examples/admin_bot/src/main.rs b/examples/admin_bot/src/main.rs index bb642a6d..9d2e9a78 100644 --- a/examples/admin_bot/src/main.rs +++ b/examples/admin_bot/src/main.rs @@ -2,7 +2,7 @@ use std::{error::Error, str::FromStr}; use chrono::{DateTime, Duration, NaiveDateTime, Utc}; use teloxide::{ - prelude::*, + prelude2::*, types::{ChatPermissions, Me}, utils::command::BotCommand, }; @@ -162,5 +162,5 @@ async fn main() { let Me { user: bot_user, .. } = bot.get_me().await.unwrap(); let bot_name = bot_user.username.expect("Bots must have usernames"); - teloxide::commands_repl(bot, bot_name, action, Command::ty()).await; + teloxide::repls2::commands_repl(bot, bot_name, action, Command::ty()).await; } diff --git a/examples/dialogue_bot/Cargo.toml b/examples/dialogue_bot/Cargo.toml index 31439f77..7db03bfb 100644 --- a/examples/dialogue_bot/Cargo.toml +++ b/examples/dialogue_bot/Cargo.toml @@ -11,15 +11,10 @@ teloxide = { path = "../../", features = ["frunk", "macros", "sqlite-storage"] } anyhow = "1.0.52" serde = "1" -futures = "0.3.5" tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] } log = "0.4.8" pretty_env_logger = "0.4.0" -derive_more = "0.99.9" - -frunk = "0.4" -frunk_core = "0.4" [profile.release] lto = true diff --git a/examples/dialogue_bot/src/main.rs b/examples/dialogue_bot/src/main.rs index 7042e245..8f211cbe 100644 --- a/examples/dialogue_bot/src/main.rs +++ b/examples/dialogue_bot/src/main.rs @@ -16,7 +16,7 @@ use teloxide::{ dispatching2::dialogue::{serializer::Json, SqliteStorage}, macros::DialogueState, - prelude::*, + prelude2::*, }; // FIXME: naming diff --git a/examples/dices_bot/src/main.rs b/examples/dices_bot/src/main.rs index 10d52566..b6587936 100644 --- a/examples/dices_bot/src/main.rs +++ b/examples/dices_bot/src/main.rs @@ -1,6 +1,6 @@ // This bot throws a dice on each incoming message. -use teloxide::prelude::*; +use teloxide::prelude2::*; type TeleBot = AutoSend; @@ -11,7 +11,7 @@ async fn main() { let bot = Bot::from_env().auto_send(); - teloxide::repl(bot, |message: Message, bot: TeleBot| async move { + teloxide::repls2::repl(bot, |message: Message, bot: TeleBot| async move { bot.send_dice(message.chat.id).await?; respond(()) }) diff --git a/examples/heroku_ping_pong_bot/src/main.rs b/examples/heroku_ping_pong_bot/src/main.rs index 508bcafc..9a280dd5 100644 --- a/examples/heroku_ping_pong_bot/src/main.rs +++ b/examples/heroku_ping_pong_bot/src/main.rs @@ -6,7 +6,7 @@ use teloxide::{ stop_token::AsyncStopToken, update_listeners::{self, StatefulListener}, }, - prelude::*, + prelude2::*, types::Update, }; @@ -24,7 +24,7 @@ async fn main() { let bot = Bot::from_env().auto_send(); - teloxide::repl_with_listener( + teloxide::repls2::repl_with_listener( bot.clone(), |mes: Message, bot: AutoSend| async move { bot.send_message(mes.chat.id, "pong").await?; diff --git a/examples/inline_bot/Cargo.toml b/examples/inline_bot/Cargo.toml index 913b25c8..ee17ce38 100644 --- a/examples/inline_bot/Cargo.toml +++ b/examples/inline_bot/Cargo.toml @@ -11,4 +11,3 @@ teloxide = { path = "../../", features = ["macros"] } 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" diff --git a/examples/inline_bot/src/main.rs b/examples/inline_bot/src/main.rs index 99273c40..bae454b6 100644 --- a/examples/inline_bot/src/main.rs +++ b/examples/inline_bot/src/main.rs @@ -1,5 +1,5 @@ use teloxide::{ - prelude::*, + prelude2::*, types::{ InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText, }, diff --git a/examples/ngrok_ping_pong_bot/src/main.rs b/examples/ngrok_ping_pong_bot/src/main.rs index 87fa3fdb..4cbb484b 100644 --- a/examples/ngrok_ping_pong_bot/src/main.rs +++ b/examples/ngrok_ping_pong_bot/src/main.rs @@ -6,7 +6,7 @@ use teloxide::{ stop_token::AsyncStopToken, update_listeners::{self, StatefulListener}, }, - prelude::*, + prelude2::*, types::Update, }; @@ -24,7 +24,7 @@ async fn main() { let bot = Bot::from_env().auto_send(); - teloxide::repl_with_listener( + teloxide::repls2::repl_with_listener( bot.clone(), |mes: Message, bot: AutoSend| async move { bot.send_message(mes.chat.id, "pong").await?; diff --git a/examples/redis_remember_bot/Cargo.toml b/examples/redis_remember_bot/Cargo.toml index 57d7b547..6d05e0b0 100644 --- a/examples/redis_remember_bot/Cargo.toml +++ b/examples/redis_remember_bot/Cargo.toml @@ -13,7 +13,4 @@ pretty_env_logger = "0.4.0" tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] } serde = "1.0.104" -futures = "0.3.5" - thiserror = "1.0.15" -derive_more = "0.99.9" diff --git a/examples/redis_remember_bot/src/main.rs b/examples/redis_remember_bot/src/main.rs index 248677c9..36629c46 100644 --- a/examples/redis_remember_bot/src/main.rs +++ b/examples/redis_remember_bot/src/main.rs @@ -1,6 +1,6 @@ use teloxide::{ dispatching2::dialogue::{serializer::Bincode, RedisStorage, Storage}, - prelude::*, + prelude2::*, RequestError, }; use thiserror::Error; diff --git a/examples/shared_state_bot/src/main.rs b/examples/shared_state_bot/src/main.rs index 45585ad9..b598b5a6 100644 --- a/examples/shared_state_bot/src/main.rs +++ b/examples/shared_state_bot/src/main.rs @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use lazy_static::lazy_static; -use teloxide::prelude::*; +use teloxide::prelude2::*; lazy_static! { static ref MESSAGES_TOTAL: AtomicU64 = AtomicU64::new(0); diff --git a/examples/simple_commands_bot/src/main.rs b/examples/simple_commands_bot/src/main.rs index 7ba91528..f3dfb30b 100644 --- a/examples/simple_commands_bot/src/main.rs +++ b/examples/simple_commands_bot/src/main.rs @@ -1,4 +1,4 @@ -use teloxide::{prelude::*, utils::command::BotCommand}; +use teloxide::{prelude2::*, utils::command::BotCommand}; use std::error::Error; use teloxide::types::Me; @@ -46,5 +46,5 @@ async fn main() { let Me { user: bot_user, .. } = bot.get_me().await.unwrap(); let bot_name = bot_user.username.expect("Bots must have usernames"); - teloxide::commands_repl(bot, bot_name, answer, Command::ty()).await; + teloxide::repls2::commands_repl(bot, bot_name, answer, Command::ty()).await; } diff --git a/examples/sqlite_remember_bot/Cargo.toml b/examples/sqlite_remember_bot/Cargo.toml index ba0f255f..c8b7cfbd 100644 --- a/examples/sqlite_remember_bot/Cargo.toml +++ b/examples/sqlite_remember_bot/Cargo.toml @@ -13,6 +13,4 @@ pretty_env_logger = "0.4.0" tokio = { version = "1.3.0", features = ["rt-multi-thread", "macros"] } serde = "1.0.104" -futures = "0.3.5" - thiserror = "1.0.15" diff --git a/examples/sqlite_remember_bot/src/main.rs b/examples/sqlite_remember_bot/src/main.rs index 7d50cd7f..755ed828 100644 --- a/examples/sqlite_remember_bot/src/main.rs +++ b/examples/sqlite_remember_bot/src/main.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use teloxide::{ dispatching2::dialogue::{serializer::Json, SqliteStorage, Storage}, - prelude::*, + prelude2::*, RequestError, }; use thiserror::Error; diff --git a/src/dispatching/mod.rs b/src/dispatching/mod.rs index dc2a2306..f9c09a6b 100644 --- a/src/dispatching/mod.rs +++ b/src/dispatching/mod.rs @@ -49,7 +49,6 @@ pub mod dialogue; pub mod stop_token; pub mod update_listeners; -#[cfg(feature = "old-dispatching")] pub(crate) mod repls; mod dispatcher; @@ -63,7 +62,7 @@ pub use dispatcher_handler_rx_ext::DispatcherHandlerRxExt; use tokio::sync::mpsc::UnboundedReceiver; pub use update_with_cx::{UpdateWithCx, UpdateWithCxRequesterType}; -#[cfg(feature = "new-dispatching")] +#[cfg(feature = "dispatching2")] pub(crate) use dispatcher::{ shutdown_check_timeout_for, shutdown_inner, DispatcherState, ShutdownState, }; diff --git a/src/dispatching2/mod.rs b/src/dispatching2/mod.rs index 9daeb26c..24fd6ef6 100644 --- a/src/dispatching2/mod.rs +++ b/src/dispatching2/mod.rs @@ -1,4 +1,4 @@ -pub(crate) mod repls; +pub mod repls; pub mod dialogue; mod dispatcher; diff --git a/src/lib.rs b/src/lib.rs index 643544b9..16ca7817 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,28 +60,26 @@ // https://github.com/rust-lang/rust-clippy/issues/7422 #![allow(clippy::nonstandard_macro_braces)] -#[cfg(all(feature = "new-dispatching", feature = "old-dispatching"))] -compile_error!("You can use only one of еру dispatching systems, not both."); - -#[cfg(feature = "old-dispatching")] pub use dispatching::repls::{ commands_repl, commands_repl_with_listener, dialogues_repl, dialogues_repl_with_listener, repl, repl_with_listener, }; -#[cfg(feature = "new-dispatching")] -pub use dispatching2::repls::{ - commands_repl, commands_repl_with_listener, repl, repl_with_listener, -}; +#[cfg(feature = "dispatching2")] +pub use dispatching2::repls as repls2; mod logging; // Things from this module is also used for the dispatching2 module. pub mod dispatching; -#[cfg(feature = "new-dispatching")] +#[cfg(feature = "dispatching2")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "dispatching2")))] pub mod dispatching2; pub mod error_handlers; pub mod prelude; +#[cfg(feature = "dispatching2")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "dispatching2")))] +pub mod prelude2; pub mod utils; #[doc(inline)] @@ -91,8 +89,8 @@ pub use teloxide_core::*; #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] pub use teloxide_macros as macros; -#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "new-dispatching")))] -#[cfg(feature = "new-dispatching")] +#[cfg(feature = "dispatching2")] +#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "dispatching2")))] pub use dptree; #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] #[cfg(feature = "macros")] diff --git a/src/prelude.rs b/src/prelude.rs index 52569c79..719881cc 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,7 +5,6 @@ pub use crate::{ respond, }; -#[cfg(feature = "old-dispatching")] pub use crate::dispatching::{ dialogue::{ exit, next, DialogueDispatcher, DialogueStage, DialogueWithCx, GetChatId, Transition, @@ -14,12 +13,6 @@ pub use crate::dispatching::{ Dispatcher, DispatcherHandlerRx, DispatcherHandlerRxExt, UpdateWithCx, }; -#[cfg(feature = "new-dispatching")] -pub use crate::dispatching2::{ - dialogue::{Dialogue, DialogueHandlerExt as _}, - Dispatcher, HandlerExt as _, -}; - #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))] #[cfg(feature = "macros")] pub use crate::teloxide; @@ -42,5 +35,3 @@ pub use crate::utils::UpState; pub use tokio::sync::mpsc::UnboundedReceiver; pub use futures::StreamExt; - -pub use dptree::{self, prelude::*}; diff --git a/src/prelude2.rs b/src/prelude2.rs new file mode 100644 index 00000000..28065453 --- /dev/null +++ b/src/prelude2.rs @@ -0,0 +1,28 @@ +//! Commonly used items (dispatching2 version). + +pub use crate::{ + error_handlers::{LoggingErrorHandler, OnError}, + respond, +}; + +pub use crate::dispatching2::{ + dialogue::{Dialogue, DialogueHandlerExt as _}, + Dispatcher, HandlerExt as _, +}; + +#[cfg_attr(all(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(no_inline)] +pub use teloxide_core::prelude::*; + +pub use dptree::{self, prelude::*};