|
@@ -20,7 +20,7 @@ class TulingWXBot(WXBot):
|
|
except Exception:
|
|
except Exception:
|
|
pass
|
|
pass
|
|
print 'tuling_key:', self.tuling_key
|
|
print 'tuling_key:', self.tuling_key
|
|
-
|
|
|
|
|
|
+# 自动回复函数self:发送方用户id, uid, msg
|
|
def tuling_auto_reply(self, uid, msg):
|
|
def tuling_auto_reply(self, uid, msg):
|
|
if self.tuling_key:
|
|
if self.tuling_key:
|
|
url = "http://www.tuling123.com/openapi/api"
|
|
url = "http://www.tuling123.com/openapi/api"
|
|
@@ -35,7 +35,7 @@ class TulingWXBot(WXBot):
|
|
result = respond['url']
|
|
result = respond['url']
|
|
elif respond['code'] == 302000:
|
|
elif respond['code'] == 302000:
|
|
for k in respond['list']:
|
|
for k in respond['list']:
|
|
- result = result + u"【" + k['source'] + u"】 " +\
|
|
|
|
|
|
+ result = result + u"【" + k['source'] + u"】 " + \
|
|
k['article'] + "\t" + k['detailurl'] + "\n"
|
|
k['article'] + "\t" + k['detailurl'] + "\n"
|
|
else:
|
|
else:
|
|
result = respond['text'].replace('<br>', ' ')
|
|
result = respond['text'].replace('<br>', ' ')
|
|
@@ -43,7 +43,7 @@ class TulingWXBot(WXBot):
|
|
print ' ROBOT:', result
|
|
print ' ROBOT:', result
|
|
return result
|
|
return result
|
|
else:
|
|
else:
|
|
- return u"知道啦"
|
|
|
|
|
|
+ return u"知道啦,我是天问机器人,主人马上就来!"
|
|
|
|
|
|
def auto_switch(self, msg):
|
|
def auto_switch(self, msg):
|
|
msg_data = msg['content']['data']
|
|
msg_data = msg['content']['data']
|
|
@@ -59,12 +59,13 @@ class TulingWXBot(WXBot):
|
|
if i == msg_data:
|
|
if i == msg_data:
|
|
self.robot_switch = True
|
|
self.robot_switch = True
|
|
self.send_msg_by_uid(u'[Robot]' + u'机器人已开启!', msg['to_user_id'])
|
|
self.send_msg_by_uid(u'[Robot]' + u'机器人已开启!', msg['to_user_id'])
|
|
-
|
|
|
|
|
|
+# msg dict: {'content': {'data': u'\u53bb', 'type': 0}, 'msg_id': u'3808887025959048251', 'msg_type_id': 4, 'to_user_id': u'@97745d23f2d3bbe5241cede14a3d8baa45809a1842e762b5a33fc1353f6efa3a', 'user': {'id': u'@f95a572b1284a0f75dd550a4ed9a93d788ded42a856db023cd3494faab623311', 'name': u'\u5929\u95ee'}}
|
|
def handle_msg_all(self, msg):
|
|
def handle_msg_all(self, msg):
|
|
if not self.robot_switch and msg['msg_type_id'] != 1:
|
|
if not self.robot_switch and msg['msg_type_id'] != 1:
|
|
return
|
|
return
|
|
if msg['msg_type_id'] == 1 and msg['content']['type'] == 0: # reply to self
|
|
if msg['msg_type_id'] == 1 and msg['content']['type'] == 0: # reply to self
|
|
self.auto_switch(msg)
|
|
self.auto_switch(msg)
|
|
|
|
+ # msg_type_id=4 发送文字
|
|
elif msg['msg_type_id'] == 4 and msg['content']['type'] == 0: # text message from contact
|
|
elif msg['msg_type_id'] == 4 and msg['content']['type'] == 0: # text message from contact
|
|
self.send_msg_by_uid(self.tuling_auto_reply(msg['user']['id'], msg['content']['data']), msg['user']['id'])
|
|
self.send_msg_by_uid(self.tuling_auto_reply(msg['user']['id'], msg['content']['data']), msg['user']['id'])
|
|
elif msg['msg_type_id'] == 3 and msg['content']['type'] == 0: # group text message
|
|
elif msg['msg_type_id'] == 3 and msg['content']['type'] == 0: # group text message
|
|
@@ -92,8 +93,15 @@ class TulingWXBot(WXBot):
|
|
else:
|
|
else:
|
|
reply += u"对不起,只认字,其他杂七杂八的我都不认识,,,Ծ‸Ծ,,"
|
|
reply += u"对不起,只认字,其他杂七杂八的我都不认识,,,Ծ‸Ծ,,"
|
|
self.send_msg_by_uid(reply, msg['user']['id'])
|
|
self.send_msg_by_uid(reply, msg['user']['id'])
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ else:
|
|
|
|
+ src_name = msg['content']['user']['name']
|
|
|
|
+ reply = 'to ' + src_name + ': '
|
|
|
|
+ reply += u"对不起,只认字,其他杂七杂八的我都不认识,,,Ծ‸Ծ,,"
|
|
|
|
+ self.send_msg_by_uid(reply, msg['user']['id'])
|
|
|
|
+
|
|
|
|
+'''
|
|
|
|
+主函数,执行TulingWXBot类里面的run方法
|
|
|
|
+'''
|
|
def main():
|
|
def main():
|
|
bot = TulingWXBot()
|
|
bot = TulingWXBot()
|
|
bot.DEBUG = True
|
|
bot.DEBUG = True
|