diff --git a/client/dingdangpath.py b/client/dingdangpath.py index c9cdec7..c127d51 100755 --- a/client/dingdangpath.py +++ b/client/dingdangpath.py @@ -7,6 +7,7 @@ DATA_PATH = os.path.join(APP_PATH, "static") LIB_PATH = os.path.join(APP_PATH, "client") +TEMP_PATH = os.path.join(APP_PATH, "temp") PLUGIN_PATH = os.path.join(LIB_PATH, "plugins") CONFIG_PATH = os.path.expanduser(os.getenv diff --git a/client/plugins/SendQR.py b/client/plugins/SendQR.py new file mode 100644 index 0000000..fe42431 --- /dev/null +++ b/client/plugins/SendQR.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8-*- + +import os +import sys + +WORDS = [u"ERWEIMA"] + + +def handle(text, mic, profile, wxbot=None): + """ + Reports the current time based on the user's timezone. + + Arguments: + text -- user-input, typically transcribed speech + mic -- used to interact with the user (for both input and output) + profile -- contains information related to the user (e.g., phone + number) + wxbot -- wechat bot instance + """ + if 'wechat' not in profile or not profile['wechat']: + mic.say(u'请先在配置文件中开启微信接入功能') + return + if 'email' not in profile or ('enable' in profile['email'] + and not profile['email']): + mic.say(u'请先配置好邮箱功能') + return + sys.path.append(mic.dingdangpath.LIB_PATH) + from app_utils import emailUser + dest_file = os.path.join(mic.dingdangpath.TEMP_PATH, 'wxqr.png') + if os.path.exists(dest_file): + mic.say(u'正在发送微信登录二维码到您的邮箱') + if emailUser(profile, u"这是您的微信登录二维码", "", [dest_file]): + mic.say(u'发送成功') + else: + mic.say(u'发送失败') + else: + mic.say(u"微信接入失败") + + +def isValid(text): + """ + Returns True if input is related to the time. + + Arguments: + text -- user-input, typically transcribed speech + """ + return all(word in text for word in ["微信", "二维码"]) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 8c1828a..e03abf8 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -2,7 +2,7 @@ # -*- coding: utf-8-*- from nose.tools import * from client import test_mic, diagnose, dingdangpath -from client.plugins import Time, Echo, Email +from client.plugins import Time, Echo, Email, SendQR DEFAULT_PROFILE = { 'prefers_email': False, @@ -52,4 +52,12 @@ def testEmail(self): inputs = [] self.runConversation(query, inputs, Gmail) + def testSendQR(self): + if 'wechat' not in self.profile or not self.profile['wechat']: + return + + query = u"发送微信二维码" + inputs = [] + self.runConversation(query, inputs, SendQR) +