mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2024-12-24 00:33:06 +03:00
перенос на новую архитектуру: в директории
This commit is contained in:
parent
7f232eff50
commit
b386e258cc
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
.env
|
||||||
|
env
|
||||||
|
venv
|
||||||
|
__pycache__
|
8
.idea/.gitignore
vendored
8
.idea/.gitignore
vendored
@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Black">
|
|
||||||
<option name="sdkName" value="Python 3.11" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (ocab)" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/ocab.iml" filepath="$PROJECT_DIR$/.idea/ocab.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
43
src/bot/config.ini
Normal file
43
src/bot/config.ini
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
[Telegram]
|
||||||
|
token=****
|
||||||
|
admin_password="Test_pass"
|
||||||
|
# Пока не используется
|
||||||
|
|
||||||
|
# Массивы заполнять через запятую. Пример: test|test2 |test3,
|
||||||
|
bot_trigger_front=
|
||||||
|
# Живой пример: Арма |Армат |Арма, |
|
||||||
|
bot_trigger_all=
|
||||||
|
# Живой пример: @arma_ai_bot |помогите |
|
||||||
|
private_answer=
|
||||||
|
# Живой пример: Я не понимаю тебя, но я могу поговорить с тобой в группе [название группы](https://t.me/) и ещё в некоторых других группах
|
||||||
|
reply_ignore=0
|
||||||
|
# По умолчанию: 0
|
||||||
|
# Содержит в себе все id топиков чата для чатов с форумным типом, если не заполнить контекст бота СЛОМАЕТСЯ!
|
||||||
|
# Пример заполнения для одного из чатов: 0| 643885| 476959| 1| 476977| 633077| 630664| 476966| 634567
|
||||||
|
start_answer= Привет! Я OCAB, открытый чат бот с ИИ для вашего чата!
|
||||||
|
top10_answer= Вот топ 10 самых разговорчивых пользователей чата:
|
||||||
|
|
||||||
|
[Roles]
|
||||||
|
user= Пользователь
|
||||||
|
moderator= Модератор
|
||||||
|
admin= Администратор
|
||||||
|
default_for_admin= 2
|
||||||
|
|
||||||
|
|
||||||
|
[Openai]
|
||||||
|
api_key=****
|
||||||
|
chat_model=gpt-3.5-turbo
|
||||||
|
story_model=
|
||||||
|
# Тут должен быть текст истории бота, но я его не показываю)))
|
||||||
|
max_token_count=4000
|
||||||
|
# максимальное количество токенов в сообщении
|
||||||
|
min_token_for_answer=800
|
||||||
|
# минимальное количество токенов в сообщении ответа бота (чем больше, тем более длинный ответ ГАРАНТИРОВАН)
|
||||||
|
|
||||||
|
[DataBase]
|
||||||
|
message_limit=3000
|
||||||
|
# Максимальное количество сообщений в базе данных
|
||||||
|
|
||||||
|
[AI_Dungeon]
|
||||||
|
use=openai
|
||||||
|
# "openai" or "YaGPT" Пока не используется
|
23
src/bot/config.yaml
Normal file
23
src/bot/config.yaml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
TELEGRAM:
|
||||||
|
TOKEN: 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
|
||||||
|
PRIVATE_ANSWER:
|
||||||
|
|
||||||
|
BOT:
|
||||||
|
ANSWER:
|
||||||
|
HELP_ANSWER:
|
||||||
|
START_ANSWER:
|
||||||
|
ABOUT_ANSWER:
|
||||||
|
|
||||||
|
ROLES:
|
||||||
|
ADMIN:
|
||||||
|
MODERATOR:
|
||||||
|
USER:
|
||||||
|
DEFAULT_FOR_ADMIN:
|
||||||
|
|
||||||
|
DATABASE:
|
||||||
|
MESSAGE_LIMIT:
|
||||||
|
|
||||||
|
GPT_MODULE:
|
||||||
|
TRIGGER_FRONT:
|
||||||
|
TRIGGER_ALL:
|
||||||
|
REPLY_IGNORE:
|
0
src/bot/core/__init__.py
Normal file
0
src/bot/core/__init__.py
Normal file
0
src/bot/core/database/__init__.py
Normal file
0
src/bot/core/database/__init__.py
Normal file
0
src/bot/core/database/methods/__init__.py
Normal file
0
src/bot/core/database/methods/__init__.py
Normal file
0
src/bot/core/database/models/__init__.py
Normal file
0
src/bot/core/database/models/__init__.py
Normal file
0
src/bot/core/filters/__init__.py
Normal file
0
src/bot/core/filters/__init__.py
Normal file
5
src/bot/core/filters/basic.py
Normal file
5
src/bot/core/filters/basic.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from aiogram.filters import BaseFilter
|
||||||
|
from aiogram.fsm.context import FSMContext
|
||||||
|
from aiogram.types import Message
|
||||||
|
|
||||||
|
# You filters
|
0
src/bot/core/handlers/__init__.py
Normal file
0
src/bot/core/handlers/__init__.py
Normal file
4
src/bot/core/handlers/basic.py
Normal file
4
src/bot/core/handlers/basic.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from aiogram.fsm.context import FSMContext
|
||||||
|
from aiogram.types import Message
|
||||||
|
|
||||||
|
# Your handlers
|
0
src/bot/core/keyboards/__init__.py
Normal file
0
src/bot/core/keyboards/__init__.py
Normal file
3
src/bot/core/keyboards/basic.py
Normal file
3
src/bot/core/keyboards/basic.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from aiogram.types import KeyboardButton, ReplyKeyboardMarkup
|
||||||
|
|
||||||
|
# Your keyboards
|
0
src/bot/core/middlewares/__init__.py
Normal file
0
src/bot/core/middlewares/__init__.py
Normal file
0
src/bot/core/states/__init__.py
Normal file
0
src/bot/core/states/__init__.py
Normal file
3
src/bot/core/states/api.py
Normal file
3
src/bot/core/states/api.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from aiogram.fsm.context import FSMContext
|
||||||
|
|
||||||
|
# Your funcs
|
5
src/bot/core/states/states.py
Normal file
5
src/bot/core/states/states.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from aiogram.fsm.state import State, StatesGroup
|
||||||
|
|
||||||
|
|
||||||
|
class MyState(StatesGroup):
|
||||||
|
state1 = State()
|
1
src/bot/core/text_of_buttons.py
Normal file
1
src/bot/core/text_of_buttons.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Here text of buttons
|
0
src/bot/core/utils/__init__.py
Normal file
0
src/bot/core/utils/__init__.py
Normal file
14
src/bot/core/utils/registry.py
Normal file
14
src/bot/core/utils/registry.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from aiogram import Dispatcher
|
||||||
|
|
||||||
|
|
||||||
|
def registry_middlewares(dp: Dispatcher):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def registry_handlers(dp: Dispatcher):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def registry(dp: Dispatcher):
|
||||||
|
registry_middlewares(dp)
|
||||||
|
registry_handlers(dp)
|
62
src/bot/core/utils/settings.py
Normal file
62
src/bot/core/utils/settings.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import openai
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class App:
|
||||||
|
telegram_token: str
|
||||||
|
openai_key: str
|
||||||
|
bot_trigger_front: list[str]
|
||||||
|
bot_trigger_all: list[str]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Database:
|
||||||
|
path: str
|
||||||
|
message_limit: int
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Config:
|
||||||
|
app: App
|
||||||
|
database: Database
|
||||||
|
|
||||||
|
def _clean_bot_trigger(bot_trigger_front, bot_trigger_all):
|
||||||
|
"""удаление лишних элементов массивов"""
|
||||||
|
bot_trigger_front.remove('')
|
||||||
|
bot_trigger_all.remove('')
|
||||||
|
|
||||||
|
|
||||||
|
def get_settings():
|
||||||
|
# Импорт переменных из файла .ini
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('core/config.ini')
|
||||||
|
|
||||||
|
bot_trigger_front = (config['Telegram']['bot_trigger_front']).split('|')
|
||||||
|
bot_trigger_all = (config['Telegram']['bot_trigger_all']).split('|')
|
||||||
|
|
||||||
|
_clean_bot_trigger(bot_trigger_front, bot_trigger_all)
|
||||||
|
|
||||||
|
|
||||||
|
return Config(
|
||||||
|
app=App(
|
||||||
|
telegram_token=config['Telegram']['token'],
|
||||||
|
openai_key=config['Openai']['api_key'],
|
||||||
|
bot_trigger_front = bot_trigger_front,
|
||||||
|
bot_trigger_all = bot_trigger_all,
|
||||||
|
),
|
||||||
|
database=Database(
|
||||||
|
path="core/database/data.db",
|
||||||
|
message_limit=int(config['DataBase']['message_limit']),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _openai_init(settings: Config):
|
||||||
|
openai.api_key = settings.app.openai_key
|
||||||
|
|
||||||
|
|
||||||
|
settings = get_settings()
|
||||||
|
_openai_init(settings)
|
28
src/bot/main.py
Normal file
28
src/bot/main.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from asyncio import run
|
||||||
|
|
||||||
|
from aiogram import Bot, Dispatcher
|
||||||
|
|
||||||
|
from core.utils.registry import registry
|
||||||
|
from core.utils.settings import settings
|
||||||
|
|
||||||
|
|
||||||
|
async def start(bot: Bot, dp: Dispatcher):
|
||||||
|
try:
|
||||||
|
await dp.start_polling(bot)
|
||||||
|
finally:
|
||||||
|
await bot.session.close()
|
||||||
|
# close db connection here
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
bot = Bot(token=settings.app.telegram_token)
|
||||||
|
|
||||||
|
dp = Dispatcher()
|
||||||
|
|
||||||
|
registry(dp)
|
||||||
|
|
||||||
|
run(start(bot, dp))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user