mirror of
https://github.com/miloszowi/everyone-mention-telegram-bot.git
synced 2025-10-25 08:25:48 +00:00
mongodb new structure, added new collection chats
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user