12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- # -*- coding: utf-8 -*-
- """
- Emotibot机器人API:http://www.emotibot.com
- """
- from __future__ import division
- from ..__load__ import *
- from .base import Base
- class Emotibot(Base):
- def __init__(self):
- super(self.__class__, self).__init__()
- def setting(self, appid, location, more, **args):
- self.appid, self.location, self.more = appid, location, more
- def chat(self, fp):
- msg = ''.join(texts)
- try:
- url = "http://idc.emotibot.com/api/ApiKey/openapi.php"
- userid = str(get_mac())[:32]
- register_data = {
- "cmd": "chat",
- "appid": self.appid,
- "userid": userid,
- "text": msg,
- "location": self.location
- }
- r = requests.post(url, params=register_data)
- jsondata = json.loads(r.text)
- result = ''
- responds = []
- if jsondata['return'] == 0:
- if self.more:
- datas = jsondata.get('data')
- for data in datas:
- if data.get('type') == 'text':
- responds.append(data.get('value'))
- else:
- responds.append(jsondata.get('data')[0].get('value'))
- result = '\n'.join(responds)
- else:
- result = "抱歉, 我的大脑短路了,请稍后再试试."
- return self.chatLog(1, result)
- except Exception:
- return self.chatLog(2, msg)
|