@@ -172,13 +172,11 @@ def listener(messages):
172172
173173
174174# Create TeleBot instance now that `listener` is defined.
175- telebot_bot = telebot .TeleBot (TIBO_TELEGRAM_BOT_TOKEN , threaded = False )
176- telebot_bot .set_update_listener (listener ) # register listener
177175print (f"Bot initialized with token: { TIBO_TELEGRAM_BOT_TOKEN [:10 ]} ..." )
178176
179177
180178# Middleware to detect command language preference
181- @telebot_bot .middleware_handler (update_types = ["message" ])
179+ @bot .middleware_handler (update_types = ["message" ])
182180def detect_command_language (bot_instance , message ):
183181 """Detect which language variant of command user used"""
184182 if message .text and message .text .startswith ("/" ):
@@ -195,7 +193,7 @@ def detect_command_language(bot_instance, message):
195193
196194
197195# handle the "/check" command
198- @telebot_bot .message_handler (commands = ["check" ])
196+ @bot .message_handler (commands = ["check" ])
199197def command_check (m ):
200198 try :
201199 cid = m .chat .id
@@ -208,13 +206,13 @@ def command_check(m):
208206 0 # save user id and his current "command level", so he can use the "/getImage" command
209207 )
210208 print (f"Sending welcome messages to { cid } " )
211- telebot_bot .send_message (cid , "Hello, stranger, let me scan you..." )
212- telebot_bot .send_message (cid , "Scanning complete, I know you now" )
209+ bot .send_message (cid , "Hello, stranger, let me scan you..." )
210+ bot .send_message (cid , "Scanning complete, I know you now" )
213211 command_help (m ) # show the new user the help page
214212 print (f"Successfully processed /start for new user { cid } " )
215213 else :
216214 print (f"User { cid } already known, sending existing user message" )
217- telebot_bot .send_message (
215+ bot .send_message (
218216 cid , "I already know you, no need for me to scan you again!"
219217 )
220218 except Exception as e :
@@ -223,15 +221,15 @@ def command_check(m):
223221
224222 traceback .print_exc ()
225223 try :
226- telebot_bot .send_message (
224+ bot .send_message (
227225 m .chat .id , "Sorry, an error occurred. Please try again."
228226 )
229227 except Exception as send_error :
230228 print (f"Failed to send error message: { send_error } " )
231229
232230
233231# handle the "/start" command
234- @telebot_bot .message_handler (
232+ @bot .message_handler (
235233 commands = ["start" , "kaishi" ]
236234) # kaishi = 开始 (start in Chinese Pinyin)
237235def command_start (m ):
@@ -257,8 +255,8 @@ def command_start(m):
257255 bot .send_message (cid , "你好,陌生人,让我扫描你..." )
258256 bot .send_message (cid , "扫描完成,现在我认识你了" )
259257 else :
260- telebot_bot .send_message (cid , "Hello, stranger, let me scan you..." )
261- telebot_bot .send_message (cid , "Scanning complete, I know you now" )
258+ bot .send_message (cid , "Hello, stranger, let me scan you..." )
259+ bot .send_message (cid , "Scanning complete, I know you now" )
262260
263261 command_help (m ) # show the new user the help page
264262 print (f"Successfully processed /start for new user { cid } " )
@@ -267,7 +265,7 @@ def command_start(m):
267265 if lang == "zh" :
268266 bot .send_message (cid , "我已经认识你了,不需要再次扫描!" )
269267 else :
270- telebot_bot .send_message (
268+ bot .send_message (
271269 cid , "I already know you, no need for me to scan you again!"
272270 )
273271 except Exception as e :
@@ -276,14 +274,14 @@ def command_start(m):
276274
277275 traceback .print_exc ()
278276 try :
279- telebot_bot .send_message (
277+ bot .send_message (
280278 m .chat .id , "Sorry, an error occurred. Please try again."
281279 )
282280 except Exception as send_error :
283281 print (f"Failed to send error message: { send_error } " )
284282
285283
286- @telebot_bot .message_handler (
284+ @bot .message_handler (
287285 commands = ["help" , "bangzhu" ]
288286) # bangzhu = 帮助 (help in Chinese Pinyin)
289287def command_help (m ):
@@ -307,10 +305,10 @@ def command_help(m):
307305 help_text += "/" + key + " - "
308306 help_text += commands [key ] + "\n "
309307
310- telebot_bot .send_message (cid , help_text )
308+ bot .send_message (cid , help_text )
311309
312310
313- @telebot_bot .message_handler (commands = ["promo" ])
311+ @bot .message_handler (commands = ["promo" ])
314312def command_promo (m ):
315313 """Best-effort promo handler: call TeleAds if available, but remain safe."""
316314 cid = m .chat .id
@@ -326,11 +324,11 @@ def command_promo(m):
326324 send_ad ({"update_id" : cid })
327325 except Exception as ex :
328326 print (f"Teleads send_advertisement failed: { ex } " )
329- telebot_bot .send_message (cid , "Promo processed (ad request sent)." )
327+ bot .send_message (cid , "Promo processed (ad request sent)." )
330328 except Exception as e :
331329 print (f"Error processing promo command: { e } " )
332330 try :
333- telebot_bot .send_message (cid , "Promo failed to process." )
331+ bot .send_message (cid , "Promo failed to process." )
334332 except Exception :
335333 pass
336334 {
@@ -359,7 +357,7 @@ def weather_get(apikey, city):
359357 return None
360358
361359
362- @telebot_bot .message_handler (
360+ @bot .message_handler (
363361 commands = ["weather" , "tianqi" , "погода" , "天气" ]
364362) # tianqi = 天气 (weather in Chinese Pinyin)
365363def command_weather (message : Message ):
@@ -375,9 +373,9 @@ def command_weather(message: Message):
375373
376374 if weather is None :
377375 if lang == "zh" :
378- telebot_bot .send_message (cid , f"获取 { city } 的天气数据失败" )
376+ bot .send_message (cid , f"获取 { city } 的天气数据失败" )
379377 else :
380- telebot_bot .send_message (cid , f"Failed to get weather data for { city } " )
378+ bot .send_message (cid , f"Failed to get weather data for { city } " )
381379 return
382380
383381 conditions = weather ["weather" ][0 ]["description" ]
@@ -386,18 +384,18 @@ def command_weather(message: Message):
386384 temp_max = weather ["main" ]["temp_max" ]
387385
388386 if lang == "zh" :
389- telebot_bot .send_message (
387+ bot .send_message (
390388 cid ,
391389 f"当前温度 { current_temp } °C,天气 { conditions } \n "
392390 f"最高温度 { temp_max } °C,最低温度 { temp_min } °C" ,
393391 )
394392 else :
395- telebot_bot .send_message (
393+ bot .send_message (
396394 cid , f"{ current_temp } { conditions } , up to { temp_max } , at night { temp_min } "
397395 )
398396
399397
400- @telebot_bot .message_handler (
398+ @bot .message_handler (
401399 commands = ["8" , "eight" , "suiji" ]
402400) # suiji = 随机 (random in Chinese Pinyin)
403401def command_eight (message : Message ):
@@ -409,19 +407,19 @@ def command_eight(message: Message):
409407 print (chislo )
410408
411409 if lang == "zh" :
412- telebot_bot .send_message (cid , f"随机数:{ chislo } " )
410+ bot .send_message (cid , f"随机数:{ chislo } " )
413411 else :
414- telebot_bot .send_message (cid , f"{ chislo } " )
412+ bot .send_message (cid , f"{ chislo } " )
415413
416414
417- @telebot_bot .message_handler (commands = ["3.14" , "3" , "three" , "pi" , "три" , "пи" ])
415+ @bot .message_handler (commands = ["3.14" , "3" , "three" , "pi" , "три" , "пи" ])
418416def command_pi (message : Message ):
419417 cid = message .chat .id
420418 command_params = message .text .split ()
421419 pi = math .pi
422420 print (pi )
423- telebot_bot .send_message (cid , f"{ pi } " )
424- telebot_bot .send_message (cid , f"{ pi } " )
421+ bot .send_message (cid , f"{ pi } " )
422+ bot .send_message (cid , f"{ pi } " )
425423
426424
427425def listToString (s ):
@@ -432,10 +430,10 @@ def listToString(s):
432430 return str1 .join (s )
433431
434432
435- @telebot_bot .message_handler (commands = ["bar" ])
433+ @bot .message_handler (commands = ["bar" ])
436434def command_bar (message : Message ):
437435 cid = message .chat .id
438- chat = telebot_bot .get_chat (message .chat .id )
436+ chat = bot .get_chat (message .chat .id )
439437 mention = []
440438 for i in bar_members :
441439 if "username" in bar_members [i ]:
@@ -449,22 +447,22 @@ def command_bar(message: Message):
449447 print (mention )
450448 push_alert = listToString (mention )
451449 print (push_alert )
452- telebot_bot .send_message (cid , f"{ push_alert } GO BAR" , parse_mode = "HTML" )
453- telebot_bot .send_poll (
450+ bot .send_message (cid , f"{ push_alert } GO BAR" , parse_mode = "HTML" )
451+ bot .send_poll (
454452 cid ,
455453 "DRINK BEER SAVE WATER" ,
456454 ["Drink beer" , "Discord" , "Play computer" ],
457455 is_anonymous = False ,
458456 )
459457 pic_choice = random .choice (beer_photo )
460- telebot_bot .send_photo (cid , pic_choice )
458+ bot .send_photo (cid , pic_choice )
461459 # bot.send_poll(cid, 'Poll', {
462460 # "Drink beer",
463461 # "Play computer"
464462 # })
465463
466464
467- @telebot_bot .message_handler (
465+ @bot .message_handler (
468466 commands = ["mem" , "tupian" ]
469467) # tupian = 图片 (image in Chinese Pinyin)
470468def command_mem (message : Message ):
@@ -478,11 +476,11 @@ def command_mem(message: Message):
478476 for i in range (0 , count_memes ):
479477 mem .append (json_data ["data" ]["memes" ][i ]["url" ])
480478 random .shuffle (mem )
481- telebot_bot .send_photo (cid , mem [0 ])
479+ bot .send_photo (cid , mem [0 ])
482480
483481
484482# test api
485- @telebot_bot .message_handler (
483+ @bot .message_handler (
486484 commands = ["getimage" , "image" , "huoqutupian" ]
487485) # huoqutupian = 获取图片 (get image in Chinese Pinyin)
488486def command_image (message : Message ):
@@ -496,10 +494,10 @@ def command_image(message: Message):
496494 for i in range (0 , count_memes ):
497495 image .append (json_data ["data" ]["memes" ][i ]["url" ])
498496 random .shuffle (image )
499- telebot_bot .send_photo (cid , image [0 ])
497+ bot .send_photo (cid , image [0 ])
500498
501499
502- @telebot_bot .message_handler (commands = ["meme" ])
500+ @bot .message_handler (commands = ["meme" ])
503501def command_mem (message : Message ):
504502 cid = message .chat .id
505503 r = requests .get ("https://api.imgflip.com/get_memes" )
@@ -513,7 +511,7 @@ def command_mem(message: Message):
513511 meme .append (json_data ["data" ]["memes" ][i ]["url" ])
514512 # print(mem[i])
515513 random .shuffle (meme )
516- telebot_bot .send_photo (cid , meme [0 ])
514+ bot .send_photo (cid , meme [0 ])
517515
518516
519517@bot .message_handler (commands = ["help_auth" ])
0 commit comments