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

Release v1.1 #2

Merged
merged 9 commits into from
Jan 14, 2025
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ RUN addgroup -S appgroup && adduser -S appuser -G appgroup

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1

PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /app

COPY requirements.txt .
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
- 🎧 Высокое качество звука
- 🌅 Аудио с обложкой
- 📱 Интуитивный интерфейс
- 🌍 Поддержка нескольких языков (английский, русский)
- 🐳 Легкое развертывание через Docker
- 🛡️ Безопасное хранение данных в PostgreSQL
- 📝 Лицензия: Apache License 2.0
- 🌍 Поддержка нескольких языков (🇬🇧 English, 🇷🇺 Русский)
- 🌍 Автоопределение языка пользователя
- 🐳 Легкое развертывание через **Docker**
- 🛡️ Безопасное хранение данных в **PostgreSQL**
- 📊 Управление базой данных через **Adminer**
- 📝 Лицензия: **Apache License 2.0**

## 🎥 Демо (Demo)

Expand Down Expand Up @@ -50,7 +52,7 @@

```env
# Bot Configuration
BOT_TOKEN=your_bot_token # Токен бота от BotFather
BOT_TOKEN=your_bot_token # Токен бота
TIMEZONE=UTC # Пример: Europe/Moscow

# Database Configuration
Expand Down
5 changes: 0 additions & 5 deletions app/__init__.py

This file was deleted.

28 changes: 0 additions & 28 deletions app/configs.py

This file was deleted.

4 changes: 0 additions & 4 deletions app/filters/__init__.py

This file was deleted.

81 changes: 0 additions & 81 deletions app/handlers/get_song.py

This file was deleted.

35 changes: 0 additions & 35 deletions app/handlers/menu.py

This file was deleted.

11 changes: 0 additions & 11 deletions app/utils.py

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions bot/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Filters for the bot."""
from .language import LanguageFilter
from .not_subbed import NotSubbedFilter


__all__ = ['LanguageFilter', 'NotSubbedFilter']
2 changes: 1 addition & 1 deletion app/filters/language.py → bot/filters/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from aiogram import types
from aiogram.filters import Filter
from database.models.user import User
from database.models import User
from locales import support_languages


Expand Down
60 changes: 60 additions & 0 deletions bot/filters/not_subbed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Check if user is subbed to the channel."""
import logging
from aiogram import types
from aiogram.filters import Filter
from aiogram import Bot
from aiogram.enums import ChatMemberStatus
from database.models import RequiredSubscriptions, User
from database.crud import CRUD

logger = logging.getLogger(__name__)


class NotSubbedFilter(Filter):
"""
A filter that checks if a user is subbed to the channel.
"""

ALLOWED_STATUSES = {
ChatMemberStatus.MEMBER,
ChatMemberStatus.ADMINISTRATOR,
ChatMemberStatus.CREATOR,
}

async def __call__(
self, update: types.Message | types.CallbackQuery, user: User, bot: Bot
) -> bool:
"""
Check if the user is not subscribed to any required channels.
Returns True if user is NOT subscribed to ANY required channel.
Returns False if user is subscribed to ALL required channels.
"""
chats = await CRUD(RequiredSubscriptions).get_all()

if not chats:
return False

for chat in chats:
if await self._not_subscribe(chat, user, bot):
return True
return False

async def _not_subscribe(
self, sub: RequiredSubscriptions, user: User, bot: Bot
) -> bool:
"""
Check if the user is subscribed to the channel.
Returns True if user is NOT subscribed.
Returns False if user is subscribed or if channel is not accessible.
"""
try:
chat = await bot.get_chat(sub.chat_id)
except Exception as e:
logger.error(f"Failed to get chat {sub.chat_id}: {e}")
return False

try:
member = await chat.get_member(user.id)
return member.status not in self.ALLOWED_STATUSES
except Exception:
return True
8 changes: 5 additions & 3 deletions app/handlers/__init__.py → bot/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Setup router for the bot."""
from aiogram import Dispatcher, Router
from . import (
get_track,
language,
menu,
faq,
search,
get_song,
pages
pages,
subscribe
)


Expand All @@ -18,8 +19,9 @@ def setup(dp: Dispatcher) -> None:
language.register(router)
menu.register(router)
faq.register(router)
subscribe.register(router)
search.register(router)
pages.register(router)
get_song.register(router)
get_track.register(router)

dp.include_router(router)
5 changes: 2 additions & 3 deletions app/handlers/faq.py → bot/handlers/faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import logging
from aiogram import types, Router, F
from aiogram.utils.i18n import gettext
from app.keyboards import inline
from bot.keyboards import inline

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


Expand All @@ -16,7 +15,7 @@ async def faq_handler(callback: types.CallbackQuery) -> None:
reply_markup=inline.get_back_keyboard(gettext, "menu")
)
except Exception as e:
logger.error(f"Failed to send message: {e}")
logger.error("Failed to send message: %s", e)


def register(router: Router) -> None:
Expand Down
Loading
Loading