Skip to content
This repository has been archived by the owner on Apr 13, 2018. It is now read-only.

Commit

Permalink
将大部分官方插件加入缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Dec 24, 2017
1 parent a8ac27d commit 1f84a21
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions client/plugins/Camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def handle(text, mic, profile, wxbot=None):
if not os.path.exists(dest_path):
os.makedirs(dest_path)
except Exception:
mic.say(u"抱歉,照片目录创建失败")
mic.say(u"抱歉,照片目录创建失败", cache=True)
return
dest_file = os.path.join(dest_path, "%s.jpg" % time.time())
if usb_camera:
Expand All @@ -83,15 +83,15 @@ def handle(text, mic, profile, wxbot=None):
if horizontal_flip:
command.append('-hf')
if sound and count_down > 0:
mic.say(u"收到,%d秒后启动拍照" % (count_down))
mic.say(u"收到,%d秒后启动拍照" % (count_down), cache=True)
if usb_camera:
time.sleep(count_down)

process = subprocess.Popen(command, shell=usb_camera)
res = process.wait()
if res != 0:
if sound:
mic.say(u"拍照失败,请检查相机是否连接正确")
mic.say(u"拍照失败,请检查相机是否连接正确", cache=True)
return
if sound:
mic.play(mic.dingdangpath.data('audio', 'camera.wav'))
Expand All @@ -103,15 +103,15 @@ def handle(text, mic, profile, wxbot=None):
not profile['prefers_email']):
target = '微信'
if sound:
mic.say(u'拍照成功!正在发送照片到您的%s' % target)
mic.say(u'拍照成功!正在发送照片到您的%s' % target, cache=True)
if sendToUser(profile, wxbot, u"这是刚刚为您拍摄的照片", "", [], [dest_file]):
if sound:
mic.say(u'发送成功')
mic.say(u'发送成功', cache=True)
else:
if sound:
mic.say(u'发送失败了')
mic.say(u'发送失败了', cache=True)
else:
mic.say(u"请先在配置文件中开启相机拍照功能")
mic.say(u"请先在配置文件中开启相机拍照功能", cache=True)


def isValid(text):
Expand Down
4 changes: 2 additions & 2 deletions client/plugins/Chatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def handle(text, mic, profile, wxbot=None):
wxbot -- wechat bot instance
"""
if not any(word in text for word in [u"结束", u"停止", u"退出", u"不聊了"]):
mic.say(u"进入闲聊模式,现在跟我说说话吧")
mic.say(u"进入闲聊模式,现在跟我说说话吧", cache=True)
mic.chatting_mode = True
mic.skip_passive = True
else:
mic.say(u"退出闲聊模式")
mic.say(u"退出闲聊模式", cache=True)
mic.skip_passive = False
mic.chatting_mode = False

Expand Down
6 changes: 3 additions & 3 deletions client/plugins/Email.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,18 @@ def handle(text, mic, profile, wxbot=None):

if msgs is None:
mic.say(
u"抱歉,您的邮箱账户验证失败了")
u"抱歉,您的邮箱账户验证失败了", cache=True)
return

if isinstance(msgs, int):
response = "您有 %d 封未读邮件" % msgs
mic.say(response)
mic.say(response, cache=True)
return

senders = [getSender(e) for e in msgs]

if not senders:
mic.say(u"您没有未读邮件,真棒!")
mic.say(u"您没有未读邮件,真棒!", cache=True)
elif len(senders) == 1:
mic.say(u"您有来自 " + senders[0] + " 的未读邮件")
else:
Expand Down
12 changes: 6 additions & 6 deletions client/plugins/SendQR.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ def handle(text, mic, profile, wxbot=None):
wxbot -- wechat bot instance
"""
if 'wechat' not in profile or not profile['wechat'] or wxbot is None:
mic.say(u'请先在配置文件中开启微信接入功能')
mic.say(u'请先在配置文件中开启微信接入功能', cache=True)
return
if 'email' not in profile or ('enable' in profile['email']
and not profile['email']):
mic.say(u'请先配置好邮箱功能')
mic.say(u'请先配置好邮箱功能', cache=True)
return
sys.path.append(mic.dingdangpath.LIB_PATH)
from app_utils import emailUser
dest_file = os.path.join(mic.dingdangpath.TEMP_PATH, 'wxqr.png')
wxbot.get_uuid()
wxbot.gen_qr_code(dest_file)
if os.path.exists(dest_file):
mic.say(u'正在发送微信登录二维码到您的邮箱')
mic.say(u'正在发送微信登录二维码到您的邮箱', cache=True)
if emailUser(profile, u"这是您的微信登录二维码", "", [dest_file]):
mic.say(u'发送成功')
mic.say(u'发送成功', cache=True)
else:
mic.say(u'发送失败')
mic.say(u'发送失败', cache=True)
else:
mic.say(u"微信接入失败")
mic.say(u"微信接入失败", cache=True)


def isValid(text):
Expand Down
2 changes: 1 addition & 1 deletion client/plugins/Unclear.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def handle(text, mic, profile, wxbot=None):
u"听不清楚呢,可以再为我说一次吗?",
u"再说一遍好吗?"]
message = random.choice(messages)
mic.say(message)
mic.say(message, cache=True)


def isValid(text):
Expand Down
20 changes: 10 additions & 10 deletions client/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ def chat(self, texts):
if self.wxbot is not None and self.wxbot.my_account != {} \
and not self.profile['prefers_email']:
target = '微信'
self.mic.say(u'一言难尽啊,我给您发%s吧' % target)
self.mic.say(u'一言难尽啊,我给您发%s吧' % target, cache=True)
if sendToUser(self.profile, self.wxbot, u'回答%s' % msg, result):
self.mic.say(u'%s发送成功!' % target)
self.mic.say(u'%s发送成功!' % target, cache=True)
else:
self.mic.say(u'抱歉,%s发送失败了!' % target)
self.mic.say(u'抱歉,%s发送失败了!' % target, cache=True)
else:
self.mic.say(result)
self.mic.say(result, cache=True)
if result.endswith('?') or result.endswith(u'?') or \
u'告诉我' in result or u'请回答' in result:
self.mic.skip_passive = True
except Exception:
self._logger.critical("Tuling robot failed to responsed for %r",
msg, exc_info=True)
self.mic.say("抱歉, 我的大脑短路了 " +
"请稍后再试试.")
"请稍后再试试.", cache=True)


class Emotibot(AbstractRobot):
Expand Down Expand Up @@ -189,13 +189,13 @@ def chat(self, texts):
if self.wxbot is not None and self.wxbot.my_account != {} \
and not self.profile['prefers_email']:
target = '微信'
self.mic.say(u'一言难尽啊,我给您发%s吧' % target)
self.mic.say(u'一言难尽啊,我给您发%s吧' % target, cache=True)
if sendToUser(self.profile, self.wxbot, u'回答%s' % msg, result):
self.mic.say(u'%s发送成功!' % target)
self.mic.say(u'%s发送成功!' % target, cache=True)
else:
self.mic.say(u'抱歉,%s发送失败了!' % target)
self.mic.say(u'抱歉,%s发送失败了!' % target, cache=True)
else:
self.mic.say(result)
self.mic.say(result, cache=True)
if result.endswith('?') or result.endswith(u'?') or \
u'告诉我' in result or u'请回答' in result:
self.mic.skip_passive = True
Expand All @@ -204,7 +204,7 @@ def chat(self, texts):
self._logger.critical("Emotibot failed to responsed for %r",
msg, exc_info=True)
self.mic.say("抱歉, 我的大脑短路了 " +
"请稍后再试试.")
"请稍后再试试.", cache=True)


def get_robot_by_slug(slug):
Expand Down

0 comments on commit 1f84a21

Please sign in to comment.