Compare commits

...

5 Commits

7 changed files with 21 additions and 25 deletions

View File

@ -15,7 +15,8 @@ anyhow = "1.0.86"
async-trait = "0.1.80" async-trait = "0.1.80"
chrono = "0.4.38" chrono = "0.4.38"
dotenvy = "0.15.7" dotenvy = "0.15.7"
telers = { git = "https://github.com/doryan04/telers.git" } regex = "1.11.0"
telers = "1.0.0-alpha.24"
tokio = { version="1.37.0", features=["rt-multi-thread"] } tokio = { version="1.37.0", features=["rt-multi-thread"] }
tracing = {version = "0.1.40"} tracing = {version = "0.1.40"}
tracing-subscriber = {version="0.3.18", features=["env-filter"]} tracing-subscriber = {version="0.3.18", features=["env-filter"]}

View File

@ -26,7 +26,7 @@ pub async fn ban_member(
let user_id: i64 = match user.get_id() { let user_id: i64 = match user.get_id() {
Some(id) => id, Some(id) => id,
None => return Ok(EventReturn::Skip) None => return Ok(EventReturn::Skip),
}; };
let callback = || async { bot.send(BanChatMember::new(chat_id, user_id)).await }; let callback = || async { bot.send(BanChatMember::new(chat_id, user_id)).await };
@ -41,7 +41,7 @@ pub async fn ban_member(
{ {
Ok(EventReturn::Cancel) Ok(EventReturn::Cancel)
} else { } else {
let banned_user_name: String = user.get_user_name(&bot, &message).await.unwrap(); let banned_user_name: Box<str> = user.get_user_name(&bot, &message).await.unwrap();
sender_builder sender_builder
.reply_to(message.id()) .reply_to(message.id())

View File

@ -27,7 +27,7 @@ pub async fn mute_member(
let user_id: i64 = match user.get_id() { let user_id: i64 = match user.get_id() {
Some(id) => id, Some(id) => id,
None => return Ok(EventReturn::Skip) None => return Ok(EventReturn::Skip),
}; };
sleep(Duration::from_millis(time.1)).await; sleep(Duration::from_millis(time.1)).await;
@ -45,7 +45,7 @@ pub async fn mute_member(
{ {
Ok(EventReturn::Cancel) Ok(EventReturn::Cancel)
} else { } else {
let muted_user_name: String = user.get_user_name(&bot, &message).await.unwrap(); let muted_user_name: Box<str> = user.get_user_name(&bot, &message).await.unwrap();
sender_builder sender_builder
.reply_to(message.id()) .reply_to(message.id())

View File

@ -21,10 +21,7 @@ pub async fn unmute_member(
if let Some(id) = user.get_id() { if let Some(id) = user.get_id() {
user_id = id; user_id = id;
} else { } else {
sender_builder sender_builder.build().send(&bot).await?;
.build()
.send(&bot)
.await?;
return Ok(EventReturn::Cancel); return Ok(EventReturn::Cancel);
} }
@ -46,7 +43,7 @@ pub async fn unmute_member(
Ok(EventReturn::Cancel) Ok(EventReturn::Cancel)
} else { } else {
let muted_user_name: String = user.get_user_name(&bot, &message).await.unwrap(); let muted_user_name: Box<str> = user.get_user_name(&bot, &message).await.unwrap();
sender_builder sender_builder
.reply_to(message.id()) .reply_to(message.id())

View File

@ -51,7 +51,6 @@ async fn main() {
match token_result { match token_result {
Ok(token) => { Ok(token) => {
let bot = Bot::new(token); let bot = Bot::new(token);
let mut route = Router::new("main"); let mut route = Router::new("main");
let mut dice = Router::new("dice"); let mut dice = Router::new("dice");

View File

@ -1,8 +1,10 @@
use async_trait::async_trait; use async_trait::async_trait;
use telers::{ use telers::{
errors::{EventErrorKind, HandlerError}, errors::{EventErrorKind, HandlerError},
event::telegram::{HandlerRequest, HandlerResponse}, event::telegram::HandlerResponse,
middlewares::{InnerMiddleware, Next}, types::Message, middlewares::{InnerMiddleware, Next},
types::Message,
Request,
}; };
use anyhow::Error as Reject; use anyhow::Error as Reject;
@ -17,16 +19,12 @@ pub struct AdminCheck {}
#[async_trait] #[async_trait]
impl InnerMiddleware for AdminCheck { impl InnerMiddleware for AdminCheck {
async fn call( async fn call(&self, request: Request, next: Next) -> Result<HandlerResponse, EventErrorKind> {
&self,
request: HandlerRequest,
next: Next,
) -> Result<HandlerResponse, EventErrorKind> {
let (bot, message) = (request.clone().bot, request.clone().update); let (bot, message) = (request.clone().bot, request.clone().update);
let is_replying_dice: Option<Message> = match message.kind().message().unwrap() { let is_replying_dice: Option<Message> = match message.kind().message().unwrap() {
Message::Dice(dice) => dice.reply_to_message.clone(), Message::Dice(dice) => dice.reply_to_message.clone(),
_ => None _ => None,
}; };
let admins_list = get_all_admins(&bot, message.chat().unwrap().id()) let admins_list = get_all_admins(&bot, message.chat().unwrap().id())
@ -41,10 +39,11 @@ impl InnerMiddleware for AdminCheck {
} else { } else {
if is_replying_dice.is_some() { if is_replying_dice.is_some() {
MessageSender::builder(chat_id) MessageSender::builder(chat_id)
.text("Недостаточно прав для использования данной команды.") .text("Недостаточно прав для использования данной команды.")
.build().send(&bot) .build()
.await .send(&bot)
.unwrap(); .await
.unwrap();
} }
return Err(EventErrorKind::Handler(HandlerError::new(Reject::msg( return Err(EventErrorKind::Handler(HandlerError::new(Reject::msg(

View File

@ -21,7 +21,7 @@ impl TargetUser {
Self::Id(_id) => true, Self::Id(_id) => true,
Self::Reply(msg) => { Self::Reply(msg) => {
if let Some(replied_msg) = msg.reply_to_message() { if let Some(replied_msg) = msg.reply_to_message() {
return replied_msg.from().map(|user| user.id).is_some(); replied_msg.from().map(|user| user.id).is_some()
} else { } else {
false false
} }
@ -46,7 +46,7 @@ impl TargetUser {
} }
} }
pub async fn get_user_name(&self, bot: &Bot, msg: &Message) -> Option<String> { pub async fn get_user_name(&self, bot: &Bot, msg: &Message) -> Option<Box<str>> {
match self { match self {
Self::Id(id) => { Self::Id(id) => {
let get_chat_member_result: Result<ChatMember, SessionErrorKind> = let get_chat_member_result: Result<ChatMember, SessionErrorKind> =