mirror of
				https://github.com/civsocit/olgram.git
				synced 2025-10-31 01:33:25 +00:00 
			
		
		
		
	Compare commits
	
		
			No commits in common. "103618cbd2c39a5ec22128e89b82e82f278103d6" and "23055908991880f0b41fcd9b85e2559a48e8d459" have entirely different histories.
		
	
	
		
			103618cbd2
			...
			2305590899
		
	
		
|  | @ -26,12 +26,9 @@ _redis: ty.Optional[Redis] = None | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _get_translator(message: types.Message) -> ty.Callable: | def _get_translator(message: types.Message) -> ty.Callable: | ||||||
|     try: |     if not message.from_user.locale: | ||||||
|         if not message.from_user.locale: |  | ||||||
|             return _ |  | ||||||
|         return translators.get(message.from_user.locale.language, _) |  | ||||||
|     except Exception: |  | ||||||
|         return _ |         return _ | ||||||
|  |     return translators.get(message.from_user.locale.language, _) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| async def init_redis(): | async def init_redis(): | ||||||
|  | @ -92,11 +89,8 @@ async def send_user_message(message: types.Message, super_chat_id: int, bot, tag | ||||||
|         if message.from_user.username: |         if message.from_user.username: | ||||||
|             user_info += " | @" + message.from_user.username |             user_info += " | @" + message.from_user.username | ||||||
|         user_info += f" | #ID{message.from_user.id}" |         user_info += f" | #ID{message.from_user.id}" | ||||||
|         try: |         if message.from_user.locale: | ||||||
|             if message.from_user.locale: |             user_info += f" | lang: {message.from_user.locale}" | ||||||
|                 user_info += f" | lang: {message.from_user.locale}" |  | ||||||
|         except Exception: |  | ||||||
|             pass |  | ||||||
|         if message.forward_sender_name: |         if message.forward_sender_name: | ||||||
|             user_info += f" | fwd: {message.forward_sender_name}" |             user_info += f" | fwd: {message.forward_sender_name}" | ||||||
|         tag = await _redis.get(_tag_uid(bot.pk, message.from_user.id), encoding="utf-8") |         tag = await _redis.get(_tag_uid(bot.pk, message.from_user.id), encoding="utf-8") | ||||||
|  | @ -225,10 +219,7 @@ async def handle_user_message(message: types.Message, super_chat_id: int, bot): | ||||||
|         send_auto = not await _redis.get(_last_message_uid(bot.pk, message.chat.id)) |         send_auto = not await _redis.get(_last_message_uid(bot.pk, message.chat.id)) | ||||||
|         await _redis.setex(_last_message_uid(bot.pk, message.chat.id), 60 * 60 * 3, 1) |         await _redis.setex(_last_message_uid(bot.pk, message.chat.id), 60 * 60 * 3, 1) | ||||||
|         if send_auto or bot.enable_always_second_message: |         if send_auto or bot.enable_always_second_message: | ||||||
|             try: |             text_obj = await BotSecondMessage.get_or_none(bot=bot, locale=str(message.from_user.locale)) | ||||||
|                 text_obj = await BotSecondMessage.get_or_none(bot=bot, locale=str(message.from_user.locale)) |  | ||||||
|             except Exception: |  | ||||||
|                 text_obj = None |  | ||||||
|             return SendMessage(chat_id=message.chat.id, text=text_obj.text if text_obj else bot.second_text, |             return SendMessage(chat_id=message.chat.id, text=text_obj.text if text_obj else bot.second_text, | ||||||
|                                parse_mode="HTML") |                                parse_mode="HTML") | ||||||
| 
 | 
 | ||||||
|  | @ -289,10 +280,7 @@ async def handle_operator_message(message: types.Message, super_chat_id: int, bo | ||||||
|         # в супер-чате кто-то пишет сообщение сам себе, только для личных сообщений |         # в супер-чате кто-то пишет сообщение сам себе, только для личных сообщений | ||||||
|         if bot.enable_mailing: |         if bot.enable_mailing: | ||||||
|             asyncio.create_task(MailingUser.get_or_create(telegram_id=message.chat.id, bot=bot)) |             asyncio.create_task(MailingUser.get_or_create(telegram_id=message.chat.id, bot=bot)) | ||||||
|         try: |         await message.forward(super_chat_id) | ||||||
|             await message.forward(super_chat_id) |  | ||||||
|         except exceptions.MessageCantBeForwarded: |  | ||||||
|             await message.copy_to(super_chat_id) |  | ||||||
|         # И отправить пользователю специальный текст, если он указан |         # И отправить пользователю специальный текст, если он указан | ||||||
|         if bot.second_text: |         if bot.second_text: | ||||||
|             return SendMessage(chat_id=message.chat.id, text=bot.second_text, parse_mode="HTML") |             return SendMessage(chat_id=message.chat.id, text=bot.second_text, parse_mode="HTML") | ||||||
|  | @ -304,10 +292,7 @@ async def message_handler(message: types.Message, *args, **kwargs): | ||||||
| 
 | 
 | ||||||
|     if message.text and message.text == "/start": |     if message.text and message.text == "/start": | ||||||
|         # На команду start нужно ответить, не пересылая сообщение никуда |         # На команду start нужно ответить, не пересылая сообщение никуда | ||||||
|         try: |         text_obj = await BotStartMessage.get_or_none(bot=bot, locale=str(message.from_user.locale)) | ||||||
|             text_obj = await BotStartMessage.get_or_none(bot=bot, locale=str(message.from_user.locale)) |  | ||||||
|         except Exception: |  | ||||||
|             text_obj = None |  | ||||||
|         text = text_obj.text if text_obj else bot.start_text |         text = text_obj.text if text_obj else bot.start_text | ||||||
|         if bot.enable_olgram_text: |         if bot.enable_olgram_text: | ||||||
|             text += _(ServerSettings.append_text()) |             text += _(ServerSettings.append_text()) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user