Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ redis-macros = { version = "0.5.6" }
url = "2.5.4"
base64 = "0.22.1"
mime = "0.3.17"
md5 = "0.7.0"
md5 = "0.7.0"
futures = "0.3.31"
34 changes: 19 additions & 15 deletions src/bot/callbacks/cobalt_pagination.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::bot::keyboards::cobalt::make_photo_pagination_keyboard;
use crate::bot::inlines::cobalter::DownloadResult;
use crate::core::config::Config;
use crate::errors::MyError;
use crate::{
bot::keyboards::cobalt::make_photo_pagination_keyboard,
core::{config::Config, services::cobalt::DownloadResult},
errors::MyError,
};
use std::sync::Arc;
use teloxide::prelude::*;
use teloxide::types::{CallbackQuery, InputFile, InputMedia, InputMediaPhoto};
use teloxide::{ApiError, RequestError};
use teloxide::{
ApiError, RequestError,
prelude::*,
types::{CallbackQuery, InputFile, InputMedia, InputMediaPhoto},
};

struct PagingData<'a> {
original_user_id: u64,
Expand All @@ -19,6 +22,7 @@ impl<'a> PagingData<'a> {
if parts.len() < 5 {
return None;
}

Some(Self {
original_user_id: parts.get(1)?.parse().ok()?,
index: parts.get(2)?.parse().ok()?,
Expand All @@ -42,7 +46,7 @@ pub async fn handle_cobalt_pagination(
}

let Some(paging_data) = PagingData::from_parts(&parts) else {
log::warn!("Invalid callback data format: {}", data);
log::error!("Invalid callback data format: {}", data);
return Ok(());
};

Expand Down Expand Up @@ -101,13 +105,13 @@ pub async fn handle_cobalt_pagination(
return Ok(());
};

if let Err(e) = edit_result {
if !matches!(e, RequestError::Api(ApiError::MessageNotModified)) {
log::error!("Failed to edit message for pagination: {}", e);
bot.answer_callback_query(q.id.clone())
.text("Не удалось обновить фото.")
.await?;
}
if let Err(e) = edit_result
&& !matches!(e, RequestError::Api(ApiError::MessageNotModified))
{
log::error!("Failed to edit message for pagination: {}", e);
bot.answer_callback_query(q.id.clone())
.text("Не удалось обновить фото.")
.await?;
}

bot.answer_callback_query(q.id).await?;
Expand Down
62 changes: 37 additions & 25 deletions src/bot/callbacks/delete.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::bot::callbacks::transcription::back_handler;
use crate::bot::keyboards::delete::confirm_delete_keyboard;
use crate::core::config::Config;
use crate::errors::MyError;
use crate::{
bot::keyboards::delete::confirm_delete_keyboard,
core::{config::Config, services::speech_recognition::back_handler},
errors::MyError,
};
use log::error;
use teloxide::prelude::*;
use teloxide::types::{ChatId, User};
use teloxide::{
prelude::*,
types::{ChatId, User},
};

async fn has_delete_permission(
bot: &Bot,
Expand All @@ -13,23 +16,24 @@ async fn has_delete_permission(
clicker: &User,
target_user_id: u64,
) -> bool {
if target_user_id == 72 {
if target_user_id == 72 || clicker.id.0 == target_user_id {
return true;
}
if clicker.id.0 == target_user_id {
return true;
}
if is_group {
if let Ok(member) = bot.get_chat_member(chat_id, clicker.id).await {
return member.is_privileged();
}

if is_group && let Ok(member) = bot.get_chat_member(chat_id, clicker.id).await {
return member.is_privileged();
}

false
}

pub async fn handle_delete_request(bot: Bot, query: CallbackQuery) -> Result<(), MyError> {
let Some(message) = query.message.as_ref().and_then(|m| m.regular_message()) else { return Ok(()) };
let Some(data) = query.data.as_ref() else { return Ok(()) };
let Some(message) = query.message.as_ref().and_then(|m| m.regular_message()) else {
return Ok(());
};
let Some(data) = query.data.as_ref() else {
return Ok(());
};

let target_user_id_str = data.strip_prefix("delete_msg:").unwrap_or_default();
let Ok(target_user_id) = target_user_id_str.parse::<u64>() else {
Expand All @@ -47,7 +51,7 @@ pub async fn handle_delete_request(bot: Bot, query: CallbackQuery) -> Result<(),
&query.from,
target_user_id,
)
.await;
.await;

if !can_delete {
bot.answer_callback_query(query.id)
Expand All @@ -63,8 +67,8 @@ pub async fn handle_delete_request(bot: Bot, query: CallbackQuery) -> Result<(),
message.id,
"Вы уверены, что хотите удалить?",
)
.reply_markup(confirm_delete_keyboard(target_user_id))
.await?;
.reply_markup(confirm_delete_keyboard(target_user_id))
.await?;

Ok(())
}
Expand All @@ -74,13 +78,21 @@ pub async fn handle_delete_confirmation(
query: CallbackQuery,
config: &Config,
) -> Result<(), MyError> {
let Some(message) = query.message.as_ref().and_then(|m| m.regular_message()) else { return Ok(()) };
let Some(data) = query.data.as_ref() else { return Ok(()) };
let Some(message) = query.message.as_ref().and_then(|m| m.regular_message()) else {
return Ok(());
};
let Some(data) = query.data.as_ref() else {
return Ok(());
};

let parts: Vec<&str> = data.split(':').collect();
if parts.len() != 3 { return Ok(()) };
if parts.len() != 3 {
return Ok(());
};

let Ok(target_user_id) = parts[1].parse::<u64>() else { return Ok(()) };
let Ok(target_user_id) = parts[1].parse::<u64>() else {
return Ok(());
};
let action = parts[2];

let can_delete = has_delete_permission(
Expand All @@ -90,7 +102,7 @@ pub async fn handle_delete_confirmation(
&query.from,
target_user_id,
)
.await;
.await;

if !can_delete {
bot.answer_callback_query(query.id)
Expand All @@ -116,4 +128,4 @@ pub async fn handle_delete_confirmation(
}

Ok(())
}
}
Loading