diff --git a/misskaty/plugins/nightmode.py b/misskaty/plugins/nightmode.py deleted file mode 100644 index f34f803e..00000000 --- a/misskaty/plugins/nightmode.py +++ /dev/null @@ -1,209 +0,0 @@ -# Auto Close and Open Group, I dont have time to add Database Support -import traceback -from datetime import datetime - -import pytz -from apscheduler.schedulers.asyncio import AsyncIOScheduler -from pyrogram import Client, __version__, filters -from pyrogram.types import ( - CallbackQuery, - ChatPermissions, - InlineKeyboardButton, - InlineKeyboardMarkup, -) - -from misskaty import BOT_USERNAME, app -from misskaty.core.decorator.ratelimiter import ratelimiter -from misskaty.vars import LOG_CHANNEL, NIGHTMODE - - -# Check calculate how long it will take to Ramadhan -def puasa(): - now = datetime.now(pytz.timezone("Asia/Jakarta")) - tahun = now.strftime("%Y") - bulan = now.strftime("%m") - tgl = now.strftime("%d") - jam = now.strftime("%H") - menit = now.strftime("%M") - detik = now.strftime("%S") - x = datetime(int(tahun), int(bulan), int(tgl), int(jam), int(menit), int(detik)) - y = datetime(2022, 4, 2, 0, 0, 0) - return y - x - - -async def job_close(): - now = datetime.now(pytz.timezone("Asia/Jakarta")) - days = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"] - month = [ - "Unknown", - "Januari", - "Februari", - "Maret", - "April", - "Mei", - "Juni", - "Juli", - "Agustus", - "September", - "Oktober", - "November", - "Desember", - ] - tgl = now.strftime("%d") - tahun = now.strftime("%Y") - jam = now.strftime("%H:%M") - try: - reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="ā¤ļø", callback_data="nightmd")]]) - await app.set_chat_permissions( - -1001128045651, - ChatPermissions(can_send_messages=False, can_invite_users=True), - ) - await app.send_message( - -1001128045651, - f"šŸ“† {days[now.weekday()]}, {tgl} {month[now.month]} {tahun}\nā° Jam : {jam}\n\n**šŸŒ— Mode Malam Aktif**\n`Grup ditutup dan semua member tidak akan bisa mengirim pesan. Selamat beristirahat dan bermimpi indah !!`", - reply_markup=reply_markup, - ) - except Exception: - exc = traceback.format_exc() - await app.send_message(LOG_CHANNEL, f"ERROR:\n{exc}") - - -async def job_close_ymoviez(): - now = datetime.now(pytz.timezone("Asia/Jakarta")) - days = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"] - month = [ - "Unknown", - "Januari", - "Februari", - "Maret", - "April", - "Mei", - "Juni", - "Juli", - "Agustus", - "September", - "Oktober", - "November", - "Desember", - ] - tgl = now.strftime("%d") - tahun = now.strftime("%Y") - jam = now.strftime("%H:%M") - try: - reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="ā¤ļø", callback_data="nightmd")]]) - await app.set_chat_permissions( - -1001255283935, - ChatPermissions(can_send_messages=False, can_invite_users=True), - ) - await app.send_message( - -1001255283935, - f"šŸ“† {days[now.weekday()]}, {tgl} {month[now.month]} {tahun}\nā° Jam : {jam}\n\n**šŸŒ— Mode Malam Aktif**\n`Grup ditutup hingga jam 9 pagi. Selamat beristirahat.....`", - ) - except Exception: - exc = traceback.format_exc() - await app.send_message(LOG_CHANNEL, f"ERROR:\n{exc}") - - -async def job_open(): - now = datetime.now(pytz.timezone("Asia/Jakarta")) - days = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"] - month = [ - "Unknown", - "Januari", - "Februari", - "Maret", - "April", - "Mei", - "Juni", - "Juli", - "Agustus", - "September", - "Oktober", - "November", - "Desember", - ] - tgl = now.strftime("%d") - tahun = now.strftime("%Y") - jam = now.strftime("%H:%M") - try: - reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="ā¤ļø", callback_data="nightmd")]]) - await app.set_chat_permissions( - -1001128045651, - ChatPermissions( - can_send_messages=True, - can_send_media_messages=True, - can_invite_users=True, - can_add_web_page_previews=True, - can_send_other_messages=False, - ), - ) - await app.send_message( - -1001128045651, - f"šŸ“† {days[now.weekday()]}, {tgl} {month[now.month]} {tahun}\nā° {jam}`\n\nšŸŒ— Mode Malam Selesai\nSelamat pagi, grup kini telah dibuka semoga hari-harimu menyenangkan.`", - reply_markup=reply_markup, - ) - except Exception: - exc = traceback.format_exc() - await app.send_message(LOG_CHANNEL, f"ERROR:\n{exc}") - - -async def job_open_ymoviez(): - now = datetime.now(pytz.timezone("Asia/Jakarta")) - days = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"] - month = [ - "Unknown", - "Januari", - "Februari", - "Maret", - "April", - "Mei", - "Juni", - "Juli", - "Agustus", - "September", - "Oktober", - "November", - "Desember", - ] - tgl = now.strftime("%d") - tahun = now.strftime("%Y") - jam = now.strftime("%H:%M") - try: - reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="ā¤ļø", callback_data="nightmd")]]) - await app.set_chat_permissions( - -1001255283935, - ChatPermissions( - can_send_messages=True, - can_send_media_messages=True, - can_invite_users=True, - can_add_web_page_previews=True, - can_send_other_messages=True, - ), - ) - await app.send_message( - -1001255283935, - f"šŸ“† {days[now.weekday()]}, {tgl} {month[now.month]} {tahun}\nā° {jam}`\n\nšŸŒ— Mode Malam Selesai\nSelamat pagi, grup kini telah dibuka semoga hari-harimu menyenangkan.`", - reply_markup=reply_markup, - ) - except Exception: - exc = traceback.format_exc() - await app.send_message(LOG_CHANNEL, f"ERROR:\n{exc}") - - -@app.on_callback_query(filters.regex(r"^nightmd$")) -@ratelimiter -async def callbackanightmd(c: Client, q: CallbackQuery): - await q.answer( - f"šŸ”– Hai, Aku {BOT_USERNAME} dibuat menggunakan Framework Pyrogram v{__version__} dan Python 3.10.\n\nMau buat bot seperti ini? Yuuk belajar di @botindonesia\nOwner: @YasirArisM", - show_alert=True, - cache_time=2160, - ) - - -scheduler = AsyncIOScheduler(timezone="Asia/Jakarta") -if NIGHTMODE: - scheduler.add_job(job_close, trigger="cron", hour=22, minute=0) - # scheduler.add_job(job_close_ymoviez, trigger="cron", hour=22, minute=0) - scheduler.add_job(job_open, trigger="cron", hour=6, minute=0) - # scheduler.add_job(job_open_ymoviez, trigger="cron", hour=10, minute=0) - scheduler.start() diff --git a/misskaty/plugins/nightmodev2.py b/misskaty/plugins/nightmodev2.py index 9b804818..6709cc7e 100644 --- a/misskaty/plugins/nightmodev2.py +++ b/misskaty/plugins/nightmodev2.py @@ -4,14 +4,15 @@ from datetime import datetime, timedelta import pytz from apscheduler.jobstores.base import ConflictingIdError -from pyrogram import filters +from pyrogram import filters, __version__ from pyrogram.errors import (ChannelInvalid, ChannelPrivate, ChatAdminRequired, ChatNotModified) -from pyrogram.types import ChatPermissions +from pyrogram.types import ChatPermissions, InlineKeyboardButton, InlineKeyboardMarkup from database.nightmode_db import TZ, scheduler -from misskaty import BOT_NAME, app +from misskaty import BOT_NAME, BOT_USERNAME, app from misskaty.core.message_utils import * +from misskaty.core.decorator.ratelimiter import ratelimiter from misskaty.core.decorator.permissions import adminsOnly from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL @@ -29,6 +30,43 @@ __HELP__ = """Enable or disable nightmode (locks the chat at specified interv """ TIME_ZONE = pytz.timezone(TZ) +reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="ā¤ļø", callback_data="nightmd")]]) + +# Check calculate how long it will take to Ramadhan +def puasa(): + now = datetime.now(pytz.timezone("Asia/Jakarta")) + tahun = now.strftime("%Y") + bulan = now.strftime("%m") + tgl = now.strftime("%d") + jam = now.strftime("%H") + menit = now.strftime("%M") + detik = now.strftime("%S") + x = datetime(int(tahun), int(bulan), int(tgl), int(jam), int(menit), int(detik)) + y = datetime(2022, 4, 2, 0, 0, 0) + return y - x + +def tglsekarang(): + now = datetime.now(pytz.timezone("Asia/Jakarta")) + days = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"] + month = [ + "Unknown", + "Januari", + "Februari", + "Maret", + "April", + "Mei", + "Juni", + "Juli", + "Agustus", + "September", + "Oktober", + "November", + "Desember", + ] + tgl = now.strftime("%d") + tahun = now.strftime("%Y") + jam = now.strftime("%H:%M") + return f"{days[now.weekday()]}, {tgl} {month[now.month]} {tahun}" def extract_time(time_val: str): if any(time_val.endswith(unit) for unit in ('m', 'h')): @@ -51,14 +89,14 @@ async def un_mute_chat(chat_id: int, perm: ChatPermissions): except ChatAdminRequired: await app.send_message( LOG_CHANNEL, - f"#NIGHT_MODE_FAIL\nFailed to turn off nightmode at `{chat_id}`," + f"#NIGHTMODE_FAIL\nFailed to turn off nightmode at `{chat_id}`," f"since {BOT_NAME} is not an admin in chat `{chat_id}`") except (ChannelInvalid, ChannelPrivate): scheduler.remove_job(f"enable_nightmode_{chat_id}") scheduler.remove_job(f"disable_nightmode_{chat_id}") await app.send_message( LOG_CHANNEL, - f"#NIGHT_MODE_FAIL\nFailed to turn off nightmode at `{chat_id}`," + f"#NIGHTMODE_FAIL\nFailed to turn off nightmode at `{chat_id}`," f"since {BOT_NAME} is not present in chat `{chat_id}`" " Removed group from list.") except ChatNotModified: @@ -66,18 +104,16 @@ async def un_mute_chat(chat_id: int, perm: ChatPermissions): except Exception as e: await app.send_message( LOG_CHANNEL, - f"#NIGHT_MODE_FAIL\nFailed to turn off nightmode at `{chat_id}`\n" + f"#NIGHTMODE_FAIL\nFailed to turn off nightmode at `{chat_id}`\n" f"ERROR: `{e}`") else: job = scheduler.get_job(f"enable_nightmode_{chat_id}") close_at = job.next_run_time await app.send_message( chat_id, - f"#AUTOMATED_HANDLER\nGroup is Opening.\nWill be closed at {close_at}") - await app.send_message( - LOG_CHANNEL, - f"#NIGHT_MODE_SUCCESS\nSuccessfully turned off nightmode at `{chat_id}`,") - + f"#NIGHTMODE_HANDLER\nšŸ“† {tglsekarang()}\n\nā˜€ļø Group is Opening.\nWill be closed at {close_at}", + reply_markup=reply_markup + ) async def mute_chat(chat_id: int): try: @@ -85,14 +121,14 @@ async def mute_chat(chat_id: int): except ChatAdminRequired: await app.send_message( LOG_CHANNEL, - f"#NIGHT_MODE_FAIL\nFailed to enable nightmode at `{chat_id}`," + f"#NIGHTMODE_FAIL\nFailed to enable nightmode at `{chat_id}`," f"since {BOT_NAME} is not an admin in chat `{chat_id}`") except (ChannelInvalid, ChannelPrivate): scheduler.remove_job(f"enable_nightmode_{chat_id}") scheduler.remove_job(f"disable_nightmode_{chat_id}") await app.send_message( LOG_CHANNEL, - f"#NIGHT_MODE_FAIL\nFailed to enable nightmode at `{chat_id}`," + f"#NIGHTMODE_FAIL\nFailed to enable nightmode at `{chat_id}`," f"since {BOT_NAME} is not present in chat `{chat_id}`" " Removed group from list.") except ChatNotModified: @@ -100,17 +136,16 @@ async def mute_chat(chat_id: int): except Exception as e: await app.send_message( LOG_CHANNEL, - f"#NIGHT_MODE_FAIL\nFailed to enable nightmode at `{chat_id}`\n" + f"#NIGHTMODE_FAIL\nFailed to enable nightmode at `{chat_id}`\n" f"ERROR: `{e}`") else: job = scheduler.get_job(f"disable_nightmode_{chat_id}") open_at = job.next_run_time await app.send_message( chat_id, - f"#AUTOMATED_HANDLER\nGroup is closing.\nWill be opened at {open_at}") - await app.send_message( - LOG_CHANNEL, - f"#NIGHT_MODE_SUCCESS\nSuccessfully turned on nightmode at `{chat_id}`,") + f"#NIGHTMODE_HANDLER\nšŸ“† {tglsekarang()}\n\nšŸŒ— Group is closing.\nWill be opened at {open_at}", + reply_markup=reply_markup + ) @app.on_message(filters.command("nightmode", COMMAND_HANDLER) & filters.group) @adminsOnly("can_change_info") @@ -186,5 +221,13 @@ async def nightmode_handler(c, msg): if not bool(scheduler.state): scheduler.start() +@app.on_callback_query(filters.regex(r"^nightmd$")) +@ratelimiter +async def callbackanightmd(c, q): + await q.answer( + f"šŸ”– Hai, Aku {BOT_USERNAME} dibuat menggunakan Framework Pyrogram v{__version__} dan Python 3.10.\n\nMau buat bot seperti ini? Yuuk belajar di @botindonesia\nOwner: @YasirArisM", + show_alert=True + ) + if bool(scheduler.get_jobs()): scheduler.start() \ No newline at end of file