Compare commits
5 Commits
7c0d1a376c
...
1ee76cbef0
Author | SHA1 | Date | |
---|---|---|---|
|
1ee76cbef0 | ||
|
59222bc4c6 | ||
|
51ec37b766 | ||
|
35c1df8363 | ||
|
e4d746ea97 |
|
@ -15,7 +15,8 @@ anyhow = "1.0.86"
|
|||
async-trait = "0.1.80"
|
||||
chrono = "0.4.38"
|
||||
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"] }
|
||||
tracing = {version = "0.1.40"}
|
||||
tracing-subscriber = {version="0.3.18", features=["env-filter"]}
|
||||
|
|
|
@ -26,7 +26,7 @@ pub async fn ban_member(
|
|||
|
||||
let user_id: i64 = match user.get_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 };
|
||||
|
@ -41,7 +41,7 @@ pub async fn ban_member(
|
|||
{
|
||||
Ok(EventReturn::Cancel)
|
||||
} 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
|
||||
.reply_to(message.id())
|
||||
|
|
|
@ -27,7 +27,7 @@ pub async fn mute_member(
|
|||
|
||||
let user_id: i64 = match user.get_id() {
|
||||
Some(id) => id,
|
||||
None => return Ok(EventReturn::Skip)
|
||||
None => return Ok(EventReturn::Skip),
|
||||
};
|
||||
|
||||
sleep(Duration::from_millis(time.1)).await;
|
||||
|
@ -45,7 +45,7 @@ pub async fn mute_member(
|
|||
{
|
||||
Ok(EventReturn::Cancel)
|
||||
} 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
|
||||
.reply_to(message.id())
|
||||
|
|
|
@ -21,10 +21,7 @@ pub async fn unmute_member(
|
|||
if let Some(id) = user.get_id() {
|
||||
user_id = id;
|
||||
} else {
|
||||
sender_builder
|
||||
.build()
|
||||
.send(&bot)
|
||||
.await?;
|
||||
sender_builder.build().send(&bot).await?;
|
||||
|
||||
return Ok(EventReturn::Cancel);
|
||||
}
|
||||
|
@ -46,7 +43,7 @@ pub async fn unmute_member(
|
|||
|
||||
Ok(EventReturn::Cancel)
|
||||
} 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
|
||||
.reply_to(message.id())
|
||||
|
|
|
@ -51,7 +51,6 @@ async fn main() {
|
|||
match token_result {
|
||||
Ok(token) => {
|
||||
let bot = Bot::new(token);
|
||||
|
||||
let mut route = Router::new("main");
|
||||
let mut dice = Router::new("dice");
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use async_trait::async_trait;
|
||||
use telers::{
|
||||
errors::{EventErrorKind, HandlerError},
|
||||
event::telegram::{HandlerRequest, HandlerResponse},
|
||||
middlewares::{InnerMiddleware, Next}, types::Message,
|
||||
event::telegram::HandlerResponse,
|
||||
middlewares::{InnerMiddleware, Next},
|
||||
types::Message,
|
||||
Request,
|
||||
};
|
||||
|
||||
use anyhow::Error as Reject;
|
||||
|
@ -17,16 +19,12 @@ pub struct AdminCheck {}
|
|||
|
||||
#[async_trait]
|
||||
impl InnerMiddleware for AdminCheck {
|
||||
async fn call(
|
||||
&self,
|
||||
request: HandlerRequest,
|
||||
next: Next,
|
||||
) -> Result<HandlerResponse, EventErrorKind> {
|
||||
async fn call(&self, request: Request, next: Next) -> Result<HandlerResponse, EventErrorKind> {
|
||||
let (bot, message) = (request.clone().bot, request.clone().update);
|
||||
|
||||
let is_replying_dice: Option<Message> = match message.kind().message().unwrap() {
|
||||
Message::Dice(dice) => dice.reply_to_message.clone(),
|
||||
_ => None
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let admins_list = get_all_admins(&bot, message.chat().unwrap().id())
|
||||
|
@ -41,10 +39,11 @@ impl InnerMiddleware for AdminCheck {
|
|||
} else {
|
||||
if is_replying_dice.is_some() {
|
||||
MessageSender::builder(chat_id)
|
||||
.text("Недостаточно прав для использования данной команды.")
|
||||
.build().send(&bot)
|
||||
.await
|
||||
.unwrap();
|
||||
.text("Недостаточно прав для использования данной команды.")
|
||||
.build()
|
||||
.send(&bot)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
return Err(EventErrorKind::Handler(HandlerError::new(Reject::msg(
|
||||
|
|
|
@ -21,7 +21,7 @@ impl TargetUser {
|
|||
Self::Id(_id) => true,
|
||||
Self::Reply(msg) => {
|
||||
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 {
|
||||
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 {
|
||||
Self::Id(id) => {
|
||||
let get_chat_member_result: Result<ChatMember, SessionErrorKind> =
|
||||
|
|
Loading…
Reference in New Issue