Example #1
0
def admin_spam(message):
    save_message(message)
    if message.chat.id in TG_BOT['admins']:
        admin = Admin.objects.get(sub__tg_chat_id=message.chat.id)
        if message.text == '/subs':
            msg = tbot.send_message(message.chat.id,
                                    Subscriber.objects.all().count())
            save_message(msg)
        if admin.is_spam and message.text != '/spam':
            for sub in Subscriber.objects.all():
                try:
                    msg = tbot.forward_message(sub.tg_chat_id, message.chat.id,
                                               message.message_id)
                    save_message(msg)
                except:
                    pass
        if message.text == '/spam':
            admin.change_mode()
            msg = tbot.send_message(message.chat.id,
                                    admin.get_spam_status(),
                                    reply_markup=keyboard)
            save_message(msg)
            return None

    if message.chat.id not in TG_BOT['admins']:
        print('wow')

    if message.text == 'Статистика':
        text = stat(message.chat.id)
        msg = tbot.send_message(message.chat.id, text, reply_markup=keyboard)
        save_message(msg)
Example #2
0
def start(message):
    save_message(message)
    Subscriber.objects.get_or_create(tg_chat_id=message.chat.id)
    print(message.chat.id)
    msg = tbot.send_message(message.chat.id,
                            'Стартовое сообщение',
                            reply_markup=keyboard)
    save_message(msg)
Example #3
0
def dialog():
    subs = Subscriber.objects.all()
    print(subs)
    markup = get_markup('charge: yes', 'charge: no')
    for sub in subs:
        try:
            msg = tbot.send_message(sub.tg_chat_id, 'Сделали ли вы сегодня зарядку?', reply_markup=markup)
            save_message(msg)
            sleep(0.1)
        except:
            pass
Example #4
0
 def edit(self, message_id: int, chat_id: int = None):
     from bot_init.utils import save_message
     if chat_id is None:
         chat_id = self.chat_id
     if chat_id is None:
         raise Exception("Не передан идентификатор чата")
     try:
         if self.keyboard:
             message = tbot.edit_message_text(chat_id=chat_id,
                                              message_id=message_id,
                                              text=self.text,
                                              reply_markup=self.keyboard,
                                              parse_mode="HTML")
             log.info(str(message))
             return
         message = tbot.send_message(chat_id=chat_id,
                                     text=self.text,
                                     parse_mode="HTML")
         log.info(str(message))
         save_message(message)
     except Exception as e:
         print(e)
 def send(self, chat_id: int = None):
     """Метод для отправки ответа."""
     from bot_init.utils import save_message
     if chat_id is None:
         chat_id = self.chat_id
     if chat_id is None:
         raise Exception("Не передан идентификатор чата")
     try:
         if self.keyboard:
             message = tbot.send_message(
                 chat_id=chat_id,
                 text=self.text,
                 reply_markup=self.keyboard,
                 parse_mode="HTML",
             )
             save_message(message, message_key=self.message_key)
             log.info(str(message))
             return
         message = tbot.send_message(chat_id=chat_id, text=self.text, parse_mode="HTML")
         log.info(str(message))
         save_message(message, message_key=self.message_key)
     except Exception as e:
         app_log.error(e)
Example #6
0
def handle_query(call):
    tg_chat_id = call.from_user.id
    data = str(call.data).split(' ')
    sub = Subscriber.objects.get(tg_chat_id=tg_chat_id)
    #call.message.date = 1588073904
    if 'charge' in data[0]:
        date = make_aware(datetime.fromtimestamp(call.message.date))
        status = True if data[1] == 'yes' else False
        Charging.objects.create(subscriber=sub, datetime=date, status=status)
        markup = get_markup('quran: yes', 'quran: no')
        msg = tbot.send_message(tg_chat_id,
                                'Прочитали ли вы сегодня джуз?',
                                reply_markup=markup)
        save_message(msg)
    elif 'quran' in data[0]:
        date = make_aware(datetime.fromtimestamp(call.message.date))
        status = True if data[1] == 'yes' else False
        Quran.objects.create(subscriber=sub, datetime=date, status=status)
        markup = get_markup('book: yes', 'book: no')
        msg = tbot.send_message(tg_chat_id,
                                'Прочитали ли вы сегодня 20 страниц книги',
                                reply_markup=markup)
        save_message(msg)
    elif 'book' in data[0]:
        date = make_aware(datetime.fromtimestamp(call.message.date))
        status = True if data[1] == 'yes' else False
        Book.objects.create(subscriber=sub, datetime=date, status=status)
        markup = get_markup('analyze: yes', 'analyze: no')
        msg = tbot.send_message(tg_chat_id,
                                'Уделили ли вы время самоанализу',
                                reply_markup=markup)
        save_message(msg)
    elif 'analyze' in data[0]:
        sub = Subscriber.objects.get(tg_chat_id=call.from_user.id)
        date = make_aware(datetime.fromtimestamp(call.message.date))
        status = True if data[1] == 'yes' else False
        SelfAnalyze.objects.create(subscriber=sub,
                                   datetime=date,
                                   status=status)

    tbot.delete_message(call.from_user.id, call.message.message_id)
Example #7
0
def start_handler(message):
    """Обработчик команды /start."""
    save_message(message)
    registration_subscriber(message.chat.id)
Example #8
0
def text_handler(message):
    save_message(message)
    answer = text_message_service(message.chat.id, message.text)
    if isinstance(answer, Answer):
        answer.send(chat_id=message.chat.id)
Example #9
0
def start_handler(message):
    """Обработчик команды /start"""
    save_message(message)
    answer = registration_subscriber(message.chat.id, message.text)
    answer.send(chat_id=message.chat.id)