diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml deleted file mode 100644 index d9a0ab1..0000000 --- a/.idea/dataSources.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - postgresql - true - org.postgresql.Driver - jdbc:postgresql://localhost:5432/postgres - $ProjectFileDir$ - - - \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9770212 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.10 +WORKDIR /app +COPY requirements.txt requirements.txt +COPY admins_id.txt admins_id.txt +RUN python3 -m pip install --upgrade pip +RUN pip install -r requirements.txt +COPY . . \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..da3ee0e --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +generate: + alembic revision --m="$(NAME)" --autogenerate + +migrate: + alembic upgrade head + diff --git a/app/store/bot/admins_id.txt b/admins_id.txt similarity index 100% rename from app/store/bot/admins_id.txt rename to admins_id.txt diff --git a/alembic.ini b/alembic.ini index 46e74ba..510a45e 100644 --- a/alembic.ini +++ b/alembic.ini @@ -53,7 +53,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = postgresql+asyncpg://kts_user:kts_pass@localhost:5432/kts +sqlalchemy.url = postgresql+asyncpg://kts_user:kts_pass@db:5432/kts [post_write_hooks] diff --git a/app/store/bot/keyboards.py b/app/store/bot/keyboards.py index 1169dde..355f724 100644 --- a/app/store/bot/keyboards.py +++ b/app/store/bot/keyboards.py @@ -12,8 +12,8 @@ def get_but(text, color): } -keyboard_admin = { - "one_time": True, +keyboard = { + "one_time": False, "buttons": [ [ get_but("Регистрация!", "primary"), @@ -34,5 +34,5 @@ def get_but(text, color): ], } -keyboard_admin = json.dumps(keyboard_admin, ensure_ascii=False).encode("utf-8") -keyboard_admin = str(keyboard_admin.decode("utf-8")) +keyboard = json.dumps(keyboard, ensure_ascii=False).encode("utf-8") +keyboard = str(keyboard.decode("utf-8")) diff --git a/app/store/bot/manager.py b/app/store/bot/manager.py index 139f9be..fdc9492 100644 --- a/app/store/bot/manager.py +++ b/app/store/bot/manager.py @@ -6,7 +6,7 @@ from sqlalchemy import insert from sqlalchemy.sql import select, update as refresh, delete -from app.store.bot.keyboards import keyboard_admin +from app.store.bot.keyboards import keyboard from app.store.bot.lexicon import ( commands_for_users, commands_for_admins, @@ -35,7 +35,7 @@ def __init__( self.time_end = {} self.storage = {} self.reader = open( - "/home/olred/PycharmProjects/kts_project_template/app/store/bot/admins_id.txt", + "admins_id.txt", "r", encoding="utf-8", ) @@ -100,8 +100,7 @@ async def handle_updates(self, update): ) if ( len(update.object.body.split()) == 2 - and f"{lexicon_for_messages['ID_GROUP']} Исключить" - in update.object.body.split() + and "Исключить" in update.object.body.split() ): await self.command_kick_from_game( update.object.body.split()[1], update, game @@ -223,7 +222,7 @@ async def command_list_of_commands(self, update, game): "keyboard", update.object.chat_id, lexicon_for_messages["COMMANDS"], - keyboard_admin, + keyboard, ) ) else: @@ -235,7 +234,7 @@ async def command_list_of_commands(self, update, game): "keyboard", update.object.chat_id, lexicon_for_messages["COMMANDS"], - keyboard_user, + keyboard, ) ) else: @@ -734,6 +733,8 @@ async def command_start_game(self, update, game): ) ) elif len(game["users"]["participants"]) == 1: + game["kicked_users"]["kicked"] = [] + await self.set_kicked(update, game["kicked_users"], game) self.out_queue.put_nowait( ( "message", @@ -741,6 +742,8 @@ async def command_start_game(self, update, game): lexicon_for_messages["LITTLE_PEOPLE"], ) ) + game["kicked_users"]["kicked"] = [] + await self.set_kicked(update, game["kicked_users"], game) else: for i in range(3, 0, -1): self.out_queue.put_nowait( diff --git a/app/store/database/database.py b/app/store/database/database.py index 4830b70..3d84b2a 100644 --- a/app/store/database/database.py +++ b/app/store/database/database.py @@ -22,7 +22,7 @@ def __init__(self, app: "Application"): async def connect(self, *_: list, **__: dict) -> None: self._db = db self._engine = create_async_engine( - "postgresql+asyncpg://kts_user:kts_pass@localhost:5432/kts", + "postgresql+asyncpg://kts_user:kts_pass@db:5432/kts", echo=True, ) self.session = sessionmaker( diff --git a/app/store/vk_api/accessor.py b/app/store/vk_api/accessor.py index c1209ab..f21f367 100644 --- a/app/store/vk_api/accessor.py +++ b/app/store/vk_api/accessor.py @@ -50,7 +50,6 @@ def _build_query(host: str, method: str, params: dict) -> str: if "v" not in params: params["v"] = "5.132" url += "&".join([f"{k}={v}" for k, v in params.items()]) - print(url) return url async def _get_long_poll_service(self): @@ -163,7 +162,6 @@ async def send_message( "access_token": self.app.config.bot.token, } else: - print(1) parametrs = { "random_id": random.randint(1, 2**32), "peer_id": message.chat_id, diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f15a8d7 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,26 @@ +version: '3.5' + +services: + db: + container_name: db + restart: on-failure + ports: + - "5433:5432" + environment: + - POSTGRES_PASSWORD=kts_pass + - POSTGRES_USER=kts_user + - POSTGRES_DB=kts + image: postgres + volumes: + - pgdata:/var/lib/postgresql/data + bot: + image: olred/vk_bot_project:my-image + command: sh -c "make migrate && python run_bot.py" + restart: always + depends_on: + - db + +volumes: + pgdata: + + diff --git a/etc/config.yaml b/etc/config.yaml deleted file mode 100644 index 1daee74..0000000 --- a/etc/config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -debug: true -web: - host: 127.0.0.1 - port: 8000 - -sentry: - dsn: - env: dev - -store: {} diff --git a/requirements.txt b/requirements.txt index 5a84433..ae7c9ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,21 @@ +aio-pika==9.0.4 aiohttp==3.8.3 aiohttp-apispec==2.2.3 aiohttp-session==2.12.0 +aiormq==6.7.2 aiosignal==1.3.1 alembic==1.9.3 apispec==3.3.2 async-timeout==4.0.2 asyncpg==0.27.0 attrs==22.2.0 +black==22.6.0 cffi==1.15.1 charset-normalizer==2.1.1 +click==8.1.3 coverage==7.1.0 cryptography==39.0.1 +exceptiongroup==1.1.0 frozenlist==1.3.3 greenlet==2.0.2 idna==3.4 @@ -18,15 +23,23 @@ iniconfig==2.0.0 Jinja2==3.1.2 Mako==1.2.4 MarkupSafe==2.1.2 +marshmallow==3.19.0 multidict==6.0.4 +mypy-extensions==1.0.0 packaging==23.0 +pamqp==3.2.1 +pathspec==0.11.0 +pika==1.3.1 +platformdirs==3.0.0 pluggy==1.0.0 +py==1.11.0 pycparser==2.21 pyparsing==3.0.9 pytest==7.2.1 pytest-aiohttp==1.0.4 pytest-asyncio==0.20.3 pytest-cov==4.0.0 +pytest-env==0.6.2 pytest-mock==3.10.0 python-dateutil==2.8.2 python-dotenv==0.21.1 @@ -34,7 +47,7 @@ PyYAML==6.0 simplejson==3.18.3 six==1.16.0 SQLAlchemy==2.0.3 +tomli==2.0.1 typing_extensions==4.4.0 webargs==5.5.3 yarl==1.8.2 -docker-compose=1.29.2-1