From 5a7bb0e0f6d2e6ca4f09a37d2986922f9e60509d Mon Sep 17 00:00:00 2001 From: Akulij Date: Sat, 7 Jun 2025 01:50:30 +0500 Subject: [PATCH] clippy fix --- src/admin.rs | 9 +++------ src/bot_handler.rs | 13 ++++++------- src/bot_manager.rs | 16 ++++------------ src/botscript.rs | 12 +++++------- src/botscript/application.rs | 4 ++-- src/botscript/message_info.rs | 6 ++++++ src/db/bots.rs | 2 -- src/db/mod.rs | 2 +- src/db/tests/mod.rs | 2 +- src/handlers/admin.rs | 10 ++++------ src/utils.rs | 2 +- 11 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/admin.rs b/src/admin.rs index 0f954f2..8665c76 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -178,12 +178,9 @@ pub async fn admin_command_handler( } }; - let bi = - BotInstance::new(name.clone(), token.to_string(), DEFAULT_SCRIPT.to_string()) - .store(&mut db) - .await?; - - bi + BotInstance::new(name.clone(), token.to_string(), DEFAULT_SCRIPT.to_string()) + .store(&mut db) + .await? }; bot.send_message( diff --git a/src/bot_handler.rs b/src/bot_handler.rs index 14bf548..25d00fd 100644 --- a/src/bot_handler.rs +++ b/src/bot_handler.rs @@ -1,21 +1,21 @@ use futures::future::join_all; use log::{error, info}; -use quickjs_rusty::serde::{from_js, to_js}; +use quickjs_rusty::serde::to_js; use serde_json::Value; use std::{ str::FromStr, - sync::{Arc, Mutex, RwLock}, + sync::{Arc, Mutex}, }; use teloxide::{ dispatching::{dialogue::GetChatId, UpdateFilterExt}, dptree::{self, Handler}, prelude::{DependencyMap, Requester}, - types::{CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, Update}, + types::{CallbackQuery, InlineKeyboardMarkup, Message, Update}, Bot, }; use crate::{ - botscript::{self, message_info::MessageInfoBuilder, BotMessage, RunnerConfig}, + botscript::{self, message_info::MessageInfoBuilder, BotMessage}, commands::BotCommand, db::{callback_info::CallbackInfo, CallDB, DB}, message_answerer::MessageAnswerer, @@ -108,7 +108,7 @@ async fn handle_botmessage(bot: Bot, mut db: DB, bm: BotMessage, msg: Message) - Err(_) => None, }; - if bm.meta() == true { + if bm.meta() { if let Some(ref meta) = variant { user.insert_meta(&mut db, meta).await?; }; @@ -193,8 +193,7 @@ async fn handle_botmessage(bot: Bot, mut db: DB, bm: BotMessage, msg: Message) - let literal = bm.literal().map_or("", |s| s.as_str()); let ma = MessageAnswerer::new(&bot, &mut db, msg.chat.id.0); - ma.answer(literal, variant.as_ref().map(|v| v.as_str()), buttons) - .await?; + ma.answer(literal, variant.as_deref(), buttons).await?; Ok(()) } diff --git a/src/bot_manager.rs b/src/bot_manager.rs index af45b65..665c463 100644 --- a/src/bot_manager.rs +++ b/src/bot_manager.rs @@ -1,28 +1,20 @@ use std::{ collections::HashMap, future::Future, - sync::{Arc, Mutex, RwLock}, + sync::{Arc, Mutex}, thread::JoinHandle, time::Duration, }; -use lazy_static::lazy_static; use log::{error, info}; -use teloxide::{ - dispatching::dialogue::serializer::Json, - dptree, - prelude::{Dispatcher, Requester}, - types::{ChatId, UserId}, - Bot, -}; -use tokio::runtime::Handle; +use teloxide::{dispatching::dialogue::serializer::Json, dptree, prelude::Dispatcher, Bot}; use crate::{ bot_handler::{script_handler, BotHandler}, db::{bots::BotInstance, DbError, DB}, message_answerer::MessageAnswerer, mongodb_storage::MongodbStorage, - BotController, BotError, BotResult, BotRuntime, + BotController, BotResult, BotRuntime, }; pub struct BotRunner { @@ -235,7 +227,7 @@ pub async fn spawn_notificator_thread( Some(n) => { // waiting time to send notification tokio::time::sleep(n.wait_for()).await; - 'n: for n in n.notifications().into_iter() { + 'n: for n in n.notifications().iter() { for user in n.get_users(&c.db).await?.into_iter() { let text = match n.resolve_message(&c.db, &user).await? { Some(text) => text, diff --git a/src/botscript.rs b/src/botscript.rs index d4c384f..999fb41 100644 --- a/src/botscript.rs +++ b/src/botscript.rs @@ -2,7 +2,7 @@ pub mod application; pub mod db; pub mod message_info; use std::collections::HashMap; -use std::sync::{Arc, Mutex, PoisonError}; +use std::sync::{Arc, Mutex}; use std::time::Duration; use crate::db::raw_calls::RawCallError; @@ -12,7 +12,6 @@ use crate::utils::parcelable::{ParcelType, Parcelable, ParcelableError, Parcelab use chrono::{DateTime, Days, NaiveTime, ParseError, TimeDelta, Timelike, Utc}; use db::attach_db_obj; use futures::future::join_all; -use futures::lock::MutexGuard; use itertools::Itertools; use quickjs_rusty::serde::{from_js, to_js}; use quickjs_rusty::utils::create_empty_object; @@ -543,7 +542,8 @@ impl BotMessage { pub fn update_defaults(self) -> Self { let bm = self; // if message is `start`, defaulting meta to true, if not set - let bm = match bm.meta { + + match bm.meta { Some(_) => bm, None => match &bm.literal { Some(l) if l == "start" => Self { @@ -552,9 +552,7 @@ impl BotMessage { }, _ => bm, }, - }; - - bm + } } pub fn is_replace(&self) -> bool { @@ -1062,7 +1060,7 @@ impl Runner { #[allow(clippy::unwrap_used)] #[allow(clippy::print_stdout)] mod tests { - use quickjs_rusty::{serde::from_js, OwnedJsObject}; + use quickjs_rusty::OwnedJsObject; use serde_json::json; use super::*; diff --git a/src/botscript/application.rs b/src/botscript/application.rs index af2b00a..3b397bd 100644 --- a/src/botscript/application.rs +++ b/src/botscript/application.rs @@ -6,9 +6,9 @@ use teloxide::Bot; use tokio::runtime::Handle; use crate::{ - db::{application::Application, message_forward::MessageForward, CallDB, DB}, + db::{application::Application, message_forward::MessageForward, DB}, message_answerer::MessageAnswerer, - send_application_to_chat, BotError, + send_application_to_chat, }; use super::ScriptError; diff --git a/src/botscript/message_info.rs b/src/botscript/message_info.rs index 36dcdd9..1b6a513 100644 --- a/src/botscript/message_info.rs +++ b/src/botscript/message_info.rs @@ -9,6 +9,12 @@ pub struct MessageInfoBuilder { inner: MessageInfo, } +impl Default for MessageInfoBuilder { + fn default() -> Self { + Self::new() + } +} + impl MessageInfoBuilder { pub fn new() -> Self { Self { diff --git a/src/db/bots.rs b/src/db/bots.rs index cd412ae..fc9a632 100644 --- a/src/db/bots.rs +++ b/src/db/bots.rs @@ -1,7 +1,5 @@ use bson::doc; -use bson::oid::ObjectId; use chrono::{DateTime, FixedOffset, Local}; -use futures::StreamExt; use futures::TryStreamExt; use serde::{Deserialize, Serialize}; diff --git a/src/db/mod.rs b/src/db/mod.rs index df2f41e..01b1882 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -7,7 +7,7 @@ pub mod raw_calls; use std::time::Duration; use async_trait::async_trait; -use chrono::{DateTime, FixedOffset, Local, Utc}; +use chrono::{DateTime, Local, Utc}; use enum_stringify::EnumStringify; use futures::stream::TryStreamExt; diff --git a/src/db/tests/mod.rs b/src/db/tests/mod.rs index 5dbc6bc..6ddaa7c 100644 --- a/src/db/tests/mod.rs +++ b/src/db/tests/mod.rs @@ -177,7 +177,7 @@ async fn test_drop_media_except() { #[tokio::test] async fn test_get_random_users() { - let mut db = setup_db().await; + let db = setup_db().await; let users = db.get_random_users(1).await.unwrap(); assert_eq!(users.len(), 1); diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index 7b74aec..d0b419f 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use itertools::Itertools; use log::{info, warn}; use std::time::Duration; @@ -108,15 +106,15 @@ async fn newscript_handler(bot: Bot, mut db: DB, msg: Message, name: String) -> let mut bytes = bytes.unwrap().to_vec(); buf.append(&mut bytes); } - let script = match String::from_utf8(buf) { + + match String::from_utf8(buf) { Ok(s) => s, Err(err) => { warn!("Failed to parse buf to string, err: {err}"); bot.send_message(msg.chat.id, format!("Failed to Convert file to script: file is not UTF-8, err: {err}")).await?; return Ok(()); } - }; - script + } } _ => todo!(), } @@ -129,7 +127,7 @@ async fn newscript_handler(bot: Bot, mut db: DB, msg: Message, name: String) -> None => { bot.send_message( msg.chat.id, - format!("Failed to set script, possibly bots name is incorrent"), + "Failed to set script, possibly bots name is incorrent".to_string(), ) .await?; return Ok(()); diff --git a/src/utils.rs b/src/utils.rs index a97e94c..bf02c8e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -85,7 +85,7 @@ where #[cfg(test)] mod tests { - use super::*; + use teloxide::types::InlineKeyboardButton; use teloxide::types::InlineKeyboardMarkup;