mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2024-12-23 16:23:01 +03:00
Merge remote-tracking branch 'origin/OCAB-V2' into OCAB-V2
# Conflicts: # src/core/main.py
This commit is contained in:
commit
2cbe898a57
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.env
|
.env
|
||||||
env
|
env
|
||||||
|
.venv
|
||||||
venv
|
venv
|
||||||
__pycache__
|
__pycache__
|
||||||
OCAB.db
|
OCAB.db
|
||||||
|
@ -51,7 +51,7 @@ OCAB - это бот для Telegram, который призван помочь
|
|||||||
|
|
||||||
## Технологический стек
|
## Технологический стек
|
||||||
|
|
||||||
* Python 3.11.6 - основной язык программирования.
|
* Python 3.11.6 или выше - основной язык программирования.
|
||||||
* SQLite 3 - база данных для хранения информации о чате и пользователях.
|
* SQLite 3 - база данных для хранения информации о чате и пользователях.
|
||||||
* [Poetry](https://gitflic.ru/project/armatik/ocab/blob?file=how-to%20install%20deps.md&branch=OCAB-V2) - менеджер зависимостей.
|
* [Poetry](https://gitflic.ru/project/armatik/ocab/blob?file=how-to%20install%20deps.md&branch=OCAB-V2) - менеджер зависимостей.
|
||||||
* aiogram 3 - библиотека для работы с Telegram API.
|
* aiogram 3 - библиотека для работы с Telegram API.
|
||||||
|
@ -1,9 +1,45 @@
|
|||||||
Ставим poetry:
|
## Poetry
|
||||||
```bash
|
|
||||||
pip install poetry
|
### Установка с официального сайта
|
||||||
|
|
||||||
|
```shell
|
||||||
|
curl -sSL https://install.python-poetry.org | python3 -
|
||||||
```
|
```
|
||||||
|
|
||||||
Ставим зависимости:
|
### Установка с PyPi
|
||||||
```bash
|
|
||||||
|
```shell
|
||||||
|
python3 -m pip install poetry
|
||||||
|
```
|
||||||
|
|
||||||
|
## Зависимости
|
||||||
|
|
||||||
|
### Добавление зависимости
|
||||||
|
```shell
|
||||||
|
poetry add NAME
|
||||||
|
```
|
||||||
|
`NAME` - название зависимости.
|
||||||
|
|
||||||
|
### Установка зависимостей
|
||||||
|
```shell
|
||||||
poetry install
|
poetry install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Обновление зависимостей
|
||||||
|
```shell
|
||||||
|
poetry update
|
||||||
|
```
|
||||||
|
|
||||||
|
## Виртуальное окружение
|
||||||
|
|
||||||
|
### Создание/активация
|
||||||
|
```shell
|
||||||
|
poetry shell
|
||||||
|
```
|
||||||
|
|
||||||
|
### Настройка
|
||||||
|
|
||||||
|
Хранить окружение внутри проекта
|
||||||
|
```shell
|
||||||
|
poetry config virtualenvs.in-project true
|
||||||
```
|
```
|
2
poetry.lock
generated
2
poetry.lock
generated
@ -824,5 +824,5 @@ multidict = ">=4.0"
|
|||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "3.11.6"
|
python-versions = "^3.11.6"
|
||||||
content-hash = "dea2f6ada13efef77325b219721fda6515a4c203c31e47dcafe8726e5d5f9ac6"
|
content-hash = "dea2f6ada13efef77325b219721fda6515a4c203c31e47dcafe8726e5d5f9ac6"
|
||||||
|
@ -2,11 +2,18 @@
|
|||||||
name = "ocab"
|
name = "ocab"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Your Name <you@example.com>"]
|
license = "GPL-3.0-only"
|
||||||
|
authors = ["Семён Фомченков <s.fomchenkov@yandex.ru>"]
|
||||||
|
maintainers = [
|
||||||
|
"Илья Женецкий <ilya_zhenetskij@vk.com>",
|
||||||
|
"qualimock <qualimock@yandex.ru>",
|
||||||
|
"Кирилл Уницаев fiersik.kouji@yandex.ru",
|
||||||
|
]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
repository = "https://gitflic.ru/project/armatik/ocab"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "3.11.6"
|
python = "^3.11.6"
|
||||||
aiogram = "^3.2.0"
|
aiogram = "^3.2.0"
|
||||||
peewee = "^3.17.0"
|
peewee = "^3.17.0"
|
||||||
pyyaml = "^6.0.1"
|
pyyaml = "^6.0.1"
|
||||||
|
@ -1 +1,2 @@
|
|||||||
import service
|
import src.service
|
||||||
|
import src.core
|
@ -1,17 +1,19 @@
|
|||||||
from src.modules.standard.config.config import get_config
|
from routers import include_routers
|
||||||
from src.modules.standard.database.models.base import database
|
from src.modules.standard.config.config import get_telegram_token
|
||||||
from src.modules.standard.database.db_api import connect_database
|
from src.modules.standard.database.api import connect_database, create_tables
|
||||||
|
|
||||||
from asyncio import run
|
from asyncio import run
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
|
|
||||||
async def main():
|
|
||||||
|
async def main(bot: Bot):
|
||||||
try:
|
try:
|
||||||
database = connect_database()
|
database, path = connect_database()
|
||||||
bot = Bot(token=get_config()["TELEGRAM"]["TOKEN"])
|
database.connect()
|
||||||
|
create_tables(database)
|
||||||
|
|
||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
|
await include_routers(dp)
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -20,4 +22,5 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run(main())
|
bot = Bot(token=get_telegram_token())
|
||||||
|
run(main(bot))
|
||||||
|
11
src/core/routers.py
Normal file
11
src/core/routers.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from aiogram import Dispatcher
|
||||||
|
|
||||||
|
from src.modules.standard.admin.routers import router as admin_router
|
||||||
|
|
||||||
|
|
||||||
|
async def include_routers(dp: Dispatcher):
|
||||||
|
"""
|
||||||
|
Подключение роутеров в бота
|
||||||
|
dp.include_router()
|
||||||
|
"""
|
||||||
|
dp.include_router(admin_router)
|
1
src/modules/standard/admin/__init__.py
Normal file
1
src/modules/standard/admin/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import routers
|
13
src/modules/standard/admin/handlers.py
Normal file
13
src/modules/standard/admin/handlers.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from aiogram import Bot
|
||||||
|
from aiogram.types import Message
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_message(message: Message, bot: Bot):
|
||||||
|
reply_message_id = message.reply_to_message.message_id
|
||||||
|
await bot.delete_message(message.chat.id, reply_message_id)
|
||||||
|
|
||||||
|
async def error_access(message: Message, bot: Bot):
|
||||||
|
await message.reply("Вы не админ/модератор")
|
||||||
|
|
||||||
|
async def get_chat_id(message: Message, bot: Bot):
|
||||||
|
await message.reply(f"ID данного чата: `{message.chat.id}`", parse_mode="MarkdownV2")
|
6
src/modules/standard/admin/info.json
Normal file
6
src/modules/standard/admin/info.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "Admin",
|
||||||
|
"description": "Модуль для работы с админкой",
|
||||||
|
"author": "OCAB Team",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
11
src/modules/standard/admin/routers.py
Normal file
11
src/modules/standard/admin/routers.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from aiogram import Router, F
|
||||||
|
|
||||||
|
from src.modules.standard.admin.handlers import delete_message, error_access, get_chat_id
|
||||||
|
from src.modules.standard.filters.admin import ChatModerOrAdminFilter
|
||||||
|
|
||||||
|
router = Router()
|
||||||
|
router.message.register(get_chat_id, ChatModerOrAdminFilter(), F.text == '/chatID')
|
||||||
|
|
||||||
|
router.message.register(delete_message, ChatModerOrAdminFilter(), F.text == '/rm')
|
||||||
|
router.message.register(error_access, F.text == '/rm')
|
||||||
|
router.message.register(error_access, F.text == '/chatID')
|
@ -12,15 +12,19 @@ def get_config(is_test: bool = False) -> dict:
|
|||||||
with open(path, 'r') as file:
|
with open(path, 'r') as file:
|
||||||
return yaml.full_load(file)
|
return yaml.full_load(file)
|
||||||
|
|
||||||
|
config = get_config()
|
||||||
|
|
||||||
|
def get_telegram_token() -> str:
|
||||||
|
return config["TELEGRAM"]["TOKEN"]
|
||||||
|
|
||||||
def get_yandexgpt_token() -> str:
|
def get_yandexgpt_token() -> str:
|
||||||
return get_config()["YANDEX_GPT_TOKEN"]
|
return config["YANDEX_GPT_TOKEN"]
|
||||||
|
|
||||||
def get_yandexgpt_catalog_id() -> str:
|
def get_yandexgpt_catalog_id() -> str:
|
||||||
return get_config()["YANDEX_GPT_CATALOG_ID"]
|
return config["YANDEX_GPT_CATALOG_ID"]
|
||||||
|
|
||||||
def get_yandexgpt_prompt() -> str:
|
def get_yandexgpt_prompt() -> str:
|
||||||
return get_config()["YANDEX_GPT_PROMPT"]
|
return config["YANDEX_GPT_PROMPT"]
|
||||||
|
|
||||||
def get_access_rights() -> dict:
|
def get_access_rights() -> dict:
|
||||||
return get_config()["ACCESS_RIGHTS"]
|
return get_config()["ACCESS_RIGHTS"]
|
||||||
|
@ -22,6 +22,8 @@ def connect_database(is_test: bool = False, module: str | None = None):
|
|||||||
Chats._meta.database = _database
|
Chats._meta.database = _database
|
||||||
Messages._meta.database = _database
|
Messages._meta.database = _database
|
||||||
Users._meta.database = _database
|
Users._meta.database = _database
|
||||||
|
UserStats._meta.database = _database
|
||||||
|
ChatStats._meta.database = _database
|
||||||
|
|
||||||
return _database, f"{db_path}/OCAB.db"
|
return _database, f"{db_path}/OCAB.db"
|
||||||
|
|
||||||
|
0
src/modules/standard/filters/__init__.py
Normal file
0
src/modules/standard/filters/__init__.py
Normal file
13
src/modules/standard/filters/admin.py
Normal file
13
src/modules/standard/filters/admin.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from aiogram.filters import BaseFilter
|
||||||
|
from aiogram.types import Message
|
||||||
|
from aiogram import Bot
|
||||||
|
|
||||||
|
from src.modules.standard.roles.api import Roles
|
||||||
|
|
||||||
|
class ChatModerOrAdminFilter(BaseFilter):
|
||||||
|
async def __call__(self, message: Message, bot: Bot) -> bool:
|
||||||
|
user_id = message.from_user.id
|
||||||
|
roles = Roles()
|
||||||
|
admins = await bot.get_chat_administrators(message.chat.id)
|
||||||
|
return await roles.check_admin_permission(user_id) or \
|
||||||
|
await roles.check_moderator_permission(user_id) or any(user_id == admin.user.id for admin in admins)
|
6
src/modules/standard/filters/info.json
Normal file
6
src/modules/standard/filters/info.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "Filters",
|
||||||
|
"description": "Модуль с фильтрами",
|
||||||
|
"author": "OCAB Team",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user