Skip to content

Commit

Permalink
Allow to reconfigure an existing plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurdok committed Oct 17, 2024
1 parent 0eb5ee1 commit 940913a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/spanreed/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ async def _manage_plugins(self, user: User) -> None:
[
"Register to new plugin",
"Unregister from an existing plugin",
"Reconfigure an existing plugin",
"Cancel",
],
)
if choice == 0: # Register to new plugin
await self._register_to_new_plugin(bot, user)
elif choice == 1: # Unregister from an existing plugin
await self._unregister_from_an_existing_plugin(bot, user)
elif choice == 2: # Cancel
elif choice == 2: # Reconfigure an existing plugin
await self._reconfigure_existing_plugin(bot, user)
elif choice == 3: # Cancel
break

async def _register_to_new_plugin(
Expand Down Expand Up @@ -101,3 +104,24 @@ async def _unregister_from_an_existing_plugin(
plugin = plugins[choice]
self._logger.info(f"Unregistering user {user} from plugin {plugin}")
await plugin.unregister_user(user)

async def _reconfigure_existing_plugin(
self, bot: TelegramBotApi, user: User
) -> None:
plugins = [plugin for plugin in await Plugin.get_plugins_for_user(user)
if plugin.has_user_config()]

if not plugins:
await bot.send_message("There are no plugins to reconfigure.")
return

if choice := await bot.request_user_choice(
"Which plugin do you want to reconfigure?",
[p.name() for p in plugins] + ["Cancel"],
) == len(plugins):
return

plugin = plugins[choice]
self._logger.info(f"Reconfiguring user {user} for plugin {plugin}")
await plugin.ask_for_user_config(user)

0 comments on commit 940913a

Please sign in to comment.