Skip to content

Commit

Permalink
Добавлен флаг, определяющий необходимость удалять сообщения-подтвержд…
Browse files Browse the repository at this point in the history
…ения об отправке со стороны юзера
  • Loading branch information
MasterGroosha committed Jan 1, 2022
1 parent cd8111f commit 8be4a8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ async def main():
bot.server = TelegramAPIServer.from_base(config.app.local_server_host)

bot["admin_chat_id"] = config.bot.admin_chat_id # Добавление айдишника к объекту bot
# Добавление флага "удалять или нет подтверждения отправки"
bot["remove_sent_confirmation"] = config.bot.remove_sent_confirmation
dp = Dispatcher(bot)

# Регистрация хэндлеров
Expand Down
4 changes: 3 additions & 1 deletion bot/configreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Bot:
token: str
admin_chat_id: int
remove_sent_confirmation: bool


@dataclass
Expand All @@ -30,7 +31,8 @@ def load_config() -> Config:
return Config(
bot=Bot(
token=getenv("BOT_TOKEN"),
admin_chat_id=int(getenv("ADMIN_CHAT_ID"))
admin_chat_id=int(getenv("ADMIN_CHAT_ID")),
remove_sent_confirmation=getenv("REMOVE_SENT_CONFIRMATION", "yes") in ("yes", "1", "true")
),
app=App(
webhook_enabled=getenv("WEBHOOK_ENABLED", "no") in ("yes", "1", "true"),
Expand Down
6 changes: 4 additions & 2 deletions bot/handlers/usermode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ async def _send_expiring_notification(message: types.Message):
:param message: сообщение, на которое бот отвечает подтверждением отправки
"""
remove_sent_confirmation = message.bot.get("remove_sent_confirmation")
msg = await message.reply("Сообщение отправлено!")
await sleep(5.0)
await msg.delete()
if remove_sent_confirmation:
await sleep(5.0)
await msg.delete()


async def text_message(message: types.Message):
Expand Down
4 changes: 4 additions & 0 deletions env_dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ BOT_TOKEN=1234567890:AaBbCcDdEeFGgHhIiJjKkLlMmNnOoPpQq
# в этом случае все участники группы/канала смогут отвечать на сообщения
ADMIN_CHAT_ID=987654321

# Удалять или нет подтверждения об отправке сообщений от юзера админам.
# Чтобы удалялось, укажите "yes", "1" или "true" (без кавычек)
REMOVE_SENT_CONFIRMATION=yes

# Переключение на вебхуки вместо поллинга. Для включения, укажите "yes", "1" или "true" (без кавычек)
WEBHOOK_ENABLED=yes

Expand Down

0 comments on commit 8be4a8a

Please sign in to comment.