mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-10 13:34:51 +00:00
Fix
This commit is contained in:
parent
6b8acd2351
commit
e162b443db
2 changed files with 61 additions and 227 deletions
|
|
@ -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<code>{exc}</code>")
|
|
||||||
|
|
||||||
|
|
||||||
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<code>{exc}</code>")
|
|
||||||
|
|
||||||
|
|
||||||
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<code>{exc}</code>")
|
|
||||||
|
|
||||||
|
|
||||||
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<code>{exc}</code>")
|
|
||||||
|
|
||||||
|
|
||||||
@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()
|
|
||||||
|
|
@ -4,14 +4,15 @@ from datetime import datetime, timedelta
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
from apscheduler.jobstores.base import ConflictingIdError
|
from apscheduler.jobstores.base import ConflictingIdError
|
||||||
from pyrogram import filters
|
from pyrogram import filters, __version__
|
||||||
from pyrogram.errors import (ChannelInvalid, ChannelPrivate, ChatAdminRequired,
|
from pyrogram.errors import (ChannelInvalid, ChannelPrivate, ChatAdminRequired,
|
||||||
ChatNotModified)
|
ChatNotModified)
|
||||||
from pyrogram.types import ChatPermissions
|
from pyrogram.types import ChatPermissions, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
|
|
||||||
from database.nightmode_db import TZ, scheduler
|
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.message_utils import *
|
||||||
|
from misskaty.core.decorator.ratelimiter import ratelimiter
|
||||||
from misskaty.core.decorator.permissions import adminsOnly
|
from misskaty.core.decorator.permissions import adminsOnly
|
||||||
from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL
|
from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL
|
||||||
|
|
||||||
|
|
@ -29,6 +30,43 @@ __HELP__ = """<b>Enable or disable nightmode (locks the chat at specified interv
|
||||||
"""
|
"""
|
||||||
|
|
||||||
TIME_ZONE = pytz.timezone(TZ)
|
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):
|
def extract_time(time_val: str):
|
||||||
if any(time_val.endswith(unit) for unit in ('m', 'h')):
|
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:
|
except ChatAdminRequired:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
LOG_CHANNEL,
|
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}`")
|
f"since {BOT_NAME} is not an admin in chat `{chat_id}`")
|
||||||
except (ChannelInvalid, ChannelPrivate):
|
except (ChannelInvalid, ChannelPrivate):
|
||||||
scheduler.remove_job(f"enable_nightmode_{chat_id}")
|
scheduler.remove_job(f"enable_nightmode_{chat_id}")
|
||||||
scheduler.remove_job(f"disable_nightmode_{chat_id}")
|
scheduler.remove_job(f"disable_nightmode_{chat_id}")
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
LOG_CHANNEL,
|
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}`"
|
f"since {BOT_NAME} is not present in chat `{chat_id}`"
|
||||||
" Removed group from list.")
|
" Removed group from list.")
|
||||||
except ChatNotModified:
|
except ChatNotModified:
|
||||||
|
|
@ -66,18 +104,16 @@ async def un_mute_chat(chat_id: int, perm: ChatPermissions):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
LOG_CHANNEL,
|
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}`")
|
f"ERROR: `{e}`")
|
||||||
else:
|
else:
|
||||||
job = scheduler.get_job(f"enable_nightmode_{chat_id}")
|
job = scheduler.get_job(f"enable_nightmode_{chat_id}")
|
||||||
close_at = job.next_run_time
|
close_at = job.next_run_time
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
chat_id,
|
chat_id,
|
||||||
f"#AUTOMATED_HANDLER\nGroup is Opening.\nWill be closed at {close_at}")
|
f"#NIGHTMODE_HANDLER\n📆 {tglsekarang()}\n\n☀️ Group is Opening.\nWill be closed at {close_at}",
|
||||||
await app.send_message(
|
reply_markup=reply_markup
|
||||||
LOG_CHANNEL,
|
)
|
||||||
f"#NIGHT_MODE_SUCCESS\nSuccessfully turned off nightmode at `{chat_id}`,")
|
|
||||||
|
|
||||||
|
|
||||||
async def mute_chat(chat_id: int):
|
async def mute_chat(chat_id: int):
|
||||||
try:
|
try:
|
||||||
|
|
@ -85,14 +121,14 @@ async def mute_chat(chat_id: int):
|
||||||
except ChatAdminRequired:
|
except ChatAdminRequired:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
LOG_CHANNEL,
|
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}`")
|
f"since {BOT_NAME} is not an admin in chat `{chat_id}`")
|
||||||
except (ChannelInvalid, ChannelPrivate):
|
except (ChannelInvalid, ChannelPrivate):
|
||||||
scheduler.remove_job(f"enable_nightmode_{chat_id}")
|
scheduler.remove_job(f"enable_nightmode_{chat_id}")
|
||||||
scheduler.remove_job(f"disable_nightmode_{chat_id}")
|
scheduler.remove_job(f"disable_nightmode_{chat_id}")
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
LOG_CHANNEL,
|
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}`"
|
f"since {BOT_NAME} is not present in chat `{chat_id}`"
|
||||||
" Removed group from list.")
|
" Removed group from list.")
|
||||||
except ChatNotModified:
|
except ChatNotModified:
|
||||||
|
|
@ -100,17 +136,16 @@ async def mute_chat(chat_id: int):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
LOG_CHANNEL,
|
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}`")
|
f"ERROR: `{e}`")
|
||||||
else:
|
else:
|
||||||
job = scheduler.get_job(f"disable_nightmode_{chat_id}")
|
job = scheduler.get_job(f"disable_nightmode_{chat_id}")
|
||||||
open_at = job.next_run_time
|
open_at = job.next_run_time
|
||||||
await app.send_message(
|
await app.send_message(
|
||||||
chat_id,
|
chat_id,
|
||||||
f"#AUTOMATED_HANDLER\nGroup is closing.\nWill be opened at {open_at}")
|
f"#NIGHTMODE_HANDLER\n📆 {tglsekarang()}\n\n🌗 Group is closing.\nWill be opened at {open_at}",
|
||||||
await app.send_message(
|
reply_markup=reply_markup
|
||||||
LOG_CHANNEL,
|
)
|
||||||
f"#NIGHT_MODE_SUCCESS\nSuccessfully turned on nightmode at `{chat_id}`,")
|
|
||||||
|
|
||||||
@app.on_message(filters.command("nightmode", COMMAND_HANDLER) & filters.group)
|
@app.on_message(filters.command("nightmode", COMMAND_HANDLER) & filters.group)
|
||||||
@adminsOnly("can_change_info")
|
@adminsOnly("can_change_info")
|
||||||
|
|
@ -186,5 +221,13 @@ async def nightmode_handler(c, msg):
|
||||||
if not bool(scheduler.state):
|
if not bool(scheduler.state):
|
||||||
scheduler.start()
|
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()):
|
if bool(scheduler.get_jobs()):
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
Loading…
Reference in a new issue