This commit is contained in:
@@ -2,9 +2,11 @@ import nio
|
||||
import simplematrixbotlib as botlib
|
||||
|
||||
from src.handlers.help import help_handler
|
||||
from src.handlers.city import list_cities_handler
|
||||
from src.handlers.city import list_cities_handler, select_city_handler
|
||||
from src.handlers.user import register_handler
|
||||
|
||||
from src.fmt.city_formatter import CityFormatter
|
||||
|
||||
def setup(bot: botlib.Bot, prefix: str):
|
||||
@bot.listener.on_message_event
|
||||
async def help_command(room: nio.rooms.MatrixRoom, message: nio.events.room_events.Event):
|
||||
@@ -22,6 +24,11 @@ def setup(bot: botlib.Bot, prefix: str):
|
||||
if match.command('cities-list'):
|
||||
await list_cities_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id)
|
||||
|
||||
if match.command('select-city'):
|
||||
formatter = CityFormatter()
|
||||
city_name = formatter.get_name_from_parts(match.args())
|
||||
await select_city_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id, city_name=city_name)
|
||||
|
||||
if match.command('register'):
|
||||
await register_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id, args=match.args())
|
||||
|
||||
|
||||
@@ -21,3 +21,14 @@ async def list_cities_handler(room_id: str, bot: botlib.Bot, sender: str, admin_
|
||||
|
||||
await bot.api.send_markdown_message(room_id=room_id, message=msg)
|
||||
|
||||
async def select_city_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str, city_name: str):
|
||||
|
||||
session = aiohttp.ClientSession(json_serialize=ujson.dumps)
|
||||
apiFetcher = ApiFetcher(dots_bot_api_config.get_base_url(), session)
|
||||
formatter = CityFormatter()
|
||||
cityAPI = CityAPI(apiFetcher, formatter)
|
||||
|
||||
msg: str = await cityAPI.select_object_message(city_name, sender)
|
||||
|
||||
await bot.api.send_markdown_message(room_id=room_id, message=msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user