Skip to content
This repository was archived by the owner on May 17, 2022. It is now read-only.

Commit 953ca49

Browse files
committed
bug fix
1 parent cf1d146 commit 953ca49

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

Handlers.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def gentoken(u: Update, c: CallbackContext):
4444
[random.choice(string.ascii_letters+string.digits) for x in range(32)])
4545
server.admin_token.append(admin_token)
4646
u.message.reply_html((
47-
'one-time admin token:\n<pre>'
47+
'one-time admin token:\n<pre>\n'
4848
f'{admin_token}'
49-
'</pre>\n<i>Send this token to anyone you want to promote as admin'
49+
'\n</pre>\n<i>Send this token to anyone you want to promote as admin</i>'
5050
))
5151

5252
# TODO:availability of removing admins feature
@@ -723,12 +723,6 @@ def send(u: Update, c: CallbackContext):
723723
server.dispatcher.add_handler(sendall_conv_handler.get_handler(), group = 1)
724724

725725
def add_users_handlers(server: BotHandler):
726-
def unknown_msg(u: Update, c: CallbackContext):
727-
u.message.reply_text(server.get_string('unknown-msg'))
728-
729-
def unknown_command(u: Update, c: CallbackContext):
730-
u.message.reply_text(server.get_string('unknown'))
731-
732726
dispatcher_decorators = DispatcherDecorators(server.dispatcher)
733727

734728
@dispatcher_decorators.commandHandler
@@ -809,9 +803,6 @@ def handle_edited_msg(u: Update, c:CallbackContext):
809803
# labels: enhancement
810804
u.edited_message.reply_text(server.strings['edited-message'])
811805

812-
dispatcher_decorators.addHandler(MessageHandler(Filters.command, unknown_command))
813-
dispatcher_decorators.addHandler(MessageHandler(Filters.all, unknown_msg))
814-
815806
def add_other_handlers(server: BotHandler):
816807
dispatcher_decorators = DispatcherDecorators(server.dispatcher)
817808

@@ -870,3 +861,17 @@ def error_handler(update: object, context: CallbackContext) -> None:
870861
user_data = context.user_data,
871862
chat_data = context.chat_data
872863
)
864+
865+
def add_unknown_handlers(server: BotHandler):
866+
"this must be the last method you call while adding handlers"
867+
868+
dispatcher_decorators = DispatcherDecorators(server.dispatcher)
869+
870+
def unknown_msg(u: Update, c: CallbackContext):
871+
u.message.reply_text(server.get_string('unknown-msg'))
872+
873+
def unknown_command(u: Update, c: CallbackContext):
874+
u.message.reply_text(server.get_string('unknown'))
875+
876+
dispatcher_decorators.addHandler(MessageHandler(Filters.command, unknown_command),1)
877+
dispatcher_decorators.addHandler(MessageHandler(Filters.all, unknown_msg),1)

main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ def __init__(
121121
Handlers.add_admin_handlers(self)
122122
Handlers.add_owner_handlers(self)
123123
Handlers.add_other_handlers(self)
124+
Handlers.add_unknown_handlers(self)
124125

125126
def log_bug(self, exc:Exception, msg='', report = True, disable_notification = False,**args):
126127
info = BugReporter.exception(msg, exc, report = self.bug_reporter and report)
127128
logging.exception(msg, exc_info=exc)
128129
msg = html.escape(msg)
129-
tb_string = html.escape(info['tb_string'])
130+
escaped_info = {k:html.escape(str(v)) for k,v in info.items()}
130131
message = (
131132
'<b>An exception was raised</b>\n'
132-
'<i>L{line_no}@{file_name}: {exc_type}<i>\n'
133+
'<i>L{line_no}@{file_name}: {exc_type}</i>\n'
133134
f'{msg}\n\n'
134-
f'<pre>{tb_string}</pre>'
135-
).format_map(info)
135+
'<pre>{tb_string}</pre>'
136+
).format_map(escaped_info)
136137

137138
if len(args):
138139
message+='\n\nExtra info:'
@@ -144,7 +145,7 @@ def log_bug(self, exc:Exception, msg='', report = True, disable_notification = F
144145
try:
145146
self.bot.send_message(chat_id = self.ownerID, text = message, parse_mode = ParseMode.HTML, disable_notification = disable_notification)
146147
except:
147-
logging.exception('can not send message to owner')
148+
logging.exception('can not send message to owner. message:\n'+message)
148149

149150
def purge(self, html_str:str, images=True):
150151
tags = self.SUPPORTED_HTML_TAGS

0 commit comments

Comments
 (0)