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

Commit

Permalink
增加SendQR插件,允许发送微信登录二维码到邮箱
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Jun 10, 2017
1 parent 50b999b commit 25c0c9b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/dingdangpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions client/plugins/SendQR.py
Original file line number Diff line number Diff line change
@@ -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 ["微信", "二维码"])
10 changes: 9 additions & 1 deletion tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)


0 comments on commit 25c0c9b

Please sign in to comment.