gluon/src/main.rs

95 lines
2.5 KiB
Rust

use dotenvy::dotenv;
use telers::{
enums::ContentType,
event::ToServiceProvider,
filters::{content_type::ContentType as CT, Command},
Bot, Dispatcher, Router,
};
mod actions;
mod assets;
mod handlers;
mod middlewares;
mod types;
mod utils;
use middlewares::admin_check_middleware::AdminCheck;
use handlers::{
commands::{admin_commands::admin_command_endpoint, info_commands::info_commands_endpoint},
dice::dice_handler::dice_handler,
};
#[cfg(debug_assertions)]
fn logs() {
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt as _, EnvFilter};
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_env("RUST_LOG"))
.init();
}
#[cfg(not(debug_assertions))]
fn logs() {
println!(
"
Logs is able in only debug mode. Start bot with command \"cargo run\"\n
Логи доступны только в режиме дебаг. Запустите бота командой \"cargo run\".
"
);
}
#[tokio::main]
async fn main() {
logs();
dotenv().ok();
let token_result = dotenvy::var("TOKEN");
match token_result {
Ok(token) => {
let bot = Bot::new(token);
let mut route = Router::new("main");
let mut dice = Router::new("dice");
dice.message
.register(dice_handler)
.filter(CT::one(ContentType::Dice));
dice.message.inner_middlewares.register(AdminCheck {});
let mut command = Router::new("commands");
let mut admin_commands = Router::new("admin_commands");
let mut default_commands = Router::new("default_commands");
create_handler!(default_commands, info_commands_endpoint, help, privacy);
create_handler!(admin_commands, admin_command_endpoint, mute, unmute, ban);
admin_commands
.message
.inner_middlewares
.register(AdminCheck {});
command.include(admin_commands).include(default_commands);
route.include(command);
route.include(dice);
let dispatcher = Dispatcher::builder().main_router(route).bot(bot).build();
dispatcher
.to_service_provider_default()
.unwrap()
.run_polling()
.await
.unwrap();
}
Err(error) => {
eprintln!("Error text: {:?}", error);
}
}
}