# Proprietary License Agreement # Copyright (c) 2024-29 Archquise # Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software for personal and non-commercial purposes, subject to the following conditions: # 1. The Software may not be modified, altered, or otherwise changed in any way without the explicit written permission of the author. # 2. Redistribution of the Software, in original or modified form, is strictly prohibited without the explicit written permission of the author. # 3. The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holder be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software. # 4. Any use of the Software must include the above copyright notice and this permission notice in all copies or substantial portions of the Software. # 5. By using the Software, you agree to be bound by the terms and conditions of this license. # For any inquiries or requests for permissions, please contact archquise@gmail.com. # --------------------------------------------------------------------------------- # Name: FolderAutoRead # Description: Automatically reads chats in selected folders # Author: @hikka_mods # --------------------------------------------------------------------------------- # meta developer: @hikka_mods # --------------------------------------------------------------------------------- import logging from telethon import functions from telethon.tl.types import DialogFilter, InputPeerChannel from .. import loader, utils logger = logging.getLogger(__name__) @loader.tds class FolderAutoReadMod(loader.Module): """Automatically reads chats in selected folders""" strings = { "name": "FolderAutoRead", "not_exists_or_already_added": "🚫 This folder does not exists or it is already added for tracking!", "_cls_doc": "Automatically reads chats in selected folders every 60 seconds!", "_cmd_doc_addfolder": "Adds folder to the tracking list by it's name. Usage: .addfolder FolderName", "_cmd_doc_listfolders": "Prints list of tracked folders", "_cmd_doc_delfolder": "Deletes folder from the tracking list", "wrong_args": "🚫 Wrong arguments! Usage: .addfolder/delfolder FolderName\n\nTip: If you trying to delete the folder from the tracking list, double-check that it really still tracking using .listfolders", "listfolders": "πŸ“ List of tracked folders:\n", "delfolder": "πŸ—‘ Folder is successfully deleted from the tracking list!", "addfolder": "πŸ“ Folder is successfully added to the tracking list!", } strings_ru = { "not_exists_or_already_added": "🚫 Π’Π°ΠΊΠΎΠΉ ΠΏΠ°ΠΏΠΊΠΈ Π½Π΅ сущСствуСт, ΠΈΠ»ΠΈ ΠΎΠ½Π° ΡƒΠΆΠ΅ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½Π° для отслСТивания!", "_cls_doc": "АвтоматичСски Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ Ρ‡Π°Ρ‚Ρ‹ Π² Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹Ρ… ΠΏΠ°ΠΏΠΊΠ°Ρ… ΠΊΠ°ΠΆΠ΄Ρ‹Π΅ 60 сСкунд!", "_cmd_doc_addfolder": "ДобавляСт ΠΏΠ°ΠΏΠΊΠΈ Π² список отслСТивания ΠΏΠΎ ΠΈΡ… названию. ИспользованиС: .addfolder НазваниСПапки", "_cmd_doc_listfolders": "Π’Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ список отслСТиваСмых ΠΏΠ°ΠΏΠΎΠΊ", "_cmd_doc_delfolder": "УдаляСт ΠΏΠ°ΠΏΠΊΡƒ ΠΈΠ· списка для отслСТнивания", "wrong_args": "🚫 НСвСрныС Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Ρ‹! ИспользованиС: .addfolder/delfolder НазваниСПапки\n\nΠ‘ΠΎΠ²Π΅Ρ‚: Если Π²Ρ‹ ΠΏΡ‹Ρ‚Π°Π΅Ρ‚Π΅ΡΡŒ ΡƒΠ΄Π°Π»ΠΈΡ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ ΠΈΠ· списка отслСТивания, ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡŒΡ‚Π΅, Ρ‡Ρ‚ΠΎ ΠΎΠ½Π° Π²ΠΎΠΎΠ±Ρ‰Π΅ отслСТиваСтся, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ .listfolders", "listfolders": "πŸ“ Бписок отслСТиваСмых ΠΏΠ°ΠΏΠΎΠΊ:\n", "delfolder": "πŸ—‘ Папка ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ ΡƒΠ΄Π°Π»Π΅Π½Π° ΠΈΠ· листа отслСТивания!", "addfolder": "πŸ“ Папка ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½Π° Π² лист отслСТивания!", } def __init__(self): self.tracked_folders = [] async def client_ready(self, client, db): self.tracked_folders = self.pointer("tracked_folders", []) async def _read_peers(self, peers): for peer in peers: try: await self._client(functions.messages.ReadMentionsRequest(peer=peer)) await self._client(functions.messages.ReadReactionsRequest(peer=peer)) if isinstance(peer, InputPeerChannel): await self._client( functions.channels.ReadHistoryRequest(channel=peer, max_id=0) ) else: await self._client( functions.messages.ReadHistoryRequest(peer=peer, max_id=0) ) except Exception as e: logger.debug(f"Failed to read peer {peer}: {e}") @loader.loop(interval=60, autostart=True) async def read_chats_in_folders(self): if self.tracked_folders: all_folders = await self._client( functions.messages.GetDialogFiltersRequest() ) for folder_name in self.tracked_folders: match = next( ( f for f in all_folders.filters if isinstance(f, DialogFilter) and f.title.text == folder_name ), None, ) if match is None: continue await self._read_peers(match.pinned_peers) await self._read_peers(match.include_peers) @loader.command( ru_doc="Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ Π² список отслСТивания", en_doc="Add folder to the tracking list", ) async def addfolder(self, message): arg = utils.get_args_raw(message) if arg: all_folders = await self._client( functions.messages.GetDialogFiltersRequest() ) match = next( ( f for f in all_folders.filters if isinstance(f, DialogFilter) and f.title.text == arg ), None, ) if match and arg not in self.tracked_folders: self.tracked_folders.append(arg) await utils.answer(message, self.strings("addfolder")) else: await utils.answer(message, self.strings("not_exists_or_already_added")) else: await utils.answer(message, self.strings("wrong_args")) @loader.command( ru_doc="Π£Π΄Π°Π»ΠΈΡ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ ΠΈΠ· списка отслСТивания", en_doc="Delete folder from the tracking list", ) async def delfolder(self, message): arg = utils.get_args_raw(message) if arg and arg in self.tracked_folders: self.tracked_folders.remove(arg) await utils.answer(message, self.strings("delfolder")) else: await utils.answer(message, self.strings("wrong_args")) @loader.command( ru_doc="Бписок отслСТиваСмых ΠΏΠ°ΠΏΠΎΠΊ", en_doc="List tracked folders", ) async def listfolders(self, message): await utils.answer( message, self.strings("listfolders") + "\n".join(f"β€’ {folder}" for folder in self.tracked_folders), )