From 94fdb2fc80591ca08fb58107202aeb3731057ebd Mon Sep 17 00:00:00 2001 From: doryan04 Date: Mon, 4 Mar 2024 23:13:37 +0400 Subject: [PATCH] clean code --- Cargo.toml | 2 -- src/handlers/main_handler.rs | 11 +++++------ src/handlers/main_handler_endpoints.rs | 13 +++++++------ src/main.rs | 2 -- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 24d8baf..10e3cdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,3 @@ chrono = "0.4.34" url = "2.5.0" dotenv = "0.15.0" -[env] -BOT_TOKEN = "6941223962:AAG4SVKKlUOPlgJTINLfxtD09duB_YSkHOw" diff --git a/src/handlers/main_handler.rs b/src/handlers/main_handler.rs index f843c58..204d935 100644 --- a/src/handlers/main_handler.rs +++ b/src/handlers/main_handler.rs @@ -1,5 +1,5 @@ +use std::{error::Error}; use teloxide::{Bot, types::Message}; -use std::{future::Future, error::Error}; #[path="../enums/commands.rs"] mod commands; @@ -10,22 +10,21 @@ use main_handler_endpoints::main_handler_endpoints::*; pub mod main_handler{ - use std::error::Error; use super::{*, commands::enum_commands::Commands}; use teloxide::{dptree::case, filter_command, types::Update, dispatching::{Dispatcher, UpdateFilterExt}}; pub async fn main_handler_spawn(bot: Bot) -> () { let command_handler = filter_command::>>() - .branch(case![Commands::Facker].endpoint(facker)) + .branch(case![Commands::Facker].endpoint(facker_endpoint)) .branch( case![Commands::DemocracyMute(multiplier, time_type)] .endpoint(|bot : Bot, msg : Message, args : (i32, String)| async move { - democracy_mute(bot, msg, args.0, args.1).await + mute_endpoint(bot, msg, args.0, args.1).await })) - .branch(case![Commands::DemocracyUnmute].endpoint(democracy_unmute)) + .branch(case![Commands::DemocracyUnmute].endpoint(unmute_endpoint)) .branch(case![Commands::Tribunal(reason)] .endpoint(|bot : Bot, msg : Message, args| async move { - tribunal(bot, msg, args).await + tribunal_endpoint(bot, msg, args).await })); let message_handler = Update::filter_message() diff --git a/src/handlers/main_handler_endpoints.rs b/src/handlers/main_handler_endpoints.rs index 102fe3f..a40c964 100644 --- a/src/handlers/main_handler_endpoints.rs +++ b/src/handlers/main_handler_endpoints.rs @@ -1,5 +1,5 @@ +use std::{error::Error}; use teloxide::{Bot, types::Message}; -use std::{future::Future, error::Error}; #[path="../bot_functions/ban.rs"] mod ban; @@ -22,14 +22,14 @@ pub mod main_handler_endpoints { use super::decorators::decorators::admin_access; use teloxide::{requests::Requester, utils::command::BotCommands}; - pub(crate) type CommandHandleResult = Result<(), Box>; + pub type CommandHandleResult = Result<(), Box>; - pub(crate) async fn facker(bot : Bot, msg : Message) -> CommandHandleResult { + pub async fn facker_endpoint(bot : Bot, msg : Message) -> CommandHandleResult { bot.send_message(msg.chat.id, Commands::descriptions().to_string()).await?; Ok(()) } - pub(crate) async fn democracy_unmute(bot : Bot, msg : Message) -> CommandHandleResult { + pub async fn unmute_endpoint(bot : Bot, msg : Message) -> CommandHandleResult { admin_access(bot.clone(), msg.clone(), unmute( msg.clone().reply_to_message(), &bot, @@ -38,7 +38,7 @@ pub mod main_handler_endpoints { Ok(()) } - pub(crate) async fn democracy_mute( + pub async fn mute_endpoint( bot : Bot, msg : Message, multiplier : i32, @@ -70,8 +70,9 @@ pub mod main_handler_endpoints { Ok(()) } - pub(crate) async fn tribunal(bot : Bot, msg : Message, reason : String) -> CommandHandleResult { + pub async fn tribunal_endpoint(bot : Bot, msg : Message, reason : String) -> CommandHandleResult { let reason_result = if reason.is_empty() { None } else { Some(reason) }; + admin_access(bot.clone(), msg.clone(), ban_user( msg.reply_to_message(), reason_result, diff --git a/src/main.rs b/src/main.rs index 5ae25af..ab3c579 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ use std::env; use dotenv::dotenv; -use std::error::Error; use teloxide::{prelude::*}; -use teloxide::error_handlers::ErrorHandler; #[path="handlers/main_handler.rs"] mod main_handler;