бот - напоминалка о спаме

Рейтинг: 0Ответов: 0Опубликовано: 02.03.2023
import asyncio
import logging
from datetime import datetime, time
import os
from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters import Command
from aiogram.types import ParseMode
import pytz

API_TOKEN = '5670634943:AAH_UNYcoCx5YMgCYm_32Vv_JPLz53dBCQM'
CHAT_IDS = [-869635480, -803351935]  # список номеров чатов

logging.basicConfig(level=logging.INFO)

bot = Bot(token=API_TOKEN, parse_mode=ParseMode.HTML)
dp = Dispatcher(bot)


async def schedule_daily_messages():
    tz = pytz.timezone('Asia/Jerusalem')
    while True:
        current_time = datetime.now(tz).time()
        if datetime.now(tz).weekday() != 5 and current_time in [time(hour=9, minute=30),
                                                                time(hour=11, minute=30),
                                                                time(hour=12, minute=11),
                                                                time(hour=3, minute=9)]:
            await send_message()
        await asyncio.sleep(60)


@dp.message_handler(Command("start"))
async def process_start_command(message: types.Message):
    await message.answer("Hello")


@dp.message_handler(Command("send"))
async def send_message(message: types.Message, state: FSMContext):
    message_text = "Hello Dear!\nPlease check our numbers for spam, if there are, replace them as soon as possible. Thanks a lot! 😊"
    for chat_id in CHAT_IDS:
        await bot.send_message(chat_id=chat_id, text=message_text)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.create_task(schedule_daily_messages())
    executor.start_polling(dp)

Ответы

Ответов пока нет.