remove old_dispatching feature, add prelude2 and repls2 modules

This commit is contained in:
p0lunin 2022-01-06 14:50:59 +02:00
parent a8098350fc
commit d7386a7dc1
20 changed files with 56 additions and 52 deletions

View file

@ -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"]

View file

@ -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;
}

View file

@ -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

View file

@ -16,7 +16,7 @@
use teloxide::{
dispatching2::dialogue::{serializer::Json, SqliteStorage},
macros::DialogueState,
prelude::*,
prelude2::*,
};
// FIXME: naming

View file

@ -1,6 +1,6 @@
// This bot throws a dice on each incoming message.
use teloxide::prelude::*;
use teloxide::prelude2::*;
type TeleBot = AutoSend<Bot>;
@ -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(())
})

View file

@ -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<Bot>| async move {
bot.send_message(mes.chat.id, "pong").await?;

View file

@ -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"

View file

@ -1,5 +1,5 @@
use teloxide::{
prelude::*,
prelude2::*,
types::{
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
},

View file

@ -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<Bot>| async move {
bot.send_message(mes.chat.id, "pong").await?;

View file

@ -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"

View file

@ -1,6 +1,6 @@
use teloxide::{
dispatching2::dialogue::{serializer::Bincode, RedisStorage, Storage},
prelude::*,
prelude2::*,
RequestError,
};
use thiserror::Error;

View file

@ -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);

View file

@ -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;
}

View file

@ -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"

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use teloxide::{
dispatching2::dialogue::{serializer::Json, SqliteStorage, Storage},
prelude::*,
prelude2::*,
RequestError,
};
use thiserror::Error;

View file

@ -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,
};

View file

@ -1,4 +1,4 @@
pub(crate) mod repls;
pub mod repls;
pub mod dialogue;
mod dispatcher;

View file

@ -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")]

View file

@ -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::*};

28
src/prelude2.rs Normal file
View file

@ -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::*};