Skip to content

Commit 025cc08

Browse files
committed
Updated the python version. Simplified set_commands
1 parent 8011dc3 commit 025cc08

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.9.16-alpine3.17
1+
FROM python:3.10.13-alpine3.19
22

33
WORKDIR /app
44

run.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,13 @@ async def start_container(update: Update, context: ContextTypes.DEFAULT_TYPE, ar
246246
await context.bot.send_message(chat_id=update.effective_chat.id, text=reply, parse_mode=ParseMode.MARKDOWN_V2)
247247

248248

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)
254253

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)
259256

260257

261258
if __name__ == '__main__':
@@ -264,15 +261,10 @@ async def set_commands(commands_map: dict, application: Application):
264261
parser.add_argument('user_id', type=FileSecretType(int), help='Absolute path to a text file with an allowed user id number.')
265262
args = parser.parse_args()
266263

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)
273264
application = ApplicationBuilder() \
274265
.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))) \
276268
.build()
277269

278270
# Make all the Docker handlers private

0 commit comments

Comments
 (0)