示例#1
0
文件: flows.py 项目: e4r7hbug/errbot
 def check_user(self, msg, flow):
     """Checks to make sure that either the user started the flow, or is a bot admin"""
     if glob(get_acl_usr(msg), self.bot_config.BOT_ADMINS):
         return True
     elif glob(get_acl_usr(msg), flow.requestor.person):
         return True
     return False
示例#2
0
文件: flows.py 项目: zoni/errbot
 def check_user(self, msg, flow):
     """Checks to make sure that either the user started the flow, or is a bot admin
     """
     if glob(get_acl_usr(msg), self.bot_config.BOT_ADMINS):
         return True
     elif glob(get_acl_usr(msg), flow.requestor.person):
         return True
     return False
示例#3
0
    def flows_status(self, msg, args):
        """ Displays the list of started flows.
        """
        with io.StringIO() as response:
            if not self._bot.flow_executor.in_flight:
                response.write('No Flow started.\n')

            else:
                if not [flow for flow in self._bot.flow_executor.in_flight if self.check_user(msg, flow)]:
                    response.write('No Flow started for current user: \n{}\n'.format(get_acl_usr(msg)))

                else:
                    if args:
                        for flow in self._bot.flow_executor.in_flight:
                            if self.check_user(msg, flow):
                                if flow.name == args:
                                    self.recurse_node(response, [], flow.root, flow)

                    else:
                        for flow in self._bot.flow_executor.in_flight:
                            if self.check_user(msg, flow):
                                next_steps = ['\\*{}\\*'.format(str(step[1].command)) for step in
                                              flow._current_step.children if step[1].command]
                                template = '\\>>> {} is using flow \\*{}\\* on step \\*{}\\*\nNext Step(s): \n{}'
                                text = template.format(str(flow.requestor),
                                                       flow.name,
                                                       str(flow.current_step),
                                                       '\n'.join(next_steps))
                                response.write(text)
            return response.getvalue()