本文整理汇总了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
)
)
示例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))