azils3/bash
0
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available -9 10At Night it will turn off everyone permission to send message in an all groups which you added via `{i}addnight`11And Turn On auto at morning12 13• `{i}addnm`14 Add NightMode15 To Add Group To Auto Night Mode.16 17• `{i}remnm`18 Remove NightMode19 To remove Group From Auto Night Mode20 21• `{i}listnm`22 List NightMode23 To Get All List of Groups where NightMode Active.24 25• `{i}nmtime <close hour> <close min> <open hour> <open min>`26 NightMode Time27 By Default Its close 00:00 , open 07:0028 Use 24hr format29 Ex- `nmtime 01 00 06 30`30"""31 32from . import LOGS33 34try:35 from apscheduler.schedulers.asyncio import AsyncIOScheduler36except ImportError:37 LOGS.error("nightmode: 'apscheduler' not Installed!")38 AsyncIOScheduler = None39 40from telethon.tl.functions.messages import EditChatDefaultBannedRightsRequest41from telethon.tl.types import ChatBannedRights42 43from pyUltroid.dB.base import KeyManager44 45from . import get_string, udB, ultroid_bot, ultroid_cmd46 47keym = KeyManager("NIGHT_CHATS", cast=list)48 49 50@ultroid_cmd(pattern="nmtime( (.*)|$)")51async def set_time(e):52 if not e.pattern_match.group(1).strip():53 return await e.eor(get_string("nightm_1"))54 try:55 ok = e.text.split(maxsplit=1)[1].split()56 if len(ok) != 4:57 return await e.eor(get_string("nightm_1"))58 tm = [int(x) for x in ok]59 udB.set_key("NIGHT_TIME", str(tm))60 await e.eor(get_string("nightm_2"))61 except BaseException:62 await e.eor(get_string("nightm_1"))63 64 65@ultroid_cmd(pattern="addnm( (.*)|$)")66async def add_grp(e):67 if pat := e.pattern_match.group(1).strip():68 try:69 keym.add((await ultroid_bot.get_entity(pat)).id)70 return await e.eor(f"Done, Added {pat} To Night Mode.")71 except BaseException:72 return await e.eor(get_string("nightm_5"), time=5)73 keym.add(e.chat_id)74 await e.eor(get_string("nightm_3"))75 76 77@ultroid_cmd(pattern="remnm( (.*)|$)")78async def r_em_grp(e):79 if pat := e.pattern_match.group(1).strip():80 try:81 keym.remove((await ultroid_bot.get_entity(pat)).id)82 return await e.eor(f"Done, Removed {pat} To Night Mode.")83 except BaseException:84 return await e.eor(get_string("nightm_5"), time=5)85 keym.remove(e.chat_id)86 await e.eor(get_string("nightm_4"))87 88 89@ultroid_cmd(pattern="listnm$")90async def rem_grp(e):91 chats = keym.get()92 name = "NightMode Groups Are-:\n\n"93 for x in chats:94 try:95 ok = await ultroid_bot.get_entity(x)96 name += f"@{ok.username}" if ok.username else ok.title97 except BaseException:98 name += str(x)99 await e.eor(name)100 101 102async def open_grp():103 for chat in keym.get():104 try:105 await ultroid_bot(106 EditChatDefaultBannedRightsRequest(107 chat,108 banned_rights=ChatBannedRights(109 until_date=None,110 send_messages=False,111 send_media=False,112 send_stickers=False,113 send_gifs=False,114 send_games=False,115 send_inline=False,116 send_polls=False,117 ),118 )119 )120 await ultroid_bot.send_message(chat, "**NightMode Off**\n\nGroup Opened 🥳.")121 except Exception as er:122 LOGS.info(er)123 124 125async def close_grp():126 __, _, h2, m2 = 0, 0, 7, 0127 if udB.get_key("NIGHT_TIME"):128 _, __, h2, m2 = eval(udB.get_key("NIGHT_TIME"))129 for chat in keym.get():130 try:131 await ultroid_bot(132 EditChatDefaultBannedRightsRequest(133 chat,134 banned_rights=ChatBannedRights(135 until_date=None,136 send_messages=True,137 ),138 )139 )140 await ultroid_bot.send_message(141 chat, f"**NightMode : Group Closed**\n\nGroup Will Open At `{h2}:{m2}`"142 )143 except Exception as er:144 LOGS.info(er)145 146 147if AsyncIOScheduler and keym.get():148 try:149 h1, m1, h2, m2 = 0, 0, 7, 0150 if udB.get_key("NIGHT_TIME"):151 h1, m1, h2, m2 = eval(udB.get_key("NIGHT_TIME"))152 sch = AsyncIOScheduler()153 sch.add_job(close_grp, trigger="cron", hour=h1, minute=m1)154 sch.add_job(open_grp, trigger="cron", hour=h2, minute=m2)155 sch.start()156 except Exception as er:157 LOGS.info(er)158 