# █ █ █ █▄▀ ▄▀█ █▀▄▀█ █▀█ █▀█ █ █ # █▀█ █ █ █ █▀█ █ ▀ █ █▄█ █▀▄ █▄█ # 🔒 Licensed under the GNU GPLv3 # 🌐 https://www.gnu.org/licenses/agpl-3.0.html # 👤 https://t.me/hikamoru # meta developer: @hikamorumods # meta banner: https://raw.githubusercontent.com/AmoreForever/assets/master/leta.jpg # I don't care about other people's opinions, if you don't like it, don't use it. i will update this module in the future, if i have time. import time import logging from .. import loader, utils from telethon.errors import ChatAdminRequiredError logger = logging.getLogger(__name__) class Leta(loader.Module): """Customizable nightmode [Leta] for your group""" strings = { "name": "Leta", "info": ( "🐈‍⬛ Heeey! I'm Leta! I'm a module for nightmode in your group.\n" "📫 You can get acquainted with my settings using the command .help Leta." ), "wrong_format": "🕔 Enter the time in the format HH:MM", "day": "🌅 Good morning!\nNight mode is disabled.", "night": "🌚 Good night!\nNight mode is enabled.", "rm": " Removed nightmode.", "rm_notfound": "🤷‍♂️ Nightmode is not set.", "set": " Time set to\n🌃🌙 Night: {}\n🌅 Day: {}", } strings_ru = { "info": ( "🐈‍⬛ Привет! Я Leta! Я модуль для ночного режима в вашей группе.\n" "📫 Ознакомиться с моими настройками можно с помощью команды .help Leta." ), "wrong_format": "🕔 Введите время в формате HH:MM", "day": "🌅 Доброе утро!\nНочной режим отключен.", "night": "🌚 Доброй ночи!\nНочной режим включен.", "rm": " Удален ночной режим.", "rm_notfound": "🤷‍♂️ Ночной режим не установлен.", "set": " Время установлено на\n🌃🌙 Ночь: {}\n🌅 День: {}", } def resolve_id(self, marked_id): if marked_id >= 0: return "user" marked_id = -marked_id marked_id -= 1000000000000 return "chat" async def client_ready(self, client, db): if not self.get("info", False): await self.inline.bot.send_animation( self._tg_id, "https://0x0.st/Hpqm.mp4", caption=self.strings("info"), parse_mode="HTML", ) self.set("info", True) async def lettimecmd(self, message): """Set time - morning [HH:MM] evening [HH:MM]""" args = utils.get_args_raw(message).split(" ") resolving = self.resolve_id(message.chat_id) if resolving != "chat": return await utils.answer(message, "Use this command in group") if not args: return await utils.answer(message, self.strings("wrong_format")) try: dh, dm = args[0].split(":") eh, em = args[1].split(":") if int(dh) > 23 or int(dh) < 0 or int(dm) > 59 or int(dm) < 0 or int(eh) > 23 or int(eh) < 0 or int(em) > 59 or int(em) < 0: return await utils.answer(message, self.strings("wrong_format")) except Exception: return await utils.answer(message, self.strings('wrong_format')) day = args[0] night = args[1] self.set( "ngs", { message.chat_id: { "time": night, "day": day, "chat": message.chat_id }, } ) await utils.answer(message, self.strings("set").format(night, day)) async def letrmchatcmd(self, message): """Remove nightmode - chat-id""" try: args = int(utils.get_args_raw(message)) d = self.get("ngs", {}) logging.info(d) if not args: return await utils.answer(message, self.strings("rm_notfound")) if args not in d: return await utils.answer(message, self.strings("rm_notfound")) del d[args] self.set("ngs", d) await utils.answer(message, self.strings("rm")) except ValueError: await utils.answer(message, self.strings("rm_notfound")) @loader.loop(interval=60, autostart=True) async def checker_loop_night(self): """Check time""" ngs = self.get("ngs", {}) for i in ngs: if ngs[i]["time"] == time.strftime("%H:%M"): try: await self.client.send_message(ngs[i]["chat"], self.strings("night")) await self.client.edit_permissions(ngs[i]['chat'], send_messages=False) except ChatAdminRequiredError: await self.inline.bot.send_message( self._tg_id, f"👎 You don't have enough rights to change permissions in {i['chat']}", parse_mode="HTML", ) async def letchatscmd(self, message): """Get all chats with nightmode""" ngs = self.get("ngs", {}) if not ngs: return await utils.answer(message, "There are no chats with nightmode") msg = "Chats with nightmode:\n" for i in ngs: msg += f"\n{i}" await utils.answer(message, msg + "\n") @loader.loop(interval=60, autostart=True) async def checker_loop_day(self): """Check time""" ngs = self.get("ngs", {}) for i in ngs: if ngs[i]["day"] == time.strftime("%H:%M"): try: await self.client.edit_permissions(ngs[i]['chat'], send_messages=True) await self.client.send_message(ngs[i]["chat"], self.strings("day")) except ChatAdminRequiredError: await self.inline.bot.send_message( self._tg_id, f"👎 You don't have enough rights to change permissions in {i['chat']}", parse_mode="HTML", )