@@ -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
725725def 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-
815806def 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 )
0 commit comments