Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗️ Refactor project structure and update major dependencies #3

Open
wants to merge 148 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
cb8584d
🚚 Create src folder and move all the code into it
DavidRomanovizc Mar 7, 2024
1275b12
🔥 remove app.py
DavidRomanovizc Mar 7, 2024
26758d9
🎨 move registration func of the middleware and filters to bot.py
DavidRomanovizc Mar 7, 2024
336eb08
♻️ fix imports
DavidRomanovizc Mar 7, 2024
aedc7c7
🔧 update paths
DavidRomanovizc Mar 7, 2024
9563811
🔥 remove utils folder
DavidRomanovizc Mar 7, 2024
c454359
🧪 add falling tests
DavidRomanovizc Mar 7, 2024
5f00a56
🔥 remove states folder
DavidRomanovizc Mar 7, 2024
8d4a4e9
🔥 remove folders
DavidRomanovizc Mar 7, 2024
256fefa
♻️ fix imports
DavidRomanovizc Mar 7, 2024
dde289e
🔥 drop django
DavidRomanovizc Mar 24, 2024
276994b
🗑️ Move legacy code to deprecated folder for future cleanup
DavidRomanovizc Mar 24, 2024
bbc2a02
🔥 remove loader.py
DavidRomanovizc Mar 24, 2024
178534d
📝 Update "About" section
DavidRomanovizc Mar 24, 2024
70e5a34
🚧⬆️ Working on dependencies in the process
DavidRomanovizc Mar 24, 2024
8cf837f
🔥 remove deprecated tests
DavidRomanovizc Mar 24, 2024
475610a
🔥 remove localization
DavidRomanovizc Mar 24, 2024
252696c
🔥 drop django
DavidRomanovizc Mar 24, 2024
57c93b5
🔥 drop brandbook
DavidRomanovizc Mar 24, 2024
7cb7394
⚰️ remove interaction with db
DavidRomanovizc Mar 24, 2024
bc1faf4
🤡 Quiet and sound of tumbleweed
DavidRomanovizc Mar 24, 2024
f0107c2
♻️ minor fixes
DavidRomanovizc Mar 24, 2024
7e0b1cf
🏷️ add types file
DavidRomanovizc Mar 24, 2024
ac7dc3c
⚰️ remove dead code
DavidRomanovizc Mar 24, 2024
6cd9c81
🚧 Update code to work with new library version
DavidRomanovizc Mar 24, 2024
9b3d1f2
🚚 rename default folder to reply
DavidRomanovizc Mar 24, 2024
1adc7f1
✨ Add funcs for sending and broadcasting messages with error handling
DavidRomanovizc Mar 24, 2024
ac5abbd
✨ Add start handler
DavidRomanovizc Mar 24, 2024
72f8167
♻️ minor fixes
DavidRomanovizc Mar 24, 2024
45b8ee2
🎉 frontend for tg mini apps
DavidRomanovizc Apr 23, 2024
27244d6
⬆️ Upgrade dependencies
DavidRomanovizc Apr 23, 2024
43b105d
⚰️ remove requirements.txt
DavidRomanovizc Apr 23, 2024
1cf9868
📝 update badges
DavidRomanovizc Apr 23, 2024
7598d9e
🔧 remove unused var and add new env var
DavidRomanovizc Apr 23, 2024
645fe52
🔧 add black alias
DavidRomanovizc Apr 23, 2024
c7869d4
🗑️ deprecate code that needs to be cleaned up
DavidRomanovizc Apr 23, 2024
4c09128
⚰️ remove yoomoney
DavidRomanovizc Apr 23, 2024
6a6421c
♻️ minor fixes
DavidRomanovizc Apr 23, 2024
f2968c2
🏷️ update Handler type
DavidRomanovizc Apr 23, 2024
2028195
🏷️ add types
DavidRomanovizc Apr 23, 2024
70c4a8e
♻️ minor fixes
DavidRomanovizc Apr 23, 2024
4373c9c
🔥 remove files
DavidRomanovizc Apr 23, 2024
9caaf6c
🚧 rewriting middlewares
DavidRomanovizc Apr 23, 2024
52eaaca
💄 update commands
DavidRomanovizc Apr 23, 2024
e044bfe
✨ add func for handle user req
DavidRomanovizc Apr 23, 2024
8c528d7
♻️ minor fixes
DavidRomanovizc Apr 23, 2024
f5154d0
🏗️ update keyboards
DavidRomanovizc Apr 23, 2024
e7af919
♻️ minor fixes
DavidRomanovizc Apr 23, 2024
9d6d8a6
♻️ minor fixes
DavidRomanovizc Apr 23, 2024
f4a6fa4
🛂 generation signature for auth
DavidRomanovizc Apr 23, 2024
94be363
✨ add handler for signin/signup
DavidRomanovizc Apr 23, 2024
2325b89
📝 update description
DavidRomanovizc Apr 26, 2024
e2217fc
💄 update frontend
DavidRomanovizc Apr 26, 2024
e3c5764
📝 remove unused env var from table
DavidRomanovizc Apr 26, 2024
0265eed
🏷️ add types
DavidRomanovizc Apr 26, 2024
deba550
💄 add web app
DavidRomanovizc Apr 26, 2024
d2d39b7
✨ add about project handler
DavidRomanovizc Apr 26, 2024
10b315b
🚧 user handler
DavidRomanovizc Apr 26, 2024
a7f52d1
🚨 fix whitespace
DavidRomanovizc Apr 29, 2024
7b2d25c
🚨 fix whitespace
DavidRomanovizc Apr 29, 2024
768cc23
⬆️ upgrade dependencies
DavidRomanovizc Apr 29, 2024
85df676
🔧 add pre-commit
DavidRomanovizc Apr 29, 2024
3aab80b
🚨 ignore f403
DavidRomanovizc Apr 29, 2024
af16616
🏷️ add typing
DavidRomanovizc Apr 29, 2024
bcd0b0a
✨ add middleware for handle deactivated user and not auth
DavidRomanovizc Apr 29, 2024
ec26a1b
♻️ minor fixes
DavidRomanovizc Apr 29, 2024
eafefc5
🚧 on handlers
DavidRomanovizc Apr 29, 2024
149d262
🚨 fix mypy warnings
DavidRomanovizc Apr 29, 2024
7111ae6
⚰️ remove unused services
DavidRomanovizc May 6, 2024
0276f8a
⬆️ upgrade dependencies
DavidRomanovizc May 6, 2024
5a0f49c
💄 update login form
DavidRomanovizc May 6, 2024
2943b31
♻️ minor fixes
DavidRomanovizc May 6, 2024
fb13c9a
✨ add handler for login form
DavidRomanovizc May 6, 2024
fd13de7
improve performance
DavidRomanovizc May 6, 2024
d41fd18
⬆️ upgrade dependencies
DavidRomanovizc May 9, 2024
b6eb93a
🌐 add localization
DavidRomanovizc May 9, 2024
10db2e8
📝 update DEVELOPMENT.md
DavidRomanovizc May 9, 2024
4036ce1
✨ add i18n
DavidRomanovizc May 9, 2024
e5c9be7
🚧 developing profile
DavidRomanovizc May 9, 2024
4dae2f6
♻️ minor fixes
DavidRomanovizc May 9, 2024
50dc944
💄 add profile menu
DavidRomanovizc May 9, 2024
c7d682b
✨ add rate limiter
DavidRomanovizc May 10, 2024
fb3e147
🔧 add env var for redis
DavidRomanovizc May 10, 2024
9ce87be
🔧 update RedisConfig
DavidRomanovizc May 10, 2024
fc3d952
📝 update badges
DavidRomanovizc May 10, 2024
0308bbc
⬆️ upgrade dependencies
DavidRomanovizc May 16, 2024
4f20526
✅ add e2e tests
DavidRomanovizc May 16, 2024
0a60f0d
🧑‍💻 add helpers func for testing
DavidRomanovizc May 16, 2024
566a840
♻️ minor fixes
DavidRomanovizc May 16, 2024
3474dad
🔐 add env vars for testing
DavidRomanovizc May 16, 2024
6c26256
⚰️ remove dead external api
DavidRomanovizc Jun 6, 2024
d85bd3b
➕ add yandex-geo
DavidRomanovizc Jun 6, 2024
14f1cb5
⬆️ upgrade dependencies
DavidRomanovizc Jun 6, 2024
28ae7e7
♻️ refactor code
DavidRomanovizc Jun 6, 2024
e2f96b3
💄 update user menu
DavidRomanovizc Jun 6, 2024
2c9bbcd
🚧 add base implementation for profile
DavidRomanovizc Jun 6, 2024
e98dbb0
🚸 diff buttons in dependence on profile
DavidRomanovizc Jun 6, 2024
512ae12
🚨 fix import with isort
DavidRomanovizc Jun 14, 2024
b0e2ac2
🚚 move states.py to deprecated
DavidRomanovizc Jun 14, 2024
1af0e87
🚨 fix import with isort
DavidRomanovizc Jun 14, 2024
b6c9ee3
🚨 fix import with isort
DavidRomanovizc Jun 14, 2024
5e314e4
💡 add todo
DavidRomanovizc Jun 14, 2024
0f80812
💄 add new keyboards
DavidRomanovizc Jun 14, 2024
055633f
💡 add todo
DavidRomanovizc Jun 14, 2024
b9bb49c
🚧 add base form for fill profile
DavidRomanovizc Jun 14, 2024
5c1b653
🧑‍💻 add middleware for working with media groups
DavidRomanovizc Jun 14, 2024
501b83d
🚨 fix linter warnings
DavidRomanovizc Jun 14, 2024
9f53697
⚰️ remove dead states and add new
DavidRomanovizc Jun 14, 2024
bf053b9
💡 comment the registration of ThrottlingMiddleware
DavidRomanovizc Jun 14, 2024
4f0e7e2
🗑️ deprecate class that needs to be cleaned up
DavidRomanovizc Jun 16, 2024
be547d9
🚚 move exceptions from middlewares to misc
DavidRomanovizc Jun 16, 2024
9ede94b
♻️ minor fixes
DavidRomanovizc Jun 16, 2024
0410354
♻️ minor fixes
DavidRomanovizc Jun 16, 2024
e80800d
💄 add new menus
DavidRomanovizc Jun 16, 2024
49143b0
🚸 handling back button
DavidRomanovizc Jun 16, 2024
f1bd8cf
💬 update text
DavidRomanovizc Jun 16, 2024
1dd60d5
⬆️ update que-sdk to 0.2.0
DavidRomanovizc Jun 27, 2024
937052f
➕ add aiogram-calendar
DavidRomanovizc Jun 27, 2024
f8054df
⬆️ upgrade dependencies
DavidRomanovizc Jun 27, 2024
f5e7a87
🔧 add folder for photos
DavidRomanovizc Jun 27, 2024
49612d1
🙈 exclude .gitkeep from photos
DavidRomanovizc Jun 27, 2024
475aba2
💬 a more intuitive label for user
DavidRomanovizc Jun 27, 2024
37849b9
✨ add client for working with geo
DavidRomanovizc Jun 27, 2024
ea9392e
✨ update misc middleware for working with geo
DavidRomanovizc Jun 27, 2024
77e10ea
♻️ minor fixes
DavidRomanovizc Jun 27, 2024
9bcb90d
🔧 add var for working with geo client
DavidRomanovizc Jun 27, 2024
f5d0c8e
✨ add new field state
DavidRomanovizc Jun 27, 2024
f7429eb
💄 add new keyboard
DavidRomanovizc Jun 27, 2024
c4bf8c4
🚧 draft work: profile, user
DavidRomanovizc Jun 27, 2024
b8ce2e9
⬆️ que-sdk to 0.2.3
DavidRomanovizc Jun 28, 2024
27d486b
➕ add numpy
DavidRomanovizc Jun 28, 2024
30cfe13
⬆️ upgrade dependencies
DavidRomanovizc Jun 28, 2024
94e7527
⚰️ remove infra
DavidRomanovizc Jun 28, 2024
e64b043
✨ add image classification
DavidRomanovizc Jun 28, 2024
23c9ebd
🧑‍💻 add consts
DavidRomanovizc Jun 28, 2024
1ae7894
⚡️ sped-up photo processing
DavidRomanovizc Jun 28, 2024
19fe9eb
🚨 fix imports
DavidRomanovizc Jun 28, 2024
e52e50a
🚚 give more suitable name for middleware
DavidRomanovizc Jul 1, 2024
ae3cb45
💄 update keyboards
DavidRomanovizc Jul 1, 2024
5709919
♻️ minor fixes
DavidRomanovizc Jul 1, 2024
5759a4e
🔥 remove codes
DavidRomanovizc Jul 1, 2024
0edb841
🎨 move to a higher level
DavidRomanovizc Jul 1, 2024
2939ba4
🎨 move funcs to one class
DavidRomanovizc Jul 1, 2024
b2490f0
♻️ minor fixes
DavidRomanovizc Jul 1, 2024
9cffc53
🚚 split single file into multiple
DavidRomanovizc Jul 3, 2024
192753a
♻️ minor fixes
DavidRomanovizc Jul 3, 2024
876f6ed
💄 update keyboards
DavidRomanovizc Jul 3, 2024
962516e
✨ add states for update profile
DavidRomanovizc Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ IP=
TIMEZONE=
MODERATE_CHAT=

POSTGRES_USER=
POSTGRES_PASSWORD=
DB_HOST=
DB_PORT=
POSTGRES_DB=
SIGNATURE_SECRET_KEY=
USE_REDIS=

SECRET_KEY=
API_KEY=
REDIS_PORT=
REDIS_HOST=

QIWI_KEY=
PHONE_NUMBER=
SECRET_P2=
API_ID=
API_HASH=
SESSION_STR=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@ dmypy.json

# Django Settings with Secret key
/django_project/django_project/settings.py
photos/
photos/
!photos/.gitkeep
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
exclude: 'docs|frontend|deprecated|README.md|CODE_OF_CONDUCT.md|LICENSE|.github'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [ --py38-plus ]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.8"
hooks:
- id: ruff
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
args: [ --follow-imports=silent, --disable-error-code=no-untyped-call, --explicit-package-bases ]
exclude: tests/
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ WORKDIR /src
COPY requirements.txt /src
RUN pip install -r /src/requirements.txt
COPY . /src

13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@

### :monocle_face: About

| 🏗️ The project has moved elsewhere, and currently available at [que.group](https://github.com/QueGroup) |
|----------------------------------------------------------------------------------------------------------|

Open-source Dating Telegram bot built on aiogram 2.x to facilitate the search for new connections. The bot incorporates
Open-source Dating Telegram bot built on aiogram 3.x to facilitate the search for new connections. The bot incorporates
a classic profile browsing system, along with filtering options and event organization capabilities. Users can create
and join events, fostering community engagement. Additionally, the project is closely integrated with neural networks,
enhancing its capabilities.

### :alembic: Built With

![Python](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue)\
![Django](https://img.shields.io/badge/Django-092E20?style=for-the-badge&logo=django&logoColor=green)\
![AIOHTTP](https://img.shields.io/badge/aiohttp-%232C5bb4.svg?style=for-the-badge&logo=aiohttp&logoColor=white)\
![Poetry](https://img.shields.io/badge/Poetry-%233B82F6.svg?style=for-the-badge&logo=poetry&logoColor=0B3D8D)\
![Babel](https://img.shields.io/badge/Babel-F9DC3e?style=for-the-badge&logo=babel&logoColor=black)\
![Postgresql](https://img.shields.io/badge/PostgreSQL-316192?style=for-the-badge&logo=postgresql&logoColor=white)\
![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)\
![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)
![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)\
![Aiogram](https://img.shields.io/badge/aiogram--V3-blue?style=for-the-badge&logo=telegram&logoColor=white)\
![Redis](https://img.shields.io/badge/redis-%23DD0031.svg?style=for-the-badge&logo=redis&logoColor=white)\
![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white)

### :hammer: Development

Expand Down
66 changes: 0 additions & 66 deletions app.py

This file was deleted.

17 changes: 7 additions & 10 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[python: data/**.py]
[python: django_project/**.py]
[python: filters/**.py]
[python: functions/**.py]
[python: handlers/**.py]
[python: keyboards/**.py]
[python: logs/**.py]
[python: middlewares/**.py]
[python: utils/**.py]
encoding = utf-8
[python: src/tgbot/filters/**.py]
[python: src/tgbot/services/**.py]
[python: src/tgbot/handlers/**.py]
[python: src/tgbot/keyboards/**.py]
[python: src/tgbot/middlewares/**.py]
[python: src/tgbot/utils/**.py]
encoding = utf-8
2 changes: 1 addition & 1 deletion bot.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ autorestart=true
autorestart=true
environment=HOME="/home/ubuntu",USER="ubuntu"
stderr_logfile=/home/ubuntu/DatingBot/logfile_err_django.log
stdout_logfile=/home/ubuntu/DatingBot/logfile_django.log
stdout_logfile=/home/ubuntu/DatingBot/logfile_django.log
156 changes: 156 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import asyncio
import logging
from typing import (
Sequence,
)

from aiogram import (
Bot,
Dispatcher,
)
from aiogram.client.default import (
DefaultBotProperties,
)
from aiogram.enums import (
ParseMode,
)
from aiogram.fsm.storage.memory import (
MemoryStorage,
)
from aiogram.fsm.storage.redis import (
DefaultKeyBuilder,
RedisStorage,
)
from aiogram.utils.i18n import (
ConstI18nMiddleware,
I18n,
)
import betterlogging as bl
from que_sdk import (
QueClient,
)
from redis.asyncio.client import Redis # type: ignore
from yandex_geocoder import (
Client,
)

from src.tgbot import (
services,
)
from src.tgbot.config import (
Config,
load_config,
)
from src.tgbot.handlers import (
routers_list,
)
from src.tgbot.middlewares import ( # type: ignore
AccessControlMiddleware,
AlbumMiddleware,
DIMiddleware,
)


async def on_startup(bot: Bot, admin_ids: Sequence[int]) -> None:
await services.broadcast(bot, list(admin_ids), "Бот запущен") # type: ignore


def setup_logging() -> None:
"""
Set up logging configuration for the application.

This method initializes the logging configuration for the application.
It sets the log level to INFO and configures a basic colorized log for
output. The log format includes the filename, line number, log level,
timestamp, logger name, and log message.

Returns:
None

Example usage:
setup_logging()
"""
log_level = logging.INFO
bl.basic_colorized_config(level=log_level)

logging.basicConfig(
level=logging.INFO,
format="%(filename)s:%(lineno)d #%(levelname)-8s [%(asctime)s] - %(name)s - %(message)s",
)
logger = logging.getLogger(__name__)
logger.info("Starting bot")


def register_global_middlewares(
dp: Dispatcher,
config: Config,
client: QueClient,
redis: Redis,
i18n: I18n,
ya_client: Client
) -> None:
logging.info("Setup middlewares...")
middleware_types = [
DIMiddleware(config, client, ya_client),
AccessControlMiddleware(client=client),
ConstI18nMiddleware(locale="ru", i18n=i18n)
]
# dp.message.middleware(ThrottlingMiddleware(redis))
dp.message.middleware(AlbumMiddleware())
for middleware_type in middleware_types:
dp.message.outer_middleware(middleware_type)
dp.callback_query.outer_middleware(middleware_type)


def get_storage(config: Config) -> MemoryStorage | RedisStorage:
"""
Return storage based on the provided configuration.

Args:
config (Config): The configuration object.

Returns:
Storage: The storage object based on the configuration.
"""
if config.tg_bot.use_redis:
return RedisStorage.from_url(
config.redis.dsn(),
key_builder=DefaultKeyBuilder(with_bot_id=True, with_destiny=True),
)
else:
return MemoryStorage()


async def main() -> None:
setup_logging()

config = load_config()
i18n = I18n(path=config.tg_bot.LOCALES_DIR, default_locale="ru", domain="messages")
storage = get_storage(config)
client = QueClient()
ya_client = Client(api_key=config.misc.yandex_map_api_key)

redis = Redis(
host=config.redis.host,
port=config.redis.port,
decode_responses=True,
max_connections=10,
auto_close_connection_pool=True
)

bot = Bot(token=config.tg_bot.token, default=DefaultBotProperties(parse_mode=ParseMode.MARKDOWN))
dp = Dispatcher(storage=storage)

register_global_middlewares(dp, config, client, redis, i18n, ya_client)
dp.include_routers(*routers_list)
await services.set_default_commands(bot, config)
await on_startup(bot, config.tg_bot.admin_ids)
await dp.start_polling(bot)


if __name__ == "__main__":
try:
# FIXME: Почему-то с редисом asyncio.run(main()) не работает
asyncio.get_event_loop().run_until_complete(main())
except (KeyboardInterrupt, SystemExit):
logging.error("Бот был выключен!")
Binary file removed brandbook/1_page.png
Binary file not shown.
Binary file removed brandbook/2_page.png
Binary file not shown.
Binary file removed brandbook/3_page.png
Binary file not shown.
Binary file removed brandbook/4_page.png
Binary file not shown.
Loading