Add the city handler to have cities-list in bot's command list.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import nio
|
import nio
|
||||||
import simplematrixbotlib as botlib
|
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):
|
def setup(bot: botlib.Bot, prefix: str):
|
||||||
@bot.listener.on_message_event
|
@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'):
|
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)
|
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)
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user