mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
leave chat button first iteration
This commit is contained in:
parent
6e2ee437ba
commit
9723c70deb
@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
from aiogram import types
|
from aiogram import types
|
||||||
from aiogram.utils.exceptions import TelegramAPIError, Unauthorized
|
from aiogram.utils.exceptions import TelegramAPIError, Unauthorized
|
||||||
|
from aiogram import Bot as AioBot
|
||||||
from olgram.models.models import Bot
|
from olgram.models.models import Bot
|
||||||
from server.server import unregister_token
|
from server.server import unregister_token
|
||||||
from locales.locale import _
|
from locales.locale import _
|
||||||
@ -62,6 +63,20 @@ async def select_chat(bot: Bot, call: types.CallbackQuery, chat: str):
|
|||||||
await bot.save()
|
await bot.save()
|
||||||
await call.answer(_("Выбран личный чат"))
|
await call.answer(_("Выбран личный чат"))
|
||||||
return
|
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()
|
chat_obj = await bot.group_chats.filter(id=chat).first()
|
||||||
if not chat_obj:
|
if not chat_obj:
|
||||||
|
@ -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",
|
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="chat",
|
||||||
chat="personal"))
|
chat="personal"))
|
||||||
)
|
)
|
||||||
|
keyboard.insert(
|
||||||
|
types.InlineKeyboardButton(text=_("❗️ Выйти из всех чатов"),
|
||||||
|
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="chat",
|
||||||
|
chat="leave"))
|
||||||
|
)
|
||||||
keyboard.insert(
|
keyboard.insert(
|
||||||
types.InlineKeyboardButton(text=_("<< Назад"),
|
types.InlineKeyboardButton(text=_("<< Назад"),
|
||||||
callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty,
|
callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty,
|
||||||
|
Loading…
Reference in New Issue
Block a user