Compare commits
No commits in common. "7c0d1a376c42c9e951295cb6c9df50df562ed6dd" and "d5c0df353c98c9c0c45f729177d6c518d36298f4" have entirely different histories.
7c0d1a376c
...
d5c0df353c
|
@ -0,0 +1,51 @@
|
||||||
|
use telers::{
|
||||||
|
event::{
|
||||||
|
EventReturn,
|
||||||
|
telegram::HandlerResult
|
||||||
|
},
|
||||||
|
filters::CommandObject,
|
||||||
|
types::Message,
|
||||||
|
Bot
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
assets::files::BAN_COMMAND_HELP, actions::ban::ban_member,
|
||||||
|
types::{
|
||||||
|
enums::target_user::TargetUser,
|
||||||
|
structs::handler_entity::HandlerEntity
|
||||||
|
},
|
||||||
|
utils::{
|
||||||
|
general::cast_boxed_array::cast_boxed,
|
||||||
|
telegram::{
|
||||||
|
args_parsers::get_user,
|
||||||
|
data_getters::get_chat_data,
|
||||||
|
senders::send_html
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn ban(bot: Bot, message: Message, command: CommandObject) -> HandlerResult {
|
||||||
|
let args: Vec<&'static str> = cast_boxed(command.args);
|
||||||
|
|
||||||
|
let (chat_id, mut handler_entity): (i64, HandlerEntity) = get_chat_data(&bot, &message);
|
||||||
|
|
||||||
|
let target_user: TargetUser = get_user(
|
||||||
|
handler_entity.clone(),
|
||||||
|
args.first().copied(),
|
||||||
|
&mut 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
if args.is_empty() && !target_user.exist(){
|
||||||
|
send_html(bot, message, BAN_COMMAND_HELP).await?;
|
||||||
|
|
||||||
|
return Ok(EventReturn::Cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
handler_entity
|
||||||
|
.message_sender_builder
|
||||||
|
.set_text("Нет ID или ответа на сообщение пользователя.");
|
||||||
|
|
||||||
|
ban_member(handler_entity, chat_id, target_user, 0).await?;
|
||||||
|
|
||||||
|
Ok(EventReturn::Finish)
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
use telers::{event::telegram::HandlerResult, types::Message, Bot};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
assets::files::{HELP_COMMAND_TEXT, PRIVACY_COMMAND_TEXT},
|
||||||
|
utils::telegram::senders::send_html,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub async fn help(bot: Bot, msg: Message) -> HandlerResult {
|
||||||
|
send_html(bot, msg, HELP_COMMAND_TEXT).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub async fn privacy(bot: Bot, msg: Message) -> HandlerResult {
|
||||||
|
send_html(bot, msg, PRIVACY_COMMAND_TEXT).await
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod ban_command;
|
||||||
|
pub mod info_commands;
|
||||||
|
pub mod mute_command;
|
||||||
|
pub mod unmute_command;
|
|
@ -0,0 +1,85 @@
|
||||||
|
use telers::{
|
||||||
|
event::{telegram::HandlerResult, EventReturn},
|
||||||
|
filters::CommandObject,
|
||||||
|
types::Message,
|
||||||
|
Bot,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
assets::files::MUTE_COMMAND_HELP,
|
||||||
|
actions::mute::mute_member,
|
||||||
|
types::{
|
||||||
|
enums::{
|
||||||
|
target_user::TargetUser,
|
||||||
|
time_metrics::TimeMetrics
|
||||||
|
},
|
||||||
|
structs::handler_entity::HandlerEntity,
|
||||||
|
},
|
||||||
|
utils::{
|
||||||
|
general::cast_boxed_array::cast_boxed,
|
||||||
|
telegram::{
|
||||||
|
args_parsers::get_user,
|
||||||
|
data_getters::get_chat_data,
|
||||||
|
senders::send_html
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn mute(bot: Bot, message: Message, command: CommandObject) -> HandlerResult {
|
||||||
|
let (chat_id, mut handler_entity): (i64, HandlerEntity) = get_chat_data(&bot, &message);
|
||||||
|
|
||||||
|
let args: Vec<&'static str> = cast_boxed(command.args);
|
||||||
|
|
||||||
|
let mut duration_argument_position = 0usize;
|
||||||
|
|
||||||
|
let target_user: TargetUser = get_user(
|
||||||
|
handler_entity.clone(),
|
||||||
|
args.first().copied(),
|
||||||
|
&mut duration_argument_position,
|
||||||
|
);
|
||||||
|
|
||||||
|
if args.is_empty() && !target_user.exist(){
|
||||||
|
send_html(bot, message, MUTE_COMMAND_HELP).await?;
|
||||||
|
|
||||||
|
return Ok(EventReturn::Cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
handler_entity
|
||||||
|
.message_sender_builder
|
||||||
|
.set_text("Нет ID или ответа на сообщение пользователя.");
|
||||||
|
|
||||||
|
match args.get(duration_argument_position).cloned() {
|
||||||
|
Some(duration_str) => {
|
||||||
|
let metric = args
|
||||||
|
.get(duration_argument_position + 1)
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or("d");
|
||||||
|
|
||||||
|
if let Ok(duration) = duration_str.parse::<i64>() {
|
||||||
|
let mute_duration = TimeMetrics::from(metric, duration);
|
||||||
|
|
||||||
|
mute_member(handler_entity, chat_id, target_user, (mute_duration, 0)).await?;
|
||||||
|
} else {
|
||||||
|
handler_entity
|
||||||
|
.message_sender_builder
|
||||||
|
.build()
|
||||||
|
.send(&handler_entity.bot_instance)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
return Ok(EventReturn::Cancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
handler_entity
|
||||||
|
.message_sender_builder
|
||||||
|
.text("Не указана длительность мута.")
|
||||||
|
.build()
|
||||||
|
.send(&handler_entity.bot_instance)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
return Ok(EventReturn::Cancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(EventReturn::Finish)
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
use telers::{
|
||||||
|
event::{telegram::HandlerResult, EventReturn},
|
||||||
|
filters::CommandObject,
|
||||||
|
types::Message,
|
||||||
|
Bot,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
actions::unmute::unmute_member,
|
||||||
|
assets::files::UNMUTE_COMMAND_HELP,
|
||||||
|
types::{enums::target_user::TargetUser, structs::handler_entity::HandlerEntity},
|
||||||
|
utils::{
|
||||||
|
general::cast_boxed_array::cast_boxed,
|
||||||
|
telegram::{args_parsers::get_user, data_getters::get_chat_data, senders::send_html},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn unmute(bot: Bot, message: Message, command: CommandObject) -> HandlerResult {
|
||||||
|
let (chat_id, mut handler_entity): (i64, HandlerEntity) = get_chat_data(&bot, &message);
|
||||||
|
|
||||||
|
let args: Vec<&'static str> = cast_boxed(command.args);
|
||||||
|
|
||||||
|
let target_user: TargetUser = get_user(handler_entity.clone(), args.first().copied(), &mut 0);
|
||||||
|
|
||||||
|
if args.is_empty() && !target_user.exist() {
|
||||||
|
send_html(bot, message, UNMUTE_COMMAND_HELP).await?;
|
||||||
|
|
||||||
|
return Ok(EventReturn::Cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
handler_entity
|
||||||
|
.message_sender_builder
|
||||||
|
.set_text("Нет ID или ответа на сообщение пользователя.");
|
||||||
|
|
||||||
|
unmute_member(handler_entity, chat_id, target_user).await?;
|
||||||
|
|
||||||
|
Ok(EventReturn::Finish)
|
||||||
|
}
|
|
@ -1,98 +0,0 @@
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use telers::{
|
|
||||||
event::{telegram::HandlerResult, EventReturn},
|
|
||||||
filters::CommandObject,
|
|
||||||
types::Message,
|
|
||||||
Bot,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
actions::{ban::ban_member, mute::mute_member, unmute::unmute_member},
|
|
||||||
assets::files::{BAN_COMMAND_HELP, MUTE_COMMAND_HELP, UNMUTE_COMMAND_HELP},
|
|
||||||
types::{
|
|
||||||
enums::{target_user::TargetUser, time_metrics::TimeMetrics},
|
|
||||||
structs::handler_entity::HandlerEntity,
|
|
||||||
},
|
|
||||||
utils::{
|
|
||||||
general::cast_boxed_array::cast_boxed,
|
|
||||||
telegram::{args_parsers::get_user, data_getters::get_chat_data, senders::send_html},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn admin_command_endpoint(
|
|
||||||
bot: Bot,
|
|
||||||
message: Message,
|
|
||||||
command: CommandObject,
|
|
||||||
) -> HandlerResult {
|
|
||||||
let command_type: &str = command.command.deref();
|
|
||||||
|
|
||||||
let args: Vec<&'static str> = cast_boxed(command.args);
|
|
||||||
|
|
||||||
let (chat_id, mut handler_entity): (i64, HandlerEntity) = get_chat_data(&bot, &message);
|
|
||||||
|
|
||||||
let mut duration_argument_position = 0usize;
|
|
||||||
|
|
||||||
let target_user: TargetUser = get_user(
|
|
||||||
handler_entity.clone(),
|
|
||||||
args.first().copied(),
|
|
||||||
&mut duration_argument_position,
|
|
||||||
);
|
|
||||||
|
|
||||||
if args.is_empty() && !target_user.exist() {
|
|
||||||
let help_txt = match command_type {
|
|
||||||
"ban" => BAN_COMMAND_HELP,
|
|
||||||
"mute" => MUTE_COMMAND_HELP,
|
|
||||||
"unmute" => UNMUTE_COMMAND_HELP,
|
|
||||||
_ => "Такой команды не существует.",
|
|
||||||
};
|
|
||||||
|
|
||||||
send_html(bot, message, help_txt).await?;
|
|
||||||
|
|
||||||
return Ok(EventReturn::Cancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
handler_entity
|
|
||||||
.message_sender_builder
|
|
||||||
.set_text("Нет ID или ответа на сообщение пользователя.");
|
|
||||||
|
|
||||||
match command_type {
|
|
||||||
"ban" => ban_member(handler_entity, chat_id, target_user, 0).await?,
|
|
||||||
"mute" => match args.get(duration_argument_position).cloned() {
|
|
||||||
Some(duration_str) => {
|
|
||||||
let metric = args
|
|
||||||
.get(duration_argument_position + 1)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or("d");
|
|
||||||
|
|
||||||
if let Ok(duration) = duration_str.parse::<i64>() {
|
|
||||||
let mute_duration = TimeMetrics::from(metric, duration);
|
|
||||||
|
|
||||||
mute_member(handler_entity, chat_id, target_user, (mute_duration, 0)).await?
|
|
||||||
} else {
|
|
||||||
handler_entity
|
|
||||||
.message_sender_builder
|
|
||||||
.build()
|
|
||||||
.send(&handler_entity.bot_instance)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
return Ok(EventReturn::Cancel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
handler_entity
|
|
||||||
.message_sender_builder
|
|
||||||
.text("Не указана длительность мута.")
|
|
||||||
.build()
|
|
||||||
.send(&handler_entity.bot_instance)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
return Ok(EventReturn::Cancel);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"unmute" => unmute_member(handler_entity, chat_id, target_user).await?,
|
|
||||||
_ => EventReturn::Finish,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(EventReturn::Finish)
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use telers::{event::telegram::HandlerResult, filters::CommandObject, types::Message, Bot};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
assets::files::{HELP_COMMAND_TEXT, PRIVACY_COMMAND_TEXT},
|
|
||||||
utils::telegram::senders::send_html,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn info_commands_endpoint(
|
|
||||||
bot: Bot,
|
|
||||||
msg: Message,
|
|
||||||
command: CommandObject,
|
|
||||||
) -> HandlerResult {
|
|
||||||
match command.command.deref() {
|
|
||||||
"help" => send_html(bot, msg, HELP_COMMAND_TEXT).await,
|
|
||||||
"privacy" => send_html(bot, msg, PRIVACY_COMMAND_TEXT).await,
|
|
||||||
_ => Ok(telers::event::EventReturn::Cancel),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
pub mod admin_commands;
|
|
||||||
pub mod info_commands;
|
|
25
src/main.rs
25
src/main.rs
|
@ -9,15 +9,20 @@ use telers::{
|
||||||
|
|
||||||
mod actions;
|
mod actions;
|
||||||
mod assets;
|
mod assets;
|
||||||
mod handlers;
|
|
||||||
mod middlewares;
|
mod middlewares;
|
||||||
mod types;
|
mod types;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use middlewares::admin_check_middleware::AdminCheck;
|
use middlewares::admin_check_middleware::AdminCheck;
|
||||||
|
|
||||||
use handlers::{
|
mod endpoints;
|
||||||
commands::{admin_commands::admin_command_endpoint, info_commands::info_commands_endpoint},
|
use endpoints::{
|
||||||
|
commands::{
|
||||||
|
ban_command::ban,
|
||||||
|
info_commands::{help, privacy},
|
||||||
|
mute_command::mute,
|
||||||
|
unmute_command::unmute,
|
||||||
|
},
|
||||||
dice::dice_handler::dice_handler,
|
dice::dice_handler::dice_handler,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,6 +46,16 @@ fn logs() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! append_command {
|
||||||
|
($branch:expr, $($command:expr), *) => {
|
||||||
|
$($branch
|
||||||
|
.message
|
||||||
|
.register($command)
|
||||||
|
.filter(Command::one(stringify!($command)));
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
logs();
|
logs();
|
||||||
|
@ -65,8 +80,8 @@ async fn main() {
|
||||||
let mut admin_commands = Router::new("admin_commands");
|
let mut admin_commands = Router::new("admin_commands");
|
||||||
let mut default_commands = Router::new("default_commands");
|
let mut default_commands = Router::new("default_commands");
|
||||||
|
|
||||||
create_handler!(default_commands, info_commands_endpoint, help, privacy);
|
append_command!(default_commands, help, privacy);
|
||||||
create_handler!(admin_commands, admin_command_endpoint, mute, unmute, ban);
|
append_command!(admin_commands, unmute, mute, ban);
|
||||||
|
|
||||||
admin_commands
|
admin_commands
|
||||||
.message
|
.message
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
#[macro_export]
|
|
||||||
macro_rules! create_handler {
|
|
||||||
($branch:expr, $command:expr) => {
|
|
||||||
$($branch
|
|
||||||
.message
|
|
||||||
.register($command)
|
|
||||||
.filter(Command::one(stringify!($command)));
|
|
||||||
)*
|
|
||||||
};
|
|
||||||
($branch:expr, $command:expr, $($endpoint:expr), *) => {
|
|
||||||
$branch
|
|
||||||
.message
|
|
||||||
.register($command)
|
|
||||||
.filter(Command::many([$(stringify!($endpoint)),*]));
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
pub mod create_handler;
|
|
|
@ -1,3 +1,2 @@
|
||||||
pub mod general;
|
pub mod general;
|
||||||
pub mod macro_rules;
|
|
||||||
pub mod telegram;
|
pub mod telegram;
|
||||||
|
|
Loading…
Reference in New Issue