def update_chat_db(message): with db_session: chat = Chat.get(chat_id=message.chat.id) if chat == None: chat = Chat(chat_id=message.chat.id, user_id=message.from_user.id, open_date=datetime.now(), \ last_message_date=datetime.now(), username=message.from_user.username, \ first_name=message.from_user.first_name, last_name=message.from_user.last_name, \ silent_mode=False, deleted=False, group_id="nobody", state="REGISTER_STATE", \ realname="") else: chat.last_message_date = datetime.now() chat.username = message.from_user.username chat.first_name = message.from_user.first_name chat.last_name = message.from_user.last_name return chat
def add_chat(_bot: Bot, update: Update) -> None: chat_id = update.effective_chat.id if not Chat.exists(chat_id=chat_id): Chat(chat_id=chat_id, name=update.effective_chat.title) Chat.get(chat_id=chat_id).name = update.effective_chat.title
def create_chat(body): community_id = body.get("community_id") chat = Chat(community_id=body.get("community_id")) db.session.add(chat) db.session.commit() return chat.serialize()