Exemple #1
0
 def validate(self):
     next_point = self.get_session('next')
     if not check_next(next_point) or not isinstance(self, next_point[0]):
         raise CriticalError
     if self.validator and issubclass(self.validator,
                                      validators.BaseValidator):
         self.data = self.validator().validate(self.message.text)
     if self.valid_name and self.data is not None:
         return merge_dicts(next_point[1], {self.valid_name: self.data})
     return next_point[1]
Exemple #2
0
 def entrypoint(self, bot, update):
     super(BaseStep, self).entrypoint(bot, update)
     try:
         params = self.validate()
     except ValidationError as e:
         self.send_message(e.message)
         return (type(self), self.get_session('next')[1])
     try:
         result = self.run(**params)
         if check_next(result):
             return result
     except Exception as e:
         logger.error(e)
Exemple #3
0
 def entrypoint(self, bot, update):
     self.load(bot, update)
     try:
         Post.get(Post.id == self.get_session('post_id'))
         next_point = self.run()
         if check_next(next_point):
             self.set_session(**next_point[1])
             return next_point[0](self.session).entrypoint(bot, update)
         self.send_message('system error')
     except:
         posts = self.print_posts()
         if posts:
             self.set_session(posts=posts)
         super(BasePostCommand, self).entrypoint(bot, update)
Exemple #4
0
 def entirypoint(self, bot, update):
     super(Bot, self).entrypoint(bot, update)
     if self.is_post():
         return
     next_point = self.get_session('next')
     if check_next(next_point):
         try:
             result = next_point[0](self.session).entrypoint(bot, update)
             self.check_next(result)
         except Exception as e:
             logger.error(e)
     else:
         self.reset_session()
         helps = []
         keyboards = []
         for com in self.list_commands:
             helps.append(com.help_text())
             keyboards.append('/{}'.format(com.command))
         text = '*Commands*\n{}'.format('\n'.join(helps))
         self.send_message(text, keyboards=keyboard_split(keyboards, config.COMMANDS_IN_LINE))
Exemple #5
0
 def check_next(self, data):
     if check_next(data):
         self.set_session(next=data)
     else:
         self.reset_session()