mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2025-11-28 10:21:55 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8953b2a15 | ||
|
|
de9a954fe3 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
.idea
|
||||
.vscode
|
||||
.env
|
||||
env
|
||||
venv
|
||||
__pycache__
|
||||
@@ -1,43 +0,0 @@
|
||||
[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" Пока не используется
|
||||
@@ -1,23 +0,0 @@
|
||||
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:
|
||||
@@ -1,5 +0,0 @@
|
||||
from aiogram.filters import BaseFilter
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import Message
|
||||
|
||||
# You filters
|
||||
@@ -1,4 +0,0 @@
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import Message
|
||||
|
||||
# Your handlers
|
||||
@@ -1,3 +0,0 @@
|
||||
from aiogram.types import KeyboardButton, ReplyKeyboardMarkup
|
||||
|
||||
# Your keyboards
|
||||
@@ -1,3 +0,0 @@
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
# Your funcs
|
||||
@@ -1,5 +0,0 @@
|
||||
from aiogram.fsm.state import State, StatesGroup
|
||||
|
||||
|
||||
class MyState(StatesGroup):
|
||||
state1 = State()
|
||||
@@ -1 +0,0 @@
|
||||
# Here text of buttons
|
||||
@@ -1,14 +0,0 @@
|
||||
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)
|
||||
@@ -1,62 +0,0 @@
|
||||
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)
|
||||
@@ -1,28 +0,0 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user