diff --git a/olgram/commands/bot_actions.py b/olgram/commands/bot_actions.py index 8bb3027..efb289f 100644 --- a/olgram/commands/bot_actions.py +++ b/olgram/commands/bot_actions.py @@ -3,6 +3,7 @@ """ from aiogram import types from aiogram.utils.exceptions import TelegramAPIError, Unauthorized +from aiogram import Bot as AioBot from olgram.models.models import Bot from server.server import unregister_token from locales.locale import _ @@ -62,6 +63,20 @@ async def select_chat(bot: Bot, call: types.CallbackQuery, chat: str): await bot.save() await call.answer(_("Выбран личный чат")) return + if chat == "leave": + bot.group_chat = None + await bot.save() + chats = await bot.group_chats.all() + a_bot = AioBot(bot.decrypted_token()) + for chat in chats: + try: + await chat.delete() + await a_bot.leave_chat(chat.chat_id) + except TelegramAPIError: + pass + await call.answer(_("Бот вышел из чатов")) + await a_bot.session.close() + return chat_obj = await bot.group_chats.filter(id=chat).first() if not chat_obj: diff --git a/olgram/commands/menu.py b/olgram/commands/menu.py index 5dbeb0b..9f1b095 100644 --- a/olgram/commands/menu.py +++ b/olgram/commands/menu.py @@ -68,6 +68,11 @@ async def send_chats_menu(bot: Bot, call: types.CallbackQuery): callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="chat", chat="personal")) ) + keyboard.insert( + types.InlineKeyboardButton(text=_("❗️ Выйти из всех чатов"), + callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="chat", + chat="leave")) + ) keyboard.insert( types.InlineKeyboardButton(text=_("<< Назад"), callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty,