def handle_new_message(self, message: Message):
     if self._offered:
         if message.text == confirm_button.text:
             self._offered = False
             self.try_offer()
         elif message.text == refuse_button.text:
             requests.post(cfg.get('API', 'API_ADDRESS') + f'/student_declines/{self._bot.get_current_user()}',
                           {'contest_id': self.current_event['contest']['id']})
             self._bot.send_message(Message(ok_text))
             self._offered = False
             self.try_offer()
         else:
             self._bot.send_message(Message(command_error_text))
     else:
         self._bot.send_message(Message(empty_event_queue_text))
Exemple #2
0
 def handle_new_message(self, message: Message):
     if test_fio(message.text):
         requests.put(cfg.get('API', 'API_ADDRESS') + f'/student/{self._bot.get_current_user()}',
                      {'name': message.text})
         self.on_page_changing.notify(RegionInputPage(self._bot))
     else:
         self._bot.send_message(Message(error_text))
 def handle_new_message(self, message: Message):
     if test_target_year(message.text, self._bot.get_current_user()):
         requests.put(
             cfg.get('API', 'API_ADDRESS') +
             f'/student/{self._bot.get_current_user()}',
             {'target_year': message.text})
         self.on_page_changing.notify(SubjectsInputPage(self._bot))
     else:
         self._bot.send_message(Message(error_text))
 def offer_front_event(self):
     event = self._events_queue.popleft()
     self.current_event = event
     self._bot.send_message(Message(new_notification_pattern.format(
         event['contest']['name'],
         event['stage']['name'],
         event['stage']['starting_date'],
         event['stage']['ending_date'],
         event['contest']['description'],
         event['stage']['description']
     )))
     self._bot.set_keyboard(local_menu, message='Выберите один из предложенных вариантов.')
 def handle_new_message(self, message: Message):
     if self._state == MENU_STATE:
         if message.text == adding_button.text:
             self._bot.send_message(Message(adding_state_text))
             self._state = ADDING_STATE
         elif message.text == deleting_button.text:
             self._state = DELETING_STATE
         elif message.text == finishing_button.text:
             requests.put(
                 cfg.get('API', 'API_ADDRESS') +
                 f'/student/{self._bot.get_current_user()}',
                 {'subjects': str(self._subjects)})
             self.on_page_changing.notify(RegistrationEndingPage(self._bot))
             return
         else:
             self._bot.set_keyboard(local_menu, message=keyboard_message)
     elif self._state == ADDING_STATE:
         if not self.try_to_add_subject(message.text):
             self._bot.send_message(Message(subject_does_not_exist_text))
         else:
             self._bot.send_message(Message(subject_added_text))
         self._bot.set_keyboard(local_menu, message=keyboard_message)
         self._state = MENU_STATE
     elif self._state == DELETING_STATE:
         self.delete_subject(message.text)
         self._bot.send_message(Message(subject_deleted_text))
         self._bot.set_keyboard(local_menu, message=keyboard_message)
         self._state = MENU_STATE
     if len(self._subjects):
         self._bot.send_message(
             Message(
                 f'{subjects_list_prefix} {"; ".join(map(lambda x: x["name"], self._subjects))}.'
             ))
     else:
         self._bot.send_message(Message(subjects_does_not_chosen_text))
Exemple #6
0
 def run(self) -> NoReturn:
     print('Бот начал работу!')
     schedule.every(5).seconds.do(self.handle_server_event)
     while True:
         try:
             for event in self._longpoll.check():
                 if event.type == VkBotEventType.MESSAGE_NEW and event.from_user:
                     self.change_user(event.message.from_id)
                     self.on_new_message.notify(
                         Message(event.message.get('text', '')))
             schedule.run_pending()
         except requests.ConnectionError:
             print(f'{datetime.now()}: Не удается подключиться к серверу!')
 def handle_starting(self):
     self._bot.send_message(Message(page_starting_text))
     self._bot.set_keyboard(local_menu, message=keyboard_message)
 def handle_starting(self):
     self._events_queue = deque()
     self._offered = False
     self.current_event = {}
     self._bot.send_message(Message(page_starting_text))
Exemple #9
0
 def handle_starting(self):
     self._bot.send_message(Message(page_starting_text))
Exemple #10
0
 def handle_starting(self):
     self._bot.send_message(Message(introduction_text))
     self.on_page_changing.notify(NameInputPage(self._bot))
Exemple #11
0
 def handle_starting(self):
     self._bot.send_message(Message(registration_ending_text))
     self.on_page_changing.notify(NotificationsHandlerPage(self._bot))