Remove the need for CacheMe in dispatcher

This commit is contained in:
Maybe Waffle 2022-04-05 17:18:37 +04:00
parent 140141f6fc
commit bb7a4729c0
2 changed files with 8 additions and 13 deletions

View file

@ -12,8 +12,7 @@ license = "MIT"
exclude = ["media"] exclude = ["media"]
[features] [features]
# FIXME: remove "cache-me" that was added by mistake here default = ["native-tls", "ctrlc_handler", "teloxide-core/default", "auto-send"]
default = ["native-tls", "ctrlc_handler", "teloxide-core/default", "auto-send", "cache-me"]
sqlite-storage = ["sqlx"] sqlite-storage = ["sqlx"]
redis-storage = ["redis"] redis-storage = ["redis"]

View file

@ -1,5 +1,4 @@
use crate::{ use crate::{
adaptors::CacheMe,
dispatching::{ dispatching::{
stop_token::StopToken, update_listeners, update_listeners::UpdateListener, ShutdownToken, stop_token::StopToken, update_listeners, update_listeners::UpdateListener, ShutdownToken,
}, },
@ -8,13 +7,11 @@ use crate::{
types::{AllowedUpdate, Update}, types::{AllowedUpdate, Update},
utils::shutdown_token::shutdown_check_timeout_for, utils::shutdown_token::shutdown_check_timeout_for,
}; };
use dptree::di::{DependencyMap, DependencySupplier}; use dptree::di::{DependencyMap, DependencySupplier};
use futures::{future::BoxFuture, StreamExt}; use futures::{future::BoxFuture, StreamExt};
use std::{collections::HashSet, fmt::Debug, ops::ControlFlow, sync::Arc}; use std::{collections::HashSet, fmt::Debug, ops::ControlFlow, sync::Arc};
use teloxide_core::{ use teloxide_core::{requests::Request, types::UpdateKind};
requests::{Request, RequesterExt},
types::UpdateKind,
};
use tokio::time::timeout; use tokio::time::timeout;
use std::future::Future; use std::future::Future;
@ -74,7 +71,6 @@ where
pub fn build(self) -> Dispatcher<R, Err> { pub fn build(self) -> Dispatcher<R, Err> {
Dispatcher { Dispatcher {
bot: self.bot.clone(), bot: self.bot.clone(),
cache_me_bot: self.bot.cache_me(),
dependencies: self.dependencies, dependencies: self.dependencies,
handler: self.handler, handler: self.handler,
default_handler: self.default_handler, default_handler: self.default_handler,
@ -88,7 +84,6 @@ where
/// The base for update dispatching. /// The base for update dispatching.
pub struct Dispatcher<R, Err> { pub struct Dispatcher<R, Err> {
bot: R, bot: R,
cache_me_bot: CacheMe<R>,
dependencies: DependencyMap, dependencies: DependencyMap,
handler: UpdateHandler<Err>, handler: UpdateHandler<Err>,
@ -175,6 +170,11 @@ where
Eh: ErrorHandler<ListenerE> + 'a, Eh: ErrorHandler<ListenerE> + 'a,
ListenerE: Debug, ListenerE: Debug,
{ {
// FIXME: there should be a way to check if dependency is already inserted
let me = self.bot.get_me().send().await.expect("Failed to retrieve 'me'");
self.dependencies.insert(me);
self.dependencies.insert(self.bot.clone());
update_listener.hint_allowed_updates(&mut self.allowed_updates.clone().into_iter()); update_listener.hint_allowed_updates(&mut self.allowed_updates.clone().into_iter());
let shutdown_check_timeout = shutdown_check_timeout_for(&update_listener); let shutdown_check_timeout = shutdown_check_timeout_for(&update_listener);
@ -232,10 +232,6 @@ where
let mut deps = self.dependencies.clone(); let mut deps = self.dependencies.clone();
deps.insert(upd); deps.insert(upd);
deps.insert(self.bot.clone());
deps.insert(
self.cache_me_bot.get_me().send().await.expect("Failed to retrieve 'me'"),
);
match self.handler.dispatch(deps).await { match self.handler.dispatch(deps).await {
ControlFlow::Break(Ok(())) => {} ControlFlow::Break(Ok(())) => {}