@@ -8,12 +8,17 @@ use teloxide::types::{
88 ChatId , InlineKeyboardButton , InlineKeyboardMarkup , MessageId , ParseMode , ThreadId ,
99} ;
1010
11-
1211/// Telegram Bot wrapper with rate limiting and forum topic support
1312pub struct TelegramBot {
1413 bot : Bot ,
1514 chat_id : ChatId ,
16- rate_limiter : Arc < RateLimiter < governor:: state:: NotKeyed , governor:: state:: InMemoryState , governor:: clock:: DefaultClock > > ,
15+ rate_limiter : Arc <
16+ RateLimiter <
17+ governor:: state:: NotKeyed ,
18+ governor:: state:: InMemoryState ,
19+ governor:: clock:: DefaultClock ,
20+ > ,
21+ > ,
1722}
1823
1924impl TelegramBot {
@@ -31,11 +36,13 @@ impl TelegramBot {
3136 }
3237
3338 /// Get a clone of the underlying Bot for polling
39+ #[ allow( dead_code) ]
3440 pub fn bot ( & self ) -> Bot {
3541 self . bot . clone ( )
3642 }
3743
3844 /// Get the chat ID
45+ #[ allow( dead_code) ]
3946 pub fn chat_id ( & self ) -> ChatId {
4047 self . chat_id
4148 }
@@ -56,16 +63,15 @@ impl TelegramBot {
5663 req = req. parse_mode ( match pm. as_str ( ) {
5764 "MarkdownV2" => ParseMode :: MarkdownV2 ,
5865 "HTML" => ParseMode :: Html ,
59- _ => ParseMode :: Markdown ,
66+ _ => ParseMode :: MarkdownV2 ,
6067 } ) ;
6168 }
6269
6370 if let Some ( tid) = effective_thread {
6471 req = req. message_thread_id ( ThreadId ( MessageId ( tid) ) ) ;
6572 }
6673
67- req. await
68- . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) )
74+ req. await . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) )
6975 }
7076
7177 /// Send a message with inline keyboard buttons
@@ -101,23 +107,26 @@ impl TelegramBot {
101107 req = req. parse_mode ( match pm. as_str ( ) {
102108 "MarkdownV2" => ParseMode :: MarkdownV2 ,
103109 "HTML" => ParseMode :: Html ,
104- _ => ParseMode :: Markdown ,
110+ _ => ParseMode :: MarkdownV2 ,
105111 } ) ;
106112 }
107113
108114 if let Some ( tid) = effective_thread {
109115 req = req. message_thread_id ( ThreadId ( MessageId ( tid) ) ) ;
110116 }
111117
112- req. await
113- . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) )
118+ req. await . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) )
114119 }
115120
116121 /// Create a forum topic
117122 pub async fn create_forum_topic ( & self , name : & str ) -> Result < Option < i32 > > {
118123 self . rate_limiter . until_ready ( ) . await ;
119124
120- match self . bot . create_forum_topic ( self . chat_id , name, 0x6FB9F0 , "" ) . await {
125+ match self
126+ . bot
127+ . create_forum_topic ( self . chat_id , name, 0x6FB9F0 , "" )
128+ . await
129+ {
121130 Ok ( topic) => {
122131 let thread_id = topic. thread_id . 0 . 0 ;
123132 tracing:: info!( %name, %thread_id, "Forum topic created" ) ;
@@ -201,8 +210,7 @@ impl TelegramBot {
201210 req = req. parse_mode ( pm) ;
202211 }
203212
204- req. await
205- . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) ) ?;
213+ req. await . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) ) ?;
206214 Ok ( ( ) )
207215 }
208216
@@ -215,8 +223,7 @@ impl TelegramBot {
215223 req = req. text ( t) ;
216224 }
217225
218- req. await
219- . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) ) ?;
226+ req. await . map_err ( |e| AppError :: Telegram ( e. to_string ( ) ) ) ?;
220227 Ok ( ( ) )
221228 }
222229
@@ -249,7 +256,16 @@ pub fn is_interrupt_command(text: &str) -> bool {
249256 let normalized = text. trim ( ) . to_lowercase ( ) ;
250257 matches ! (
251258 normalized. as_str( ) ,
252- "stop" | "/stop" | "cancel" | "/cancel" | "abort" | "/abort" | "esc" | "/esc" | "escape" | "/escape"
259+ "stop"
260+ | "/stop"
261+ | "cancel"
262+ | "/cancel"
263+ | "abort"
264+ | "/abort"
265+ | "esc"
266+ | "/esc"
267+ | "escape"
268+ | "/escape"
253269 )
254270}
255271
0 commit comments