mongodb new structure, added new collection chats

This commit is contained in:
miloszowi
2021-10-14 20:24:58 +02:00
parent 9c8f5795f8
commit e0916441b9
17 changed files with 194 additions and 193 deletions

View File

@@ -5,8 +5,8 @@ from telegram.update import Update
from bot.handler.abstractHandler import AbstractHandler
from bot.message.replier import Replier
from config.contents import joined, not_joined
from exception.notFoundException import NotFoundException
from logger import Logger
from exception.invalidActionException import InvalidActionException
from repository.chatRepository import ChatRepository
from repository.userRepository import UserRepository
@@ -18,18 +18,17 @@ class JoinHandler(AbstractHandler):
def __init__(self) -> None:
self.bot_handler = CommandHandler(self.action, self.wrap)
self.user_repository = UserRepository()
self.chat_repository = ChatRepository()
def handle(self, update: Update, context: CallbackContext) -> None:
try:
user = self.user_repository.get_by_id(self.inbound.user_id)
user = self.user_repository.provide(self.inbound)
chat = self.chat_repository.provide(self.inbound)
users = chat.groups.get(self.inbound.group_name)
if user.is_in_chat(self.inbound.chat_id):
return Replier.markdown(update, Replier.interpolate(not_joined, self.inbound))
if user.user_id in users:
raise InvalidActionException(Replier.interpolate(not_joined, self.inbound))
user.add_to_chat(self.inbound.chat_id)
self.user_repository.save(user)
except NotFoundException:
self.user_repository.save_by_inbound_message(self.inbound)
users.append(user.user_id)
self.chat_repository.save(chat)
Replier.markdown(update, Replier.interpolate(joined, self.inbound))
Logger.action(self.inbound, self.action)