diff --git a/src/handlers/__init__.py b/src/handlers/__init__.py index 438bcc7..08f611c 100644 --- a/src/handlers/__init__.py +++ b/src/handlers/__init__.py @@ -1,8 +1,8 @@ import nio import simplematrixbotlib as botlib -from .help import help_handler - +from src.handlers.help import help_handler +from src.handlers.city import list_cities_handler def setup(bot: botlib.Bot, prefix: str): @bot.listener.on_message_event @@ -12,3 +12,6 @@ def setup(bot: botlib.Bot, prefix: str): if match.is_not_from_this_bot() and match.prefix() and match.command('help'): await help_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id) + if match.is_not_from_this_bot() and match.prefix() and match.command('cities-list'): + await list_cities_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id) + diff --git a/src/handlers/city.py b/src/handlers/city.py new file mode 100644 index 0000000..64621dc --- /dev/null +++ b/src/handlers/city.py @@ -0,0 +1,20 @@ +import simplematrixbotlib as botlib +import aiohttp +import asyncio +import ujson + +from src.api.v2.city_api import CityAPI +from src.fetcher.v2.api_fetcher import ApiFetcher +from src.fmt.city_formatter import CityFormatter + +async def list_cities_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str): + + session = aiohttp.ClientSession(json_serialize=ujson.dumps) + apiFetcher = ApiFetcher("https://domain", session) + formatter = CityFormatter() + cityAPI = CityAPI(apiFetcher, formatter) + + msg: str = await cityAPI.get_objects_message() + + await bot.api.send_markdown_message(room_id=room_id, message=msg) +