@@ -309,35 +309,37 @@ def process_msg(self, msg):
309
309
os .stat (msg .path ).st_size , msg .mime )
310
310
if os .stat (msg .path ).st_size == 0 :
311
311
os .remove (msg .path )
312
- return self .bot .bot .sendMessage (tg_dest ,
312
+ tg_msg = self .bot .bot .sendMessage (tg_dest ,
313
313
msg_template % ("Error: Empty %s received. (MS01)" % msg .type ))
314
- if not msg .text :
315
- if msg .type == MsgType .Image :
316
- msg .text = "sent a picture."
317
- elif msg .type == MsgType .Sticker :
318
- msg .text = "sent a sticker."
319
- if msg .mime == "image/gif" :
320
- tg_msg = self .bot .bot .sendDocument (tg_dest , msg .file , caption = msg_template % msg .text )
321
314
else :
322
- try :
323
- tg_msg = self .bot .bot .sendPhoto (tg_dest , msg .file , caption = msg_template % msg .text )
324
- except telegram .error .BadRequest :
315
+ if not msg .text :
316
+ if msg .type == MsgType .Image :
317
+ msg .text = "sent a picture."
318
+ elif msg .type == MsgType .Sticker :
319
+ msg .text = "sent a sticker."
320
+ if msg .mime == "image/gif" :
325
321
tg_msg = self .bot .bot .sendDocument (tg_dest , msg .file , caption = msg_template % msg .text )
326
- os .remove (msg .path )
322
+ else :
323
+ try :
324
+ tg_msg = self .bot .bot .sendPhoto (tg_dest , msg .file , caption = msg_template % msg .text )
325
+ except telegram .error .BadRequest :
326
+ tg_msg = self .bot .bot .sendDocument (tg_dest , msg .file , caption = msg_template % msg .text )
327
+ os .remove (msg .path )
327
328
self .logger .debug ("%s, process_msg_step_3_3" , xid )
328
329
elif msg .type == MsgType .File :
329
330
if os .stat (msg .path ).st_size == 0 :
330
331
os .remove (msg .path )
331
- return self .bot .bot .sendMessage (tg_dest ,
332
+ tg_msg = self .bot .bot .sendMessage (tg_dest ,
332
333
msg_template % ("Error: Empty %s received. (MS02)" % msg .type ))
333
- if not msg .text :
334
- file_name = os .path .basename (msg .path )
335
- msg .text = "sent a file."
336
334
else :
337
- file_name = msg .text
338
- tg_msg = self .bot .bot .sendDocument (tg_dest , msg .file , caption = msg_template % msg .text ,
339
- filename = file_name )
340
- os .remove (msg .path )
335
+ if not msg .text :
336
+ file_name = os .path .basename (msg .path )
337
+ msg .text = "sent a file."
338
+ else :
339
+ file_name = msg .text
340
+ tg_msg = self .bot .bot .sendDocument (tg_dest , msg .file , caption = msg_template % msg .text ,
341
+ filename = file_name )
342
+ os .remove (msg .path )
341
343
elif msg .type == MsgType .Audio :
342
344
if os .stat (msg .path ).st_size == 0 :
343
345
os .remove (msg .path )
@@ -387,7 +389,7 @@ def process_msg(self, msg):
387
389
self .logger .debug ("%s, process_msg_step_4" , xid )
388
390
if msg .source in (MsgSource .User , MsgSource .Group ):
389
391
msg_log = {"master_msg_id" : "%s.%s" % (tg_msg .chat .id , tg_msg .message_id ),
390
- "text" : msg .text ,
392
+ "text" : msg .text or "Sent a %s." % msg . type ,
391
393
"msg_type" : msg .type ,
392
394
"sent_to" : "Master" ,
393
395
"slave_origin_uid" : "%s.%s" % (msg .channel_id , msg .origin ['uid' ]),
@@ -1169,9 +1171,20 @@ def poll(self):
1169
1171
1170
1172
def error (self , bot , update , error ):
1171
1173
"""
1172
- Print error to console, Triggered by python-telegram-bot error callback.
1174
+ Print error to console, and send error message to first admin.
1175
+ Triggered by python-telegram-bot error callback.
1173
1176
"""
1174
- self .logger .warning ('ERRORRR! Update %s caused error %s' % (update , error ))
1177
+ if "Conflict: terminated by other long poll or webhook (409)" in str (error ):
1178
+ msg = 'Please immediately turn off all EFB instances.\n Another bot instance or web-hook detected.'
1179
+ self .logger .error (msg )
1180
+ bot .sendMessage (getattr (config , self .channel_id )['admins' ][0 ], msg )
1181
+ else :
1182
+ bot .sendMessage (getattr (config , self .channel_id )['admins' ][0 ],
1183
+ "EFB Telegram Master channel encountered error <code>%s</code> "
1184
+ "caused by update <code>%s</code>.\n \n "
1185
+ "Report issue: <a href=\" https://github.com/blueset/ehForwarderBot/issues/new\" >GitHub Issue Page</a>" %
1186
+ (html .escape (error ), html .escape (update )))
1187
+ self .logger .error ('ERROR! Update %s caused error %s' % (update , error ))
1175
1188
1176
1189
def _flag (self , key , value ):
1177
1190
"""
0 commit comments