def message_handler_thread_work(self):
self.bot_handle=telepot.Bot(self.token)
bot_bind_ok=False
activation_fail_announce=False
while bot_bind_ok==False:
try:
self.bot_handle.getMe()[u"username"]
bot_bind_ok=True
except:
if activation_fail_announce==False:
report("w","<"+self.allowed_user+"> "+"Message handler activation error. Will keep trying...")
activation_fail_announce=True
time.sleep(LISTENER_SERVICE_THREAD_HEARTBEAT_SECONDS)
self.listener.consume_user_messages(self.allowed_user)
report("w","<"+self.allowed_user+"> "+"Message handler for user \""+self.allowed_user+"\" is now active.")
while self.keep_running.is_set()==True:
time.sleep(USER_MESSAGE_HANDLER_THREAD_HEARTBEAT_SECONDS)
self.check_tasks()
if self.listen_flag.is_set()==True:
new_messages=self.listener.consume_user_messages(self.allowed_user)
total_new_messages=len(new_messages)
if total_new_messages>0:
report("w","<"+self.allowed_user+"> "+str(total_new_messages)+" new message(s) received.")
self.process_messages(new_messages)
report("w","<"+self.allowed_user+"> "+"Message handler exited.")
self.bot_has_exited.set()
return
评论列表
文章目录