27
27
28
28
updater = None
29
29
default_chat_id = None
30
+ custom_command = None
30
31
custom_command_callback = None
31
32
32
- def bot_start (token , chat_id , custom_command = None , command_callback = None ):
33
+ def bot_start (token , chat_id , command = None , command_callback = None ):
33
34
global updater
34
35
global default_chat_id
36
+ global custom_command
35
37
global custom_command_callback
36
38
37
39
default_chat_id = chat_id
@@ -40,9 +42,11 @@ def bot_start(token, chat_id, custom_command = None, command_callback = None):
40
42
41
43
updater .dispatcher .add_error_handler (on_error )
42
44
43
- if custom_command is not None :
44
- updater .dispatcher .add_handler (telegram .ext .CommandHandler (custom_command , on_custom_command ))
45
- custom_command_callback = command_callback
45
+ if command is not None :
46
+ updater .dispatcher .add_handler (telegram .ext .CommandHandler (command , on_custom_command ))
47
+
48
+ custom_command = command
49
+ custom_command_callback = command_callback
46
50
47
51
updater .start_polling ()
48
52
@@ -60,6 +64,7 @@ def on_custom_command(update, context):
60
64
61
65
def on_error (update , context ):
62
66
global updater
67
+ global custom_command
63
68
64
69
logging .exception ('Error in telegram bot' , exc_info = context .error )
65
70
@@ -69,6 +74,12 @@ def on_error(update, context):
69
74
updater .stop ()
70
75
time .sleep (2 )
71
76
updater .start_polling ()
77
+
78
+ # Reattach handlers
79
+ updater .dispatcher .add_error_handler (on_error )
80
+ if custom_command is not None :
81
+ updater .dispatcher .add_handler (telegram .ext .CommandHandler (custom_command , on_custom_command ))
82
+
72
83
73
84
74
85
def bot_stop ():
0 commit comments