Exemple #1
0
async def set_data(m: Message):
    global mailing_data

    if m.text:
        mailing_data.text = m.text
    elif m.photo:
        mailing_data.photo_id = m.photo[0].file_id
        mailing_data.caption = m.caption
    else:
        await m.answer('Некорректное сообщение')
        return

    m.set_action_path('/mailing_verify')

    await m.answer('Напишите "Старт" - чтобы начать рассылку, или "Отмена"')
Exemple #2
0
async def start_mailing(m: Message):
    global mailing_data

    all_user_ids = hl.get_all_ids()
    await m.answer('📤 Бот начал рассылку')
    m.set_action_path('/')

    for user_id in all_user_ids:
        try:
            if mailing_data.text:
                await m.bot.send_message(user_id, mailing_data.text)

            elif mailing_data.photo_id:
                await m.bot.send_photo(user_id,
                                       photo=mailing_data.photo_id,
                                       caption=mailing_data.caption)
        except BotBlocked:
            pass

    await m.answer(
        f'📩 Рассылка закончена. Кол-во отправленных сообщений: {len(all_user_ids)}'
    )
    mailing_data = MailingData()
Exemple #3
0
async def cancel_mailing(m: Message):
    global mailing_data

    mailing_data = MailingData()
    m.set_action_path('/')
    await m.answer('Рассылка отменена')
Exemple #4
0
async def mailing(m: Message):
    if m.from_user.id == config.ADMIN_ID:
        await m.answer('📝 Введите текст сообщения')
        m.set_action_path('/mailing')
Exemple #5
0
 def _middleware(self, m: Message):
     m.set_action_path = lambda p: self.set_user_path(p, m.from_user.id)
     m.get_action_path = lambda: self.get_user_path(m.from_user.id)
     return m