mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
fix clippy errors
This commit is contained in:
parent
d7386a7dc1
commit
7615fc1392
7 changed files with 44 additions and 27 deletions
|
@ -107,6 +107,7 @@ where
|
|||
/// [`shutdown`]: ShutdownToken::shutdown
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "ctrlc_handler")))]
|
||||
#[must_use]
|
||||
pub fn setup_ctrlc_handler(self) -> Self {
|
||||
let state = Arc::clone(&self.state);
|
||||
tokio::spawn(async move {
|
||||
|
|
|
@ -3,6 +3,7 @@ use dptree::{di::DependencyMap, Handler};
|
|||
use std::sync::Arc;
|
||||
|
||||
pub trait DialogueHandlerExt {
|
||||
#[must_use]
|
||||
fn add_dialogue<Upd, S, D>(self) -> Self
|
||||
where
|
||||
S: Storage<D> + Send + Sync + 'static,
|
||||
|
|
|
@ -28,11 +28,7 @@ pub struct Dialogue<D, S> {
|
|||
// but `S` wrapped around Arc, and `D` wrapped around PhantomData.
|
||||
impl<D, S> Clone for Dialogue<D, S> {
|
||||
fn clone(&self) -> Self {
|
||||
Dialogue {
|
||||
storage: self.storage.clone(),
|
||||
chat_id: self.chat_id.clone(),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
Dialogue { storage: self.storage.clone(), chat_id: self.chat_id, _phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ where
|
|||
/// [`shutdown`]: ShutdownToken::shutdown
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "ctrlc_handler")))]
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn setup_ctrlc_handler(self) -> Self {
|
||||
let state = Arc::clone(&self.state);
|
||||
tokio::spawn(async move {
|
||||
|
@ -227,21 +228,25 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn handler(self, handler: UpdateHandler<Err>) -> Self {
|
||||
Dispatcher { handler: self.handler.branch(handler), ..self }
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
// Specify handler that will be called if other handlers was not handle the
|
||||
// update.
|
||||
pub fn default_handler(self, handler: UpdateHandler<Err>) -> Self {
|
||||
Dispatcher { handler: self.handler.branch(handler), ..self }
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
// Specify dependencies that can be used inside of handlers.
|
||||
pub fn dependencies(self, dependencies: DependencyMap) -> Self {
|
||||
Dispatcher { dependencies, ..self }
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn messages_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -253,6 +258,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn edited_messages_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -264,6 +270,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn channel_posts_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -275,6 +282,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn edited_channel_posts_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -286,6 +294,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn inline_queries_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -297,6 +306,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn chosen_inline_results_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -308,6 +318,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn callback_queries_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -319,6 +330,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn shipping_queries_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -330,6 +342,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn pre_checkout_queries_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -341,6 +354,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn polls_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -352,6 +366,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn poll_answers_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -363,6 +378,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn my_chat_members_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
@ -374,6 +390,7 @@ where
|
|||
self.handler(handler)
|
||||
}
|
||||
|
||||
#[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."]
|
||||
pub fn chat_members_handler(
|
||||
mut self,
|
||||
make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>,
|
||||
|
|
|
@ -2,10 +2,12 @@ use crate::{dispatching2::HandlerFactory, types::Message, utils::command::BotCom
|
|||
use dptree::{di::DependencyMap, Handler};
|
||||
|
||||
pub trait HandlerExt<Output> {
|
||||
#[must_use]
|
||||
fn add_command<C>(self, bot_name: String) -> Self
|
||||
where
|
||||
C: BotCommand + Send + Sync + 'static;
|
||||
|
||||
#[must_use]
|
||||
fn dispatch_by<F>(self) -> Self
|
||||
where
|
||||
F: HandlerFactory<Out = Output>;
|
||||
|
|
|
@ -61,7 +61,7 @@ pub fn code_block(code: &str) -> String {
|
|||
pub fn code_block_with_lang(code: &str, lang: &str) -> String {
|
||||
format!(
|
||||
"<pre><code class=\"language-{}\">{}</code></pre>",
|
||||
escape(lang).replace("\"", """),
|
||||
escape(lang).replace('"', """),
|
||||
escape(code)
|
||||
)
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ pub fn code_inline(s: &str) -> String {
|
|||
///
|
||||
/// [spec]: https://core.telegram.org/bots/api#html-style
|
||||
pub fn escape(s: &str) -> String {
|
||||
s.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
s.replace('&', "&").replace('<', "<").replace('>', ">")
|
||||
}
|
||||
|
||||
pub fn user_mention_or_link(user: &User) -> String {
|
||||
|
|
|
@ -89,36 +89,36 @@ pub fn code_inline(s: &str) -> String {
|
|||
///
|
||||
/// [spec]: https://core.telegram.org/bots/api#html-style
|
||||
pub fn escape(s: &str) -> String {
|
||||
s.replace("_", r"\_")
|
||||
.replace("*", r"\*")
|
||||
.replace("[", r"\[")
|
||||
.replace("]", r"\]")
|
||||
.replace("(", r"\(")
|
||||
.replace(")", r"\)")
|
||||
.replace("~", r"\~")
|
||||
.replace("`", r"\`")
|
||||
.replace(">", r"\>")
|
||||
.replace("#", r"\#")
|
||||
.replace("+", r"\+")
|
||||
.replace("-", r"\-")
|
||||
.replace("=", r"\=")
|
||||
.replace("|", r"\|")
|
||||
.replace("{", r"\{")
|
||||
.replace("}", r"\}")
|
||||
.replace(".", r"\.")
|
||||
.replace("!", r"\!")
|
||||
s.replace('_', r"\_")
|
||||
.replace('*', r"\*")
|
||||
.replace('[', r"\[")
|
||||
.replace(']', r"\]")
|
||||
.replace('(', r"\(")
|
||||
.replace(')', r"\)")
|
||||
.replace('~', r"\~")
|
||||
.replace('`', r"\`")
|
||||
.replace('>', r"\>")
|
||||
.replace('#', r"\#")
|
||||
.replace('+', r"\+")
|
||||
.replace('-', r"\-")
|
||||
.replace('=', r"\=")
|
||||
.replace('|', r"\|")
|
||||
.replace('{', r"\{")
|
||||
.replace('}', r"\}")
|
||||
.replace('.', r"\.")
|
||||
.replace('!', r"\!")
|
||||
}
|
||||
|
||||
/// Escapes all markdown special characters specific for the inline link URL
|
||||
/// (``` and `)`).
|
||||
pub fn escape_link_url(s: &str) -> String {
|
||||
s.replace("`", r"\`").replace(")", r"\)")
|
||||
s.replace('`', r"\`").replace(')', r"\)")
|
||||
}
|
||||
|
||||
/// Escapes all markdown special characters specific for the code block (``` and
|
||||
/// `\`).
|
||||
pub fn escape_code(s: &str) -> String {
|
||||
s.replace(r"\", r"\\").replace("`", r"\`")
|
||||
s.replace('\\', r"\\").replace('`', r"\`")
|
||||
}
|
||||
|
||||
pub fn user_mention_or_link(user: &User) -> String {
|
||||
|
|
Loading…
Add table
Reference in a new issue