Skip to content

Commit 1d30314

Browse files
committed
Error Handler update
1 parent 6f1463f commit 1d30314

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

.DS_Store

0 Bytes
Binary file not shown.

bot/.DS_Store

0 Bytes
Binary file not shown.

bot/commands/.DS_Store

0 Bytes
Binary file not shown.

bot/errors/callback_error.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,47 @@ def init(update, context):
99
try:
1010
raise context.error
1111
except Unauthorized:
12-
err = '[ERROR] Unauthorized\n'
12+
err = '<i>[ERROR] Unauthorized</i>\n'
1313
#error_message(update, context, err)
1414
# remove update.message.chat_id from conversation list
1515
except BadRequest:
16-
err = '[ERROR] BadRequest - malformed requests\n'
16+
err = '<i>[ERROR] BadRequest - malformed requests</i>\n'
1717
#error_message(update, context, err)
1818
# handle malformed requests - read more below!
1919
except TimedOut:
20-
err = '[ERROR] TimedOut - slow connection problems\n'
20+
err = '<i>[ERROR] TimedOut - slow connection problems</i>\n'
2121
#error_message(update, context, err)
2222
# handle slow connection problems
2323
except NetworkError:
24-
err = '[ERROR] NetworkError - other connection problems\n'
24+
err = '<i>[ERROR] NetworkError - other connection problems</i>\n'
2525
#error_message(update, context, err)
2626
# handle other connection problems
2727
except ChatMigrated:
28-
err = '[ERROR] ChatMigrated - chat_id not found (maybe group/channel migrated?)\n'
28+
err = '<i>[ERROR] ChatMigrated - chat_id not found (maybe group/channel migrated?)</i>\n'
2929
#error_message(update, context, err)
3030
# the chat_id of a group has changed, use e.new_chat_id instead
3131
except TelegramError:
32-
err = '[ERROR] TelegramError\nThis is a generic error not handled by other handlers, check the console logs for info\n'
32+
err = '<i>[ERROR] TelegramError\nThis is a generic error not handled by other handlers, check the console logs for info</i>\n'
3333
#error_message(update, context, err)
3434
# handle all other telegram related errors
3535
except AttributeError:
36-
err = '[ERROR] AttributeError - bad code'
36+
err = '<i>[ERROR] AttributeError - bad code</i>'
3737
except TypeError:
3838
# err = '[ERROR] TypeError - Unknown'
3939
# need to fix this...
4040
err = None
4141

4242
if err != None:
43-
error_message(update, context, err, txt)
43+
nomeutente=update.message.from_user.first_name
44+
username="@"+update.message.from_user.username
45+
id=update.message.from_user.id
46+
chat_id = update.message.chat_id
47+
chat_name = update.message.chat.title
48+
error_message(update, context, err, txt, nomeutente, username, id, chat_id, chat_name)
4449

4550

4651
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
4752
logger = logging.getLogger(__name__)
48-
def error_message(update, context, err, txt):
49-
log = '\n[LOG] errore: {}'.format(context.error)
50-
context.bot.send_message(chat_id=config.log_channel, text = "{}\n\n{}{}".format(txt, err, log), parse_mode='HTML')
53+
def error_message(update, context, err, txt, name, username, id, chatid, chat_name):
54+
log = '\n<i>[LOG] errore: {}</i>'.format(context.error)
55+
context.bot.send_message(chat_id=config.log_channel, text = "<b>Resoconto errore</b>\n<b>Chat</b>: [{}][{}]\n<b>Utente</b>: [{}][{}][{}]\n<b>Comando/messaggio</b>:{}\n\n<b>Errori rilevati</b>:\n{}{}".format(chat_name, chatid, id, name, username, txt, err, log), parse_mode='HTML')

0 commit comments

Comments
 (0)