From 3132ebd03672b9f79c9a87dfbe39801e1b99b5df Mon Sep 17 00:00:00 2001 From: shiroyashik Date: Tue, 28 Jan 2025 21:30:25 +0300 Subject: [PATCH 1/2] fix i32 uid in check_rights --- src/handle/add.rs | 5 +++-- src/main.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/handle/add.rs b/src/handle/add.rs index 062727b..7ec99d7 100644 --- a/src/handle/add.rs +++ b/src/handle/add.rs @@ -10,7 +10,7 @@ use crate::{check_subscription, markup, notify, AppState, DialogueState, MyDialo pub async fn message(bot: Bot, msg: Message, dialogue: MyDialogue) -> anyhow::Result<()> { use youtube::*; if let Some(text) = msg.clone().text() { - if let Some(user) = check_subscription(&bot, &msg.from.ok_or(anyhow::anyhow!("Message not from user!"))?.id).await { + if let Some(user) = check_subscription(&bot, &msg.clone().from.ok_or(anyhow::anyhow!("Message not from user!"))?.id).await { // Get ready! if let Some(ytid) = extract_youtube_video_id(text) { let meta = get_video_metadata(&ytid).await?; @@ -21,7 +21,8 @@ pub async fn message(bot: Bot, msg: Message, dialogue: MyDialogue) -> anyhow::Re )).parse_mode(ParseMode::Html).reply_markup(markup::inline_yes_or_no()).await?; dialogue.update(DialogueState::AcceptVideo { ytid, uid: user.id.0, title: meta.title }).await?; } else { - bot.send_message(msg.chat.id, "Это не похоже на YouTube видео... Долбоёб").await?; + tracing::debug!("Not a YouTube video: {:?}", msg); + bot.send_message(msg.chat.id, "Это не похоже на YouTube видео... Долбоёб").await?; } } else { let link = if let Some(hash) = CHANNEL_INVITE_HASH.as_ref() { diff --git a/src/main.rs b/src/main.rs index a4be837..a4e6231 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ async fn main() -> anyhow::Result<()> { // Pass the shared state to the handler as a dependency. .dependencies(dptree::deps![state, InMemStorage::::new()]) .default_handler(|upd| async move { - tracing::warn!("Unhandled update: {:?}", upd); + tracing::debug!("Unhandled update: {:?}", upd); }) .enable_ctrlc_handler() .build() @@ -184,7 +184,7 @@ impl AppState { async fn check_rights(&self, uid: &UserId) -> anyhow::Result { use database::moderators::Entity as Moderators; - Ok(if let Some(moder) = Moderators::find_by_id(uid.0 as i32).one(&self.db).await? { + Ok(if let Some(moder) = Moderators::find_by_id(uid.0 as i64).one(&self.db).await? { Rights::Moderator { can_add_mods: moder.can_add_mods } } else { Rights::None From 655e195c91342623e3edd5476c13a022b1f70324 Mon Sep 17 00:00:00 2001 From: shiroyashik Date: Tue, 28 Jan 2025 21:46:03 +0300 Subject: [PATCH 2/2] f*cking i am! f*cking i32! --- src/handle/moderator/remove.rs | 2 +- src/handle/notify.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handle/moderator/remove.rs b/src/handle/moderator/remove.rs index 49dcfb3..b1cecf8 100644 --- a/src/handle/moderator/remove.rs +++ b/src/handle/moderator/remove.rs @@ -29,7 +29,7 @@ pub async fn inline(bot: Bot, q: CallbackQuery, state: Arc, uid: Strin if let Some(data) = q.clone().data { let text= if &data == "yes" { if let Ok(uid) = uid.parse::() { - if Entity::delete_by_id(uid as i32).exec(&state.db).await?.rows_affected != 0 { + if Entity::delete_by_id(uid as i64).exec(&state.db).await?.rows_affected != 0 { "Модератор удалён!" } else { "Произошла ошибка!\nПо всей видимости такого модератора не существует." diff --git a/src/handle/notify.rs b/src/handle/notify.rs index 00cedc0..564e196 100644 --- a/src/handle/notify.rs +++ b/src/handle/notify.rs @@ -8,7 +8,7 @@ use crate::AppState; /// Invert notify status for moderator pub async fn command(bot: Bot, msg: Message, uid: UserId, state: Arc) -> anyhow::Result<()> { - let text = if let Some(moder) = moderators::Entity::find_by_id(uid.0 as i32).one(&state.db).await? { + let text = if let Some(moder) = moderators::Entity::find_by_id(uid.0 as i64).one(&state.db).await? { let moder = match moder.notify { true => { let mut moder = moder.into_active_model();