clean code

This commit is contained in:
doryan04 2024-03-04 23:13:37 +04:00
parent 6d7024f7dd
commit 94fdb2fc80
4 changed files with 12 additions and 16 deletions

View File

@ -14,5 +14,3 @@ chrono = "0.4.34"
url = "2.5.0"
dotenv = "0.15.0"
[env]
BOT_TOKEN = "6941223962:AAG4SVKKlUOPlgJTINLfxtD09duB_YSkHOw"

View File

@ -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::<Commands, Result<(), Box<(dyn Error + Send + Sync + 'static)>>>()
.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()

View File

@ -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<dyn Error + Send + Sync>>;
pub type CommandHandleResult = Result<(), Box<dyn Error + Send + Sync>>;
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,

View File

@ -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;