diff options
author | Kyomotoi <[email protected]> | 2020-06-21 14:50:04 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2020-06-21 14:50:04 +0800 |
commit | fa41d1bf035a2ffaf51e7255d7148ba779ae2cb4 (patch) | |
tree | ec6b81f575ab30ce7a0edf18c1fb6f89fd352003 /AyaBot/plugins | |
parent | d320ea0800c02f6d67dbbd645d49d690021b1440 (diff) | |
download | ATRI-fa41d1bf035a2ffaf51e7255d7148ba779ae2cb4.tar.gz ATRI-fa41d1bf035a2ffaf51e7255d7148ba779ae2cb4.tar.bz2 ATRI-fa41d1bf035a2ffaf51e7255d7148ba779ae2cb4.zip |
First official version
Diffstat (limited to 'AyaBot/plugins')
-rw-r--r-- | AyaBot/plugins/__pycache__/chat.cpython-37.pyc | bin | 0 -> 2726 bytes | |||
-rw-r--r-- | AyaBot/plugins/__pycache__/covid19.cpython-37.pyc | bin | 2252 -> 2291 bytes | |||
-rw-r--r-- | AyaBot/plugins/__pycache__/other.cpython-37.pyc | bin | 1953 -> 2498 bytes | |||
-rw-r--r-- | AyaBot/plugins/__pycache__/setu.cpython-37.pyc | bin | 3586 -> 3596 bytes | |||
-rw-r--r-- | AyaBot/plugins/__pycache__/translate.cpython-37.pyc | bin | 1756 -> 1795 bytes | |||
-rw-r--r-- | AyaBot/plugins/__pycache__/weather.cpython-37.pyc | bin | 6213 -> 6252 bytes | |||
-rw-r--r-- | AyaBot/plugins/chat.py | 80 | ||||
-rw-r--r-- | AyaBot/plugins/setu.py | 8 |
8 files changed, 85 insertions, 3 deletions
diff --git a/AyaBot/plugins/__pycache__/chat.cpython-37.pyc b/AyaBot/plugins/__pycache__/chat.cpython-37.pyc Binary files differnew file mode 100644 index 0000000..ad1818d --- /dev/null +++ b/AyaBot/plugins/__pycache__/chat.cpython-37.pyc diff --git a/AyaBot/plugins/__pycache__/covid19.cpython-37.pyc b/AyaBot/plugins/__pycache__/covid19.cpython-37.pyc Binary files differindex 7524c7d..f1a5940 100644 --- a/AyaBot/plugins/__pycache__/covid19.cpython-37.pyc +++ b/AyaBot/plugins/__pycache__/covid19.cpython-37.pyc diff --git a/AyaBot/plugins/__pycache__/other.cpython-37.pyc b/AyaBot/plugins/__pycache__/other.cpython-37.pyc Binary files differindex 1b4d258..9934055 100644 --- a/AyaBot/plugins/__pycache__/other.cpython-37.pyc +++ b/AyaBot/plugins/__pycache__/other.cpython-37.pyc diff --git a/AyaBot/plugins/__pycache__/setu.cpython-37.pyc b/AyaBot/plugins/__pycache__/setu.cpython-37.pyc Binary files differindex 66e8215..1bca92b 100644 --- a/AyaBot/plugins/__pycache__/setu.cpython-37.pyc +++ b/AyaBot/plugins/__pycache__/setu.cpython-37.pyc diff --git a/AyaBot/plugins/__pycache__/translate.cpython-37.pyc b/AyaBot/plugins/__pycache__/translate.cpython-37.pyc Binary files differindex 42462a8..17bf117 100644 --- a/AyaBot/plugins/__pycache__/translate.cpython-37.pyc +++ b/AyaBot/plugins/__pycache__/translate.cpython-37.pyc diff --git a/AyaBot/plugins/__pycache__/weather.cpython-37.pyc b/AyaBot/plugins/__pycache__/weather.cpython-37.pyc Binary files differindex 02ebb2f..b931e84 100644 --- a/AyaBot/plugins/__pycache__/weather.cpython-37.pyc +++ b/AyaBot/plugins/__pycache__/weather.cpython-37.pyc diff --git a/AyaBot/plugins/chat.py b/AyaBot/plugins/chat.py new file mode 100644 index 0000000..38a4759 --- /dev/null +++ b/AyaBot/plugins/chat.py @@ -0,0 +1,80 @@ +# -*- coding:utf-8 -*- +import time +import httpx +import string +import nonebot +import hashlib +from AyaBot.plugins import * +from random import randint +from urllib.parse import urlencode +from nonebot.helpers import context_id, render_expression +from nonebot import on_command, CommandSession, on_natural_language, NLPSession, IntentCommand + +bot = nonebot.get_bot() + +ERROR_REPLY = ( + '吾辈不是很能理解主人的意思...', + '(。´・ω・)ん?', + 'ん?', + 'あつ...脑子坏了..理解不能', + '吾辈想听主人再说一次...' +) + +class Chat(object): + URL = 'https://api.ai.qq.com/fcgi-bin/nlp/nlp_textchat' + app_id = bot.config.TX_APP_ID + app_key = bot.config.TX_APPKEY + print(app_id, app_key) + nonce_str_example = 'fa577ce340859f9fe' + ct = lambda: time.time() + + @classmethod + def get_nonce_str(self): + nonce_str = '' + len_str = string.digits + string.ascii_letters + for i in range(len(self.nonce_str_example)): + nonce_str += len_str[randint(0, len(len_str) - 1)] + return nonce_str + + @classmethod + def sign(self, req_data): + new_list = sorted(req_data.items()) + encode_list = urlencode(new_list) + req_data = encode_list + "&" + "app_key" + "=" + self.app_key + md5 = hashlib.md5() + md5.update(req_data.encode('utf-8')) + data = md5.hexdigest() + return data.upper() + + @classmethod + async def request(self, text): + req_data = { + 'app_id': self.app_id, + 'time_stamp': int(self.ct()), + 'nonce_str': self.get_nonce_str(), + 'session': 10000, + 'question': text, + } + print(req_data) + req_data['sign'] = self.sign(req_data) + req_data = sorted(req_data.items()) + requests = httpx.AsyncClient() + result = await requests.get(self.URL, params=req_data) + await requests.aclose() + result = result.json() + print(result) + if result['ret'] == 0: + return result['data']['answer'] + return render_expression(ERROR_REPLY) + + +@on_command('chat') +async def chat(session: CommandSession): + msg = session.state.get('msg') + reply = await Chat.request(msg) + await session.finish(reply) + return + +@on_natural_language +async def _(session: NLPSession): + return IntentCommand(60.0, ('chat'), {'msg': session.msg_text})
\ No newline at end of file diff --git a/AyaBot/plugins/setu.py b/AyaBot/plugins/setu.py index f0d5365..3f24129 100644 --- a/AyaBot/plugins/setu.py +++ b/AyaBot/plugins/setu.py @@ -7,6 +7,7 @@ import requests from aiohttp import ClientSession from nonebot import on_command, CommandSession +bot = nonebot.get_bot() async def post_bytes(url, headers=None,data=None): async with ClientSession() as asyncsession: @@ -62,8 +63,9 @@ async def _(session: CommandSession): await session.send(f'[CQ:image,file={pt}]') if r == '2': url = 'https://api.lolicon.app/setu/' + apikey = bot.config.LOLICONAPI values = { - "apikey": "574300555ee56eb2be5e03", + "apikey": apikey, "r18": "0", "num": "1" } @@ -78,7 +80,7 @@ async def _(session: CommandSession): # if r == '2': # URL = 'https://danbooru.donmai.us/post.json' # values = { - # "api_key": "UoTNRNeta73tqqdGVvsU9mmH" + # "api_key": "" # } # response = requests.get(URL, params=values) # html = response.text @@ -89,7 +91,7 @@ async def _(session: CommandSession): # if r == '3': # URL = 'https://yande.re/post.json' # values = { - # "api_key": "zgBbal8sZVuRYp3UNX5Frg" + # "api_key": "" # } # response = requests.get(URL, params=values) # html = response.text |