0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2024-12-24 00:33:05 +03:00

адаптированы yangexgpt и message_processing

This commit is contained in:
Maxim Slipenko 2024-07-13 19:15:49 +03:00
parent 212c2836c9
commit d624ed4a1b
11 changed files with 86 additions and 51 deletions

View File

@ -6,12 +6,12 @@ def main():
pwd = Path().cwd()
dir_core = pwd / "src" / "ocab_core"
dir_modules_standard = pwd / "src" / "ocab_modules" / "standard"
dir_modules_custom = pwd / "src" / "ocab_modules" / "custom"
dir_modules_external = pwd / "src" / "ocab_modules" / "external"
json = {
"core": str(dir_core),
"modules standard": str(dir_modules_standard),
"modules custom": str(dir_modules_custom),
"modules external": str(dir_modules_external),
}
with open("src/paths.json", "w", encoding="utf8") as f:
f.write(dumps(json, indent=4))

View File

@ -15,11 +15,13 @@ bot_modules = [
UnsafeFSLoader(f"{paths.modules_standard}/config"),
UnsafeFSLoader(f"{paths.modules_standard}/database"),
UnsafeFSLoader(f"{paths.modules_standard}/roles"),
UnsafeFSLoader(f"{paths.modules_external}/yandexgpt"),
FSLoader(f"{paths.modules_standard}/command_helper"),
FSLoader(f"{paths.modules_standard}/info"),
FSLoader(f"{paths.modules_standard}/filters"),
FSLoader(f"{paths.modules_standard}/create_report_apps"),
FSLoader(f"{paths.modules_standard}/admin"),
FSLoader(f"{paths.modules_standard}/message_processing"),
]

View File

@ -1,15 +0,0 @@
from aiogram import Dispatcher
from src.ocab_modules.standard.message_processing.message_api import (
router as process_message,
)
async def include_routers(dp: Dispatcher):
"""
Подключение роутеров в бота
dp.include_router()
"""
# dp.include_router(info_router)
# dp.include_router(admin_router)
dp.include_router(process_message)

View File

@ -0,0 +1 @@
from .handlers import answer_to_message

View File

@ -1,6 +1,9 @@
{
w "id": "external.yandexgpt",
"name": "Yandex GPT",
"description": "Модуль для работы с Yandex GPT",
"author": "OCAB Team",
"version": "1.0"
"version": "1.0.0",
"privileged": true,
"dependencies": {}
}

View File

@ -15,9 +15,6 @@ from .handlers import (
"standard.filters", ["ChatModerOrAdminFilter", "ChatNotInApproveFilter"]
)
log(ChatModerOrAdminFilter)
log(ChatNotInApproveFilter)
router = Router()
# Если сообщение содержит какой либо текст и выполняется фильтр ChatNotInApproveFilter, то вызывается функция chat_not_in_approve_list

View File

@ -1 +1,7 @@
from .config import get_approved_chat_id, get_default_chat_tag, get_roles
from .config import (
get_approved_chat_id,
get_default_chat_tag,
get_roles,
get_yandexgpt_in_words,
get_yandexgpt_start_words,
)

View File

@ -0,0 +1 @@
from .message_api import module_init

View File

@ -0,0 +1,13 @@
{
"id": "standard.message_processing",
"name": "Info",
"description": "Модуль с информацией",
"author": "OCAB Team",
"version": "1.0.0",
"privileged": false,
"dependencies": {
"standard.roles": "^1.0.0",
"standard.database": "^1.0.0",
"standard.command_helper": "^1.0.0"
}
}

View File

@ -2,14 +2,45 @@
from aiogram import Bot, F, Router, types
from ocab_core.logger import log
from ocab_modules.external.yandexgpt.handlers import answer_to_message
from ocab_modules.standard.config.config import (
get_approved_chat_id,
get_yandexgpt_in_words,
get_yandexgpt_start_words,
from ocab_core.modules_system.public_api import get_module, log, register_router
# from ocab_modules.standard.database.db_api import *
(get_approved_chat_id, get_yandexgpt_in_words, get_yandexgpt_start_words) = get_module(
"standard.config",
["get_approved_chat_id", "get_yandexgpt_in_words", "get_yandexgpt_start_words"],
)
answer_to_message = get_module("external.yandexgpt", "answer_to_message")
(
get_chat,
add_chat,
get_user,
add_user,
get_user_name,
change_user_name,
get_user_tag,
change_user_tag,
update_chat_all_stat,
update_user_all_stat,
add_message,
) = get_module(
"standard.database",
[
"db_api.get_chat",
"db_api.add_chat",
"db_api.get_user",
"db_api.add_user",
"db_api.get_user_name",
"db_api.change_user_name",
"db_api.get_user_tag",
"db_api.change_user_tag",
"db_api.update_chat_all_stat",
"db_api.update_user_all_stat",
"db_api.add_message",
],
)
from ocab_modules.standard.database.db_api import *
async def chat_check(message: types.Message):
@ -19,15 +50,13 @@ async def chat_check(message: types.Message):
if get_chat(message.chat.id) is None:
if message.chat.id in get_approved_chat_id():
# print(f"Chat in approve list: {message.chat.id} {message.chat.title}")
await log(f"Chat in approve list: {message.chat.id} {message.chat.title}")
log(f"Chat in approve list: {message.chat.id} {message.chat.title}")
add_chat(message.chat.id, message.chat.title)
# print(f"Chat added: {message.chat.id} {message.chat.title}")
await log(f"Chat added: {message.chat.id} {message.chat.title}")
log(f"Chat added: {message.chat.id} {message.chat.title}")
else:
# print(f"Chat not in approve list: {message.chat.id} {message.chat.title}")
await log(
f"Chat not in approve list: {message.chat.id} {message.chat.title}"
)
log(f"Chat not in approve list: {message.chat.id} {message.chat.title}")
pass
else:
# Проверяем обновление названия чата
@ -36,10 +65,10 @@ async def chat_check(message: types.Message):
chat.chat_name = message.chat.title
chat.save()
# print(f"Chat updated: {message.chat.id} {message.chat.title}")
await log(f"Chat updated: {message.chat.id} {message.chat.title}")
log(f"Chat updated: {message.chat.id} {message.chat.title}")
else:
# print(f"Chat already exists: {message.chat.id} {message.chat.title}")
await log(f"Chat already exists: {message.chat.id} {message.chat.title}")
log(f"Chat already exists: {message.chat.id} {message.chat.title}")
pass
@ -62,23 +91,19 @@ async def user_check(message: types.Message):
message.from_user.last_name,
message.from_user.username,
)
# print(f"User added: {message.from_user.id} {message.from_user.first_name} {message.from_user.last_name}")
await log(f"User added: {message.from_user.id} {current_user_name}")
log(f"User added: {message.from_user.id} {current_user_name}")
else:
# print(f"User already exists: {message.from_user.id} {message.from_user.first_name} {message.from_user.last_name} {message.from_user.username}")
await log(
log(
f"User already exists: {message.from_user.id} {current_user_name} {message.from_user.username}"
)
# Проверяем обновление имени пользователя
if get_user_name(message.from_user.id) != current_user_name:
change_user_name(message.from_user.id, current_user_name)
# print(f"User updated: {message.from_user.id} {message.from_user.first_name} {message.from_user.last_name}")
await log(f"User name updated: {message.from_user.id} {current_user_name}")
log(f"User name updated: {message.from_user.id} {current_user_name}")
# Проверяем обновление username пользователя
if get_user_tag(message.from_user.id) != message.from_user.username:
change_user_tag(message.from_user.id, message.from_user.username)
# print(f"User updated: {message.from_user.id} {message.from_user.username}")
await log(
log(
f"User tag updated: {message.from_user.id} {message.from_user.username}"
)
pass
@ -101,17 +126,19 @@ async def message_processing(message: types.Message, bot: Bot):
if (message.text.split(" ")[0] in get_yandexgpt_start_words()) or (
any(word in message.text for word in get_yandexgpt_in_words())
):
# print("message_processing")
await log("message_processing")
log("message_processing")
await answer_to_message(message, bot)
elif message.reply_to_message is not None:
if message.reply_to_message.from_user.is_bot:
# print("message_processing")
await log("message_processing")
log("message_processing")
await answer_to_message(message, bot)
router = Router()
# Если сообщение содержит текст то вызывается функция message_processing
router.message.register(message_processing, F.text)
async def module_init():
register_router(router)

View File

@ -7,7 +7,7 @@ from json import loads
class Path:
core: str
modules_standard: str
modules_custom: str
modules_external: str
def _get_paths(path_to_json: str):
@ -16,7 +16,7 @@ def _get_paths(path_to_json: str):
return Path(
core=paths["core"],
modules_standard=paths["modules standard"],
modules_custom=paths["modules custom"],
modules_external=paths["modules external"],
)