@@ -246,16 +246,13 @@ async def start_container(update: Update, context: ContextTypes.DEFAULT_TYPE, ar
246
246
await context .bot .send_message (chat_id = update .effective_chat .id , text = reply , parse_mode = ParseMode .MARKDOWN_V2 )
247
247
248
248
249
- async def set_commands (commands_map : dict , application : Application ):
250
- for Scope , scope_data in commands_map .items ():
251
- scope = Scope () \
252
- if not scope_data .get ('args' ) \
253
- else Scope (* scope_data ['args' ]) # set `chat_id`
249
+ async def set_commands (scope : BotCommandScopeDefault | BotCommandScopeChat ,
250
+ commands : list [BotCommand ],
251
+ application : Application ):
252
+ await application .bot .set_my_commands (commands , scope = scope )
254
253
255
- await application .bot .set_my_commands (scope_data ['commands' ], scope = scope )
256
-
257
- cmd_names = ', ' .join (bc .command for bc in scope_data ['commands' ])
258
- logging .info ('Commands have been set: %s[%s]' , Scope .__name__ , cmd_names )
254
+ cmd_names = ', ' .join (bc .command for bc in commands )
255
+ logging .info ('Commands have been set: %s[%s]' , scope .__name__ , cmd_names )
259
256
260
257
261
258
if __name__ == '__main__' :
@@ -264,15 +261,10 @@ async def set_commands(commands_map: dict, application: Application):
264
261
parser .add_argument ('user_id' , type = FileSecretType (int ), help = 'Absolute path to a text file with an allowed user id number.' )
265
262
args = parser .parse_args ()
266
263
267
- commands_map = {
268
- BotCommandScopeDefault : {'commands' : SCOPES [BotCommandScopeDefault ]},
269
- BotCommandScopeChat : {'commands' : list (chain .from_iterable (SCOPES .values ())),
270
- 'args' : (args .user_id , )}
271
- }
272
- _set_commands = partial (set_commands , commands_map )
273
264
application = ApplicationBuilder () \
274
265
.token (args .token ) \
275
- .post_init (_set_commands ) \
266
+ .post_init (partial (set_commands , SCOPES [BotCommandScopeDefault ], BotCommandScopeDefault ())) \
267
+ .post_init (partial (set_commands , SCOPES [BotCommandScopeChat ], BotCommandScopeChat (args .user_id ))) \
276
268
.build ()
277
269
278
270
# Make all the Docker handlers private
0 commit comments