-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topic frinedly check && username validation
- Loading branch information
Showing
3 changed files
with
18 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
use teloxide::{payloads::*, prelude::*, requests::JsonRequest, types::*}; | ||
|
||
trait RequestTopicFriendly { | ||
pub trait Rustina { | ||
type Err: std::error::Error + Send; | ||
type SendMessageTF: Request<Payload = SendMessage, Err = Self::Err>; | ||
|
||
/// For Telegram documentation see [`SendMessage`]. | ||
fn send_message_tf<C, T>(&self, chat_id: C, text: T) -> Self::SendMessageTF | ||
fn send_message_tf<C, T>(&self, chat_id: C, text: T, message: &Message) -> Self::SendMessageTF | ||
where | ||
C: Into<Recipient>, | ||
T: Into<String>; | ||
} | ||
|
||
impl RequestTopicFriendly for Bot { | ||
impl Rustina for Bot { | ||
type Err = teloxide::errors::RequestError; | ||
type SendMessageTF = JsonRequest<teloxide::payloads::SendMessage>; | ||
|
||
fn send_message_tf<C, T>(&self, chat_id: C, text: T) -> Self::SendMessageTF | ||
fn send_message_tf<C, T>(&self, chat_id: C, text: T, message: &Message) -> Self::SendMessageTF | ||
where | ||
C: Into<Recipient>, | ||
T: Into<String>, | ||
{ | ||
Self::SendMessageTF::new( | ||
self.clone(), | ||
teloxide::payloads::SendMessage::new(chat_id, text), | ||
) | ||
match message.thread_id { | ||
Some(thread_id) => Self::SendMessageTF::new( | ||
self.clone(), | ||
teloxide::payloads::SendMessage::new(chat_id, text), | ||
) | ||
.message_thread_id(thread_id), | ||
None => Self::SendMessageTF::new( | ||
self.clone(), | ||
teloxide::payloads::SendMessage::new(chat_id, text), | ||
), | ||
} | ||
} | ||
} |