mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2025-09-26 18:29:06 +03:00
Открытое бета тестирование + фиксы первого дня
This commit is contained in:
@@ -6,6 +6,7 @@ from .models.chat_stats import ChatStats
|
||||
from ....service import paths
|
||||
from ..exceptions.module_exceptions import MissingModuleName, NotExpectedModuleName
|
||||
import peewee as pw
|
||||
from aiogram.types import Message
|
||||
|
||||
|
||||
def connect_database(is_test: bool = False, module: str | None = None):
|
||||
@@ -39,7 +40,7 @@ def add_chat(chat_id, chat_name, chat_type=10, chat_stats=0):
|
||||
chat, created = Chats.get_or_create(id=chat_id, defaults={
|
||||
'chat_name': chat_name,
|
||||
'chat_type': chat_type,
|
||||
'chat_stats': chat_stats,
|
||||
'chat_all_stat': chat_stats,
|
||||
})
|
||||
if not created:
|
||||
# Обновить существующий чат, если он уже существует
|
||||
@@ -49,7 +50,12 @@ def add_chat(chat_id, chat_name, chat_type=10, chat_stats=0):
|
||||
chat.save()
|
||||
|
||||
|
||||
def add_user(user_id, user_name, user_tag=None, user_role=0, user_stats=0, user_rep=0):
|
||||
def add_user(user_id, user_first_name, user_last_name=None, user_tag=None, user_role=0, user_stats=0, user_rep=0):
|
||||
if user_last_name is None:
|
||||
user_name = user_first_name
|
||||
else:
|
||||
user_name = user_first_name + " " + user_last_name
|
||||
|
||||
user, created = Users.get_or_create(id=user_id, defaults={
|
||||
'user_tag': user_tag,
|
||||
'user_name': user_name,
|
||||
@@ -67,15 +73,18 @@ def add_user(user_id, user_name, user_tag=None, user_role=0, user_stats=0, user_
|
||||
user.save()
|
||||
|
||||
|
||||
def add_message(message_chat_id, message_id, message_sender_id, message_text, answer_to_message_id=None,
|
||||
message_ai_model=None):
|
||||
def add_message(message: Message, message_ai_model=None):
|
||||
if message.reply_to_message:
|
||||
answer_to_message_id = message.reply_to_message.message_id
|
||||
else:
|
||||
answer_to_message_id = None
|
||||
Messages.create(
|
||||
message_chat_id=message_chat_id,
|
||||
message_id=message_id,
|
||||
message_sender_id=message_sender_id,
|
||||
message_chat_id=message.chat.id,
|
||||
message_id=message.message_id,
|
||||
message_sender_id=message.from_user.id,
|
||||
answer_to_message_id=answer_to_message_id,
|
||||
message_ai_model=message_ai_model,
|
||||
message_text=message_text
|
||||
message_text=message.text
|
||||
)
|
||||
|
||||
|
||||
@@ -127,6 +136,10 @@ def get_user_tag(user_id):
|
||||
user = Users.get_or_none(Users.id == user_id)
|
||||
return user.user_tag if user else None
|
||||
|
||||
def get_user_id(user_tag):
|
||||
user = Users.get_or_none(Users.user_tag == user_tag)
|
||||
return user.id if user else None
|
||||
|
||||
|
||||
def get_user_name(user_id):
|
||||
user = Users.get_or_none(Users.id == user_id)
|
||||
@@ -148,7 +161,11 @@ def get_user_rep(user_id):
|
||||
return user.user_rep if user else None
|
||||
|
||||
|
||||
def change_user_name(user_id, new_user_name):
|
||||
def change_user_name(user_id, user_first_name, user_last_name=None):
|
||||
if user_last_name is None:
|
||||
new_user_name = user_first_name
|
||||
else:
|
||||
new_user_name = user_first_name + " " + user_last_name
|
||||
query = Users.update(user_name=new_user_name).where(Users.id == user_id)
|
||||
query.execute()
|
||||
|
||||
|
Reference in New Issue
Block a user