当前位置: 首页>>代码示例>>Python>>正文


Python Messenger.write_error方法代码示例

本文整理汇总了Python中messenger.Messenger.write_error方法的典型用法代码示例。如果您正苦于以下问题:Python Messenger.write_error方法的具体用法?Python Messenger.write_error怎么用?Python Messenger.write_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在messenger.Messenger的用法示例。


在下文中一共展示了Messenger.write_error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import write_error [as 别名]
    def start(self, resource):
        """Creates Slack Web and RTM clients for the given Resource
        using the provided API tokens and configuration, then
        connects websocket and listens for RTM events.

        Args:
            resource (dict of Resource JSON): See message payloads:
            https://beepboophq.com/docs/article/resourcer-api
        """
        logger.info('Starting bot for resource: {}'.format(resource))
        if ('resource' in resource and
                'SlackBotAccessToken' in resource['resource']):
            res_access_token = resource['resource']['SlackBotAccessToken']
            self.clients = SlackClients(res_access_token)

        if self.clients.rtm.rtm_connect():
            logging.info(
                u'Connected {} to {} team at https://{}.slack.com'.format(
                    self.clients.rtm.server.username,
                    self.clients.rtm.server.login_data['team']['name'],
                    self.clients.rtm.server.domain
                )
            )

            msg_writer = Messenger(self.clients)

            # Random markov here
            markov_chain = Markov(3, msg_writer)

            config_manager.start_config_loader()

            event_handler = RtmEventHandler(
                self.clients, msg_writer, markov_chain
            )
            time_event_handler = TimeTriggeredEventManager(
                self.clients, msg_writer, markov_chain
            )

            os.chmod('./scripts/make_config.sh', 0755)

            while self.keep_running:
                for event in self.clients.rtm.rtm_read():
                    try:
                        event_handler.handle(event)
                    except:
                        err_msg = traceback.format_exc()
                        logging.error('Unexpected error: {}'.format(err_msg))
                        msg_writer.write_error(err_msg, event['channel'])
                        continue

                self._auto_ping(time_event_handler)
                time.sleep(.1)
        else:
            logger.error(
                'Failed to connect to RTM client with token: {}'.format(
                    self.clients.token
                )
            )
开发者ID:ianadmu,项目名称:starter-python-bot,代码行数:60,代码来源:slack_bot.py

示例2: start

# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import write_error [as 别名]
    def start(self, resource):
        """Creates Slack Web and RTM clients for the given Resource
        using the provided API tokens and configuration, then connects websocket
        and listens for RTM events.

        Args:
            resource (dict of Resource JSON): See message payloads - https://beepboophq.com/docs/article/resourcer-api
        """

        logger.debug("Python Version: " + sys.version)
        logging.info('Starting bot for resource: {}'.format(resource))
        if 'resource' in resource and 'SlackBotAccessToken' in resource['resource']:
            res_access_token = resource['resource']['SlackBotAccessToken']
            self.clients = SlackClients(res_access_token)

        if self.clients.rtm.rtm_connect():
            logging.info(u'Connected {} to {} team at https://{}.slack.com'.format(
                self.clients.rtm.server.username,
                self.clients.rtm.server.login_data['team']['name'],
                self.clients.rtm.server.domain))

            msg_writer = Messenger(self.clients)
            event_handler = RtmEventHandler(self.clients, msg_writer)

            while self.keep_running:
                for event in self.clients.rtm.rtm_read():
                    try:
                        event_handler.handle(event)
                    except:
                        err_msg = traceback.format_exc()
                        logging.error('Unexpected error: {}'.format(err_msg))
                        msg_writer.write_error(event['channel'], err_msg)
                        continue

                self._auto_ping()
                time.sleep(.1)

        else:
            logger.error('Failed to connect to RTM client with token: {}'.format(self.clients.token))
开发者ID:davenewham,项目名称:starter-python-bot,代码行数:41,代码来源:slack_bot.py


注:本文中的messenger.Messenger.write_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。