jerrita 9 månader sedan
förälder
incheckning
868e8ecbe3
2 ändrade filer med 35 tillägg och 0 borttagningar
  1. 35 0
      plugins/anon/turing.py
  2. 0 0
      requirements.txt

+ 35 - 0
plugins/anon/turing.py

@@ -0,0 +1,35 @@
+from anon import PluginManager
+from anon.event import MessageEvent
+
+import aiohttp
+import json
+
+url = 'http://openapi.tuling123.com/openapi/api/v2'
+
+data = {
+    'reqType': 0,
+    'perception': {
+        'inputText': {
+            'text': 'test'
+        }
+    },
+    'userInfo': {
+        'apiKey': '19894d9f828147549f19be2ea668a9e4',
+        'userId': 'placeholder'
+    }
+}
+
+
+async def getResponse(sentence, uid):
+    data['userInfo']['userId'] = uid
+    data['perception']['inputText']['text'] = sentence
+
+    async with aiohttp.ClientSession() as session:
+        async with session.post(url, json=data) as res:
+            return json.loads(await res.text())['results'][0]['values']['text']
+
+
+@PluginManager().register_event([MessageEvent])
+async def turing(event: MessageEvent):
+    if event.raw.startswith(' '):
+        await event.reply(await getResponse(event.raw.strip(), event.sender.user_id))

+ 0 - 0
requirements.txt