Skip to content

Commit

Permalink
Merge branch 'develop' into feature/synchronize-external_site_user-wi…
Browse files Browse the repository at this point in the history
…th-user-683
  • Loading branch information
gorskyolga authored Sep 27, 2024
2 parents 589c956 + 5138679 commit 5b9d759
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
57 changes: 57 additions & 0 deletions src/bot/handlers/user_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from telegram import Update
from telegram.ext import Application, ContextTypes, MessageHandler, filters

from src.bot.utils import registered_user_required
from src.core.db.models import ExternalSiteUser
from src.core.logging.utils import logger_decor

ALLOWED_MESSAGES_FILTER = (
filters.TEXT
| filters.VOICE
| filters.Document.ALL
| filters.PHOTO
| filters.VIDEO
| filters.VIDEO_NOTE
| filters.AUDIO
| filters.Sticker.ALL
) & ~filters.ANIMATION

DISALLOWED_MESSAGES_FILTER = filters.LOCATION | filters.POLL | filters.CONTACT | filters.ANIMATION


@logger_decor
@registered_user_required
async def allowed_messages_callback(
update: Update,
context: ContextTypes.DEFAULT_TYPE,
ext_site_user: ExternalSiteUser,
):
print(type(update.message.effective_attachment))
filling = ("твои", "") if ext_site_user.user.is_volunteer else ("ваши", "те")
text = (
"Пока что мы не можем получать {} сообщения через бот — "
"пожалуйста, пиши{} нам через форму обратной связи. "
'Ее можно найти в меню бота по кнопке "✍ Написать в службу поддержки".'
).format(*filling)
await update.effective_message.reply_text(text)


@logger_decor
@registered_user_required
async def disallowed_messages_callback(
update: Update,
context: ContextTypes.DEFAULT_TYPE,
ext_site_user: ExternalSiteUser,
):
filling = ("",) if ext_site_user.user.is_volunteer else ("те",)
text = (
"Такие сообщения бот не принимает — "
"пожалуйста, пиши{} нам через форму обратной связи. "
'Ее можно найти в меню бота по кнопке "✍ Написать в службу поддержки".'
).format(*filling)
await update.effective_message.reply_text(text)


def registration_handlers(app: Application):
app.add_handler(MessageHandler(ALLOWED_MESSAGES_FILTER, allowed_messages_callback))
app.add_handler(MessageHandler(DISALLOWED_MESSAGES_FILTER, disallowed_messages_callback))
3 changes: 2 additions & 1 deletion src/bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
def init_bot(telegram_bot: Application) -> Application:
"""Инициализация телеграм бота."""

from .handlers import categories, menu, notifications, registration, tasks
from .handlers import categories, menu, notifications, registration, tasks, user_messages

registration.registration_handlers(telegram_bot)
categories.registration_handlers(telegram_bot)
notifications.registration_handlers(telegram_bot)
tasks.registration_handlers(telegram_bot)
menu.registration_handlers(telegram_bot)
user_messages.registration_handlers(telegram_bot)
telegram_bot.add_handler(TypeHandler(Update, logging_updates))
return telegram_bot

0 comments on commit 5b9d759

Please sign in to comment.