Skip to content

Commit

Permalink
fix(tg): Incorrect logic on bot command modifications
Browse files Browse the repository at this point in the history
Signed-off-by: Kwong Tung Nan <[email protected]>
  • Loading branch information
kwongtn committed Jun 30, 2024
1 parent 66e76a7 commit 96efe41
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions telegram_provider/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,27 @@ async def startup(self, **_):
for k, v in handlers_mapping.items():
handlers_dict[k]["handler"] = v

# TODO: Add logic for when a new command is added
has_changes = False
existing_commands = set()
for bot_command in await ptb_application.bot.get_my_commands():
command = bot_command.command
existing_commands.add(command)
if (
command not in handlers_dict.keys()
or handlers_dict[command]["description"] != bot_command.description
):
logger.info(
"Modification to bot command list required, updating now..."
)
await ptb_application.bot.set_my_commands(
[
(command, elem["description"])
for command, elem in handlers_dict.items()
]
)
break
has_changes = True

if has_changes or set(handlers_dict.keys()).symmetric_difference(
existing_commands
):
logger.info("Modification to bot command list required, updating now...")
await ptb_application.bot.set_my_commands(
[
(command, elem["description"])
for command, elem in handlers_dict.items()
]
)

ptb_application.add_handlers(
[
Expand Down

0 comments on commit 96efe41

Please sign in to comment.