fix: prevent moving `Message` in `BotExt`

This commit is contained in:
Harsh Shandilya 2024-04-29 06:32:42 +05:30
parent dc6b8db163
commit 1ebdccff4a
7 changed files with 19 additions and 19 deletions

View File

@ -86,11 +86,11 @@ pub(crate) async fn handler(
) -> Result<(), AsyncError> {
match command {
Command::Help | Command::Start => {
bot.send_chat_message(message, Command::descriptions().to_string())
bot.send_chat_message(&message, Command::descriptions().to_string())
.await?;
}
Command::Ping => {
bot.send_chat_message(message, "Pong".to_string()).await?;
bot.send_chat_message(&message, "Pong".to_string()).await?;
}
#[cfg(feature = "ddinstagram")]
Command::Instagram { filter_state } => {
@ -100,13 +100,13 @@ pub(crate) async fn handler(
update_fixer_state(&message, |x| x.instagram(filter_state));
let state = if filter_state { "enabled" } else { "disabled" };
bot.send_chat_message(
message,
&message,
format!("Instagram link replacement is now {}", state),
)
.await?;
}
Err(error_message) => {
bot.send_chat_message(message, error_message).await?;
bot.send_chat_message(&message, error_message).await?;
}
}
} else {
@ -124,13 +124,13 @@ pub(crate) async fn handler(
update_fixer_state(&message, |x| x.medium(filter_state));
let state = if filter_state { "enabled" } else { "disabled" };
bot.send_chat_message(
message,
&message,
format!("Medium link replacement is now {}", state),
)
.await?;
}
Err(error_message) => {
bot.send_chat_message(message, error_message).await?;
bot.send_chat_message(&message, error_message).await?;
}
}
} else {
@ -154,13 +154,13 @@ pub(crate) async fn handler(
update_fixer_state(&message, |x| x.twitter(filter_state));
let state = if filter_state { "enabled" } else { "disabled" };
bot.send_chat_message(
message,
&message,
format!("Twitter link replacement is now {}", state),
)
.await?;
}
Err(error_message) => {
bot.send_chat_message(message, error_message).await?;
bot.send_chat_message(&message, error_message).await?;
}
}
} else {
@ -178,13 +178,13 @@ pub(crate) async fn handler(
update_fixer_state(&message, |x| x.youtube(filter_state));
let state = if filter_state { "enabled" } else { "disabled" };
bot.send_chat_message(
message,
&message,
format!("YouTube link replacement is now {}", state),
)
.await?;
}
Err(error_message) => {
bot.send_chat_message(message, error_message).await?;
bot.send_chat_message(&message, error_message).await?;
}
}
} else {

View File

@ -38,7 +38,7 @@ pub async fn handler(bot: Bot, message: Message) -> Result<(), AsyncError> {
}
let text = format!("{}: {}", link(user.url().as_str(), &user.full_name()), text);
let _del = bot.delete_message(message.chat.id, message.id).await;
bot.try_reply(message, text).await?;
bot.try_reply(&message, text).await?;
}
Ok(())
}

View File

@ -20,7 +20,7 @@ pub async fn handler(bot: Bot, message: Message) -> Result<(), AsyncError> {
let text = text.replace(&caps[HOST_MATCH_GROUP], "ddinstagram.com");
let text = format!("{}: {}", link(user.url().as_str(), &user.full_name()), text);
let _del = bot.delete_message(message.chat.id, message.id).await;
bot.try_reply(message, text).await?;
bot.try_reply(&message, text).await?;
}
Ok(())
}

View File

@ -19,7 +19,7 @@ pub async fn handler(bot: Bot, message: Message) -> Result<(), AsyncError> {
let text = text.replace(&caps[HOST_MATCH_GROUP], "medium.rip");
let text = format!("{}: {}", link(user.url().as_str(), &user.full_name()), text);
let _del = bot.delete_message(message.chat.id, message.id).await;
bot.try_reply(message, text).await?;
bot.try_reply(&message, text).await?;
}
Ok(())
}

View File

@ -6,16 +6,16 @@ use teloxide::{
};
pub(crate) trait BotExt {
async fn try_reply(&self, message: Message, text: String) -> Result<Message, RequestError>;
async fn try_reply(&self, message: &Message, text: String) -> Result<Message, RequestError>;
async fn send_chat_message(
&self,
message: Message,
message: &Message,
text: String,
) -> Result<Message, RequestError>;
}
impl BotExt for Bot {
async fn try_reply(&self, message: Message, text: String) -> Result<Message, RequestError> {
async fn try_reply(&self, message: &Message, text: String) -> Result<Message, RequestError> {
if let Some(reply) = message.reply_to_message() {
self.send_message(message.chat.id, text)
.reply_to_message_id(reply.id)
@ -30,7 +30,7 @@ impl BotExt for Bot {
async fn send_chat_message(
&self,
message: Message,
message: &Message,
text: String,
) -> Result<Message, RequestError> {
self.send_chat_action(message.chat.id, ChatAction::Typing)

View File

@ -29,7 +29,7 @@ pub async fn handler(bot: Bot, message: Message) -> Result<(), AsyncError> {
};
let text = format!("{}: {}", link(user.url().as_str(), &user.full_name()), text);
let _del = bot.delete_message(message.chat.id, message.id).await;
bot.try_reply(message, text).await?;
bot.try_reply(&message, text).await?;
}
Ok(())
}

View File

@ -18,7 +18,7 @@ pub async fn handler(bot: Bot, message: Message) -> Result<(), AsyncError> {
let text = text.replace(&caps["shorts"], "watch?v=");
let text = format!("{}: {}", link(user.url().as_str(), &user.full_name()), text);
let _del = bot.delete_message(message.chat.id, message.id).await;
bot.try_reply(message, text).await?;
bot.try_reply(&message, text).await?;
}
Ok(())
}