From ce934affe34fc82bcfbdf8b64745c558d2be6032 Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Sun, 20 Nov 2022 02:22:35 +0300 Subject: [PATCH] =?UTF-8?q?backend=20+=20telegram:=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=20chat=5Fid=20=D1=83=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/migrations/versions/231e5697b63e_.py | 128 ------------------ backend/migrations/versions/57b47e18fdab_.py | 68 ---------- .../{370968e335df_.py => c3b392fdf575_.py} | 25 +++- backend/textsouls/models.py | 1 + telegram/textsouls/handlers/control.py | 1 + telegram/textsouls/main.py | 22 ++- 6 files changed, 43 insertions(+), 202 deletions(-) delete mode 100644 backend/migrations/versions/231e5697b63e_.py delete mode 100644 backend/migrations/versions/57b47e18fdab_.py rename backend/migrations/versions/{370968e335df_.py => c3b392fdf575_.py} (65%) diff --git a/backend/migrations/versions/231e5697b63e_.py b/backend/migrations/versions/231e5697b63e_.py deleted file mode 100644 index 3a062db..0000000 --- a/backend/migrations/versions/231e5697b63e_.py +++ /dev/null @@ -1,128 +0,0 @@ -"""empty message - -Revision ID: 231e5697b63e -Revises: 57b47e18fdab -Create Date: 2022-11-19 21:56:35.469495 - -""" -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import mysql - -# revision identifiers, used by Alembic. -revision = '231e5697b63e' -down_revision = '57b47e18fdab' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('character_classes', schema=None) as batch_op: - batch_op.alter_column('endurance_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('strength_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('agility_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('defence_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('wisdom_koef', - existing_type=mysql.FLOAT(), - nullable=False) - - with op.batch_alter_table('character_races', schema=None) as batch_op: - batch_op.alter_column('endurance_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('strength_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('agility_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('defence_koef', - existing_type=mysql.FLOAT(), - nullable=False) - batch_op.alter_column('wisdom_koef', - existing_type=mysql.FLOAT(), - nullable=False) - - with op.batch_alter_table('characters', schema=None) as batch_op: - batch_op.alter_column('endurance_base', - existing_type=mysql.INTEGER(), - nullable=False) - batch_op.alter_column('strength_base', - existing_type=mysql.INTEGER(), - nullable=False) - batch_op.alter_column('agility_base', - existing_type=mysql.INTEGER(), - nullable=False) - batch_op.alter_column('defence_base', - existing_type=mysql.INTEGER(), - nullable=False) - batch_op.alter_column('wisdom_base', - existing_type=mysql.INTEGER(), - nullable=False) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('characters', schema=None) as batch_op: - batch_op.alter_column('wisdom_base', - existing_type=mysql.INTEGER(), - nullable=True) - batch_op.alter_column('defence_base', - existing_type=mysql.INTEGER(), - nullable=True) - batch_op.alter_column('agility_base', - existing_type=mysql.INTEGER(), - nullable=True) - batch_op.alter_column('strength_base', - existing_type=mysql.INTEGER(), - nullable=True) - batch_op.alter_column('endurance_base', - existing_type=mysql.INTEGER(), - nullable=True) - - with op.batch_alter_table('character_races', schema=None) as batch_op: - batch_op.alter_column('wisdom_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('defence_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('agility_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('strength_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('endurance_koef', - existing_type=mysql.FLOAT(), - nullable=True) - - with op.batch_alter_table('character_classes', schema=None) as batch_op: - batch_op.alter_column('wisdom_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('defence_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('agility_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('strength_koef', - existing_type=mysql.FLOAT(), - nullable=True) - batch_op.alter_column('endurance_koef', - existing_type=mysql.FLOAT(), - nullable=True) - - # ### end Alembic commands ### diff --git a/backend/migrations/versions/57b47e18fdab_.py b/backend/migrations/versions/57b47e18fdab_.py deleted file mode 100644 index e58cf82..0000000 --- a/backend/migrations/versions/57b47e18fdab_.py +++ /dev/null @@ -1,68 +0,0 @@ -"""empty message - -Revision ID: 57b47e18fdab -Revises: 370968e335df -Create Date: 2022-11-19 20:40:22.680225 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '57b47e18fdab' -down_revision = '370968e335df' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('character_classes', schema=None) as batch_op: - batch_op.add_column(sa.Column('endurance_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('strength_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('agility_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('defence_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('wisdom_koef', sa.Float(), nullable=True)) - - with op.batch_alter_table('character_races', schema=None) as batch_op: - batch_op.add_column(sa.Column('endurance_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('strength_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('agility_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('defence_koef', sa.Float(), nullable=True)) - batch_op.add_column(sa.Column('wisdom_koef', sa.Float(), nullable=True)) - - with op.batch_alter_table('characters', schema=None) as batch_op: - batch_op.add_column(sa.Column('endurance_base', sa.Integer(), nullable=True)) - batch_op.add_column(sa.Column('strength_base', sa.Integer(), nullable=True)) - batch_op.add_column(sa.Column('agility_base', sa.Integer(), nullable=True)) - batch_op.add_column(sa.Column('defence_base', sa.Integer(), nullable=True)) - batch_op.add_column(sa.Column('wisdom_base', sa.Integer(), nullable=True)) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('characters', schema=None) as batch_op: - batch_op.drop_column('wisdom_base') - batch_op.drop_column('defence_base') - batch_op.drop_column('agility_base') - batch_op.drop_column('strength_base') - batch_op.drop_column('endurance_base') - - with op.batch_alter_table('character_races', schema=None) as batch_op: - batch_op.drop_column('wisdom_koef') - batch_op.drop_column('defence_koef') - batch_op.drop_column('agility_koef') - batch_op.drop_column('strength_koef') - batch_op.drop_column('endurance_koef') - - with op.batch_alter_table('character_classes', schema=None) as batch_op: - batch_op.drop_column('wisdom_koef') - batch_op.drop_column('defence_koef') - batch_op.drop_column('agility_koef') - batch_op.drop_column('strength_koef') - batch_op.drop_column('endurance_koef') - - # ### end Alembic commands ### diff --git a/backend/migrations/versions/370968e335df_.py b/backend/migrations/versions/c3b392fdf575_.py similarity index 65% rename from backend/migrations/versions/370968e335df_.py rename to backend/migrations/versions/c3b392fdf575_.py index 1134709..906ca6a 100644 --- a/backend/migrations/versions/370968e335df_.py +++ b/backend/migrations/versions/c3b392fdf575_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 370968e335df +Revision ID: c3b392fdf575 Revises: -Create Date: 2022-11-19 06:44:47.040525 +Create Date: 2022-11-20 00:31:12.952336 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '370968e335df' +revision = 'c3b392fdf575' down_revision = None branch_labels = None depends_on = None @@ -21,23 +21,35 @@ def upgrade(): op.create_table('character_classes', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=True), + sa.Column('endurance_koef', sa.Float(), nullable=False), + sa.Column('strength_koef', sa.Float(), nullable=False), + sa.Column('agility_koef', sa.Float(), nullable=False), + sa.Column('defence_koef', sa.Float(), nullable=False), + sa.Column('wisdom_koef', sa.Float(), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') ) op.create_table('character_races', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=True), + sa.Column('endurance_koef', sa.Float(), nullable=False), + sa.Column('strength_koef', sa.Float(), nullable=False), + sa.Column('agility_koef', sa.Float(), nullable=False), + sa.Column('defence_koef', sa.Float(), nullable=False), + sa.Column('wisdom_koef', sa.Float(), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') ) op.create_table('users', sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False), + sa.Column('chat_id', sa.BigInteger(), nullable=False), sa.Column('first_name', sa.String(length=255), nullable=True), sa.Column('last_name', sa.String(length=255), nullable=True), sa.Column('username', sa.String(length=255), nullable=False), sa.Column('registered_on', sa.DateTime(), nullable=False), sa.Column('is_admin', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('id') + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('chat_id') ) op.create_table('characters', sa.Column('id', sa.Integer(), nullable=False), @@ -46,6 +58,11 @@ def upgrade(): sa.Column('character_race', sa.Integer(), nullable=False), sa.Column('character_class', sa.Integer(), nullable=False), sa.Column('created_on', sa.DateTime(), nullable=False), + sa.Column('endurance_base', sa.Integer(), nullable=False), + sa.Column('strength_base', sa.Integer(), nullable=False), + sa.Column('agility_base', sa.Integer(), nullable=False), + sa.Column('defence_base', sa.Integer(), nullable=False), + sa.Column('wisdom_base', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['character_class'], ['character_classes.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['character_race'], ['character_races.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['owner'], ['users.id'], ondelete='CASCADE'), diff --git a/backend/textsouls/models.py b/backend/textsouls/models.py index 14a5541..0149726 100644 --- a/backend/textsouls/models.py +++ b/backend/textsouls/models.py @@ -14,6 +14,7 @@ class User(db.Model, SerializerMixin): serialize_rules = ("-character",) id = db.Column(db.BigInteger, primary_key=True, autoincrement=False) + chat_id = db.Column(db.BigInteger, nullable=False, unique=True) first_name = db.Column(db.String(255), nullable=True) last_name = db.Column(db.String(255), nullable=True) username = db.Column(db.String(255), nullable=False) diff --git a/telegram/textsouls/handlers/control.py b/telegram/textsouls/handlers/control.py index 18da026..5ba9997 100644 --- a/telegram/textsouls/handlers/control.py +++ b/telegram/textsouls/handlers/control.py @@ -16,6 +16,7 @@ async def start(message, state): tg_user = message.from_user ts_user = { "id": tg_user.id, + "chat_id": message.chat.id, "first_name": tg_user.first_name, "last_name": tg_user.last_name, "username": tg_user.username, diff --git a/telegram/textsouls/main.py b/telegram/textsouls/main.py index 938545c..cad7616 100644 --- a/telegram/textsouls/main.py +++ b/telegram/textsouls/main.py @@ -2,16 +2,34 @@ import json from fastapi import FastAPI +import asyncio + from aiogram import Bot, Dispatcher from aiogram.fsm.storage.memory import MemoryStorage +from textsouls.handlers import control +from textsouls.handlers import character_creation + with open("textsouls/config.json") as config_file: config_data = json.load(config_file) app = FastAPI() -bot = Bot(token=config_data["MAIN_SETTINGS"]["BOT_TOKEN"]) -dp = Dispatcher(storage=MemoryStorage()) + +async def start_bot(): + bot = Bot(token=config_data["MAIN_SETTINGS"]["BOT_TOKEN"]) + dp = Dispatcher(storage=MemoryStorage()) + + dp.include_router(control.router) + dp.include_router(character_creation.router) + + await bot.delete_webhook(drop_pending_updates=True) + await dp.start_polling(bot) + + +@app.on_event("startup") +async def startup_event(): + asyncio.create_task(start_bot()) @app.get("/")