75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
import asyncio
|
|
from pprint import pprint
|
|
|
|
from pyrogram.enums import ParseMode
|
|
from pyrogram.errors import PeerIdInvalid
|
|
from pyrogram.types import Message
|
|
|
|
from bot import config
|
|
from bot.loader import app1, scheduler
|
|
from pyrogram import filters
|
|
|
|
from bot.sending import is_valid_time_format, sending, check_stop_sign, forward_post, get_number_posts, set_number_posts
|
|
|
|
|
|
class Sending:
|
|
SEND = True
|
|
|
|
|
|
recently_media_groups = set()
|
|
|
|
|
|
@app1.on_message(filters.chat(config.admins) & filters.command('current'))
|
|
async def current_tasks(client, message: Message):
|
|
"""Присылает текущие таймслоты на пересылку"""
|
|
text = "Текущие расписание постов:\n" + '\n'.join([time for _, time, _ in scheduler.tasks])
|
|
if len(scheduler.tasks) == 0: text += "Пусто"
|
|
# print(message.text)
|
|
await message.reply(text)
|
|
|
|
|
|
@app1.on_message(filters.chat(config.admins) & filters.command('add'))
|
|
async def add(client, message: Message):
|
|
"""Добавление нового времени"""
|
|
if len(message.command) < 2 or not is_valid_time_format(message.command[1]):
|
|
await message.reply("Введите /add HH:MM")
|
|
return
|
|
time = message.command[1]
|
|
await scheduler.add_task(task=sending, run_time=time)
|
|
await current_tasks(app1, message)
|
|
|
|
|
|
@app1.on_message(filters.chat(config.admins) & filters.command('delete'))
|
|
async def delete(client, message: Message):
|
|
"""Удаление нового времени"""
|
|
if len(message.command) < 2 or not is_valid_time_format(message.command[1]):
|
|
await message.reply("Введите /add HH:MM")
|
|
return
|
|
time = message.command[1]
|
|
if await scheduler.remove_task(sending, time):
|
|
await message.reply(f"Успешно удалено время {time}")
|
|
await current_tasks(client, message)
|
|
|
|
|
|
@app1.on_message(filters.chat(config.admins) & filters.command('switch'))
|
|
async def switch(client, message: Message):
|
|
""" вкл/выкл пересылки """
|
|
if Sending.SEND:
|
|
Sending.SEND = False
|
|
else:
|
|
Sending.SEND = True
|
|
await message.reply(f"моментальная пересылка {'вкл' if Sending.SEND else 'выкл'}")
|
|
|
|
|
|
@app1.on_message(filters.chat(config.admins) & filters.command('set_posts'))
|
|
async def set_posts(client, message: Message):
|
|
""" установить нужное количество постов для пересылки """
|
|
global g
|
|
try:
|
|
set_number_posts(int(message.command[1]))
|
|
await message.reply(f"Количество постов {get_number_posts()} установлено")
|
|
except:
|
|
await message.reply("Введите /set_posts число")
|
|
|
|
|