mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
fix group chat remove, some minor fixes
This commit is contained in:
parent
cb05f9d1fa
commit
9f32edd1be
@ -5,7 +5,7 @@ from olgram.models.models import Bot, User
|
||||
from aiogram.dispatcher import FSMContext
|
||||
from aiogram.utils.callback_data import CallbackData
|
||||
from textwrap import dedent
|
||||
from olgram.utils.mix import edit_or_create
|
||||
from olgram.utils.mix import edit_or_create, button_text_limit
|
||||
from olgram.commands import bot_actions
|
||||
|
||||
import typing as ty
|
||||
@ -57,7 +57,7 @@ async def send_chats_menu(bot: Bot, call: types.CallbackQuery):
|
||||
|
||||
for chat in chats:
|
||||
keyboard.insert(
|
||||
types.InlineKeyboardButton(text=chat.name,
|
||||
types.InlineKeyboardButton(text=button_text_limit(chat.name),
|
||||
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="chat",
|
||||
chat=chat.id))
|
||||
)
|
||||
|
@ -20,3 +20,10 @@ async def edit_or_create(call: CallbackQuery, message: str,
|
||||
except TelegramAPIError: # кнопка устарела
|
||||
await call.bot.send_message(call.message.chat.id, text=message, reply_markup=reply_markup,
|
||||
parse_mode=parse_mode)
|
||||
|
||||
|
||||
def button_text_limit(data: str) -> str:
|
||||
max_len = 30
|
||||
if len(data) > max_len:
|
||||
data = data[:max_len-4] + "..."
|
||||
return data
|
||||
|
@ -12,6 +12,7 @@ import typing as ty
|
||||
from olgram.settings import ServerSettings
|
||||
from olgram.models.models import Bot, GroupChat
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@ -72,6 +73,7 @@ async def receive_invite(message: types.Message):
|
||||
if member.id == message.bot.id:
|
||||
chat, _ = await GroupChat.get_or_create(chat_id=message.chat.id,
|
||||
defaults={"name": message.chat.full_name})
|
||||
chat.name = message.chat.full_name
|
||||
if chat not in await bot.group_chats.all():
|
||||
await bot.group_chats.add(chat)
|
||||
await bot.save()
|
||||
@ -79,19 +81,15 @@ async def receive_invite(message: types.Message):
|
||||
|
||||
|
||||
async def receive_left(message: types.Message):
|
||||
_logger.info("Receive left")
|
||||
bot = db_bot_instance.get()
|
||||
if message.left_chat_member.id == message.bot.id:
|
||||
chat = await bot.group_chats.filter(chat_id=message.chat.id).first()
|
||||
_logger.info(f"chat found {chat}")
|
||||
if chat:
|
||||
await bot.group_chats.remove(chat)
|
||||
bot_group_chat = await bot.group_chat
|
||||
_logger.info(f"chat removed {bot_group_chat} {chat}")
|
||||
if bot_group_chat == chat:
|
||||
_logger.info("saved")
|
||||
bot.group_chat = None
|
||||
await bot.save(update_fields=["group_chat"])
|
||||
await bot.save()
|
||||
|
||||
|
||||
class CustomRequestHandler(WebhookRequestHandler):
|
||||
|
Loading…
Reference in New Issue
Block a user