Add the company handlers.

main
KKlochko 2 years ago
parent b22166d031
commit fc33d5c63f

@ -3,9 +3,11 @@ import simplematrixbotlib as botlib
from src.handlers.help import help_handler
from src.handlers.city import city_list_handler, select_city_handler
from src.handlers.company import company_list_handler, select_company_handler
from src.handlers.user import register_handler
from src.fmt.city_formatter import CityFormatter
from src.fmt.company_formatter import CompanyFormatter
def setup(bot: botlib.Bot, prefix: str):
@bot.listener.on_message_event
@ -34,3 +36,13 @@ def setup(bot: botlib.Bot, prefix: str):
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())
# A registered user required
if match.command('company-list'):
await company_list_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id)
if match.command('select-company'):
formatter = CompanyFormatter()
company_name = formatter.get_name_from_parts(match.args())
await select_company_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id, company_name=company_name)

@ -0,0 +1,34 @@
import simplematrixbotlib as botlib
import aiohttp
import asyncio
import ujson
from src.config.dots_bot_api_config import DotsBotApiConfig
from src.api.v2.company_api import CompanyAPI
from src.fetcher.v2.api_fetcher import ApiFetcher
from src.fmt.company_formatter import CompanyFormatter
dots_bot_api_config = DotsBotApiConfig()
async def company_list_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str):
session = aiohttp.ClientSession(json_serialize=ujson.dumps)
apiFetcher = ApiFetcher(dots_bot_api_config.get_base_url(), session)
formatter = CompanyFormatter()
companyAPI = CompanyAPI(apiFetcher, formatter)
msg: str = await companyAPI.get_objects_message(sender)
await bot.api.send_markdown_message(room_id=room_id, message=msg)
async def select_company_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str, company_name: str):
session = aiohttp.ClientSession(json_serialize=ujson.dumps)
apiFetcher = ApiFetcher(dots_bot_api_config.get_base_url(), session)
formatter = CompanyFormatter()
companyAPI = CompanyAPI(apiFetcher, formatter)
msg: str = await companyAPI.select_object_message(company_name, sender)
await bot.api.send_markdown_message(room_id=room_id, message=msg)
Loading…
Cancel
Save