From 77514e99f0308ed90dc031810f71c67771971878 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Fri, 17 Jul 2020 21:36:55 +0800 Subject: [FIX] --- ATRIbot/plugins/hitokoto.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ATRIbot/plugins/hitokoto.py (limited to 'ATRIbot/plugins/hitokoto.py') diff --git a/ATRIbot/plugins/hitokoto.py b/ATRIbot/plugins/hitokoto.py new file mode 100644 index 0000000..d5f05a3 --- /dev/null +++ b/ATRIbot/plugins/hitokoto.py @@ -0,0 +1,30 @@ +# -*- coding:utf-8 -*- +import asyncio +import requests +from typing import Any +from functools import partial +from nonebot import on_command, CommandSession + + +class AsyncResponse: + def __init__(self, response: requests.Response): + self.raw_response = response + +async def run_sync_func(func, *args, **kwargs) -> Any: + return await asyncio.get_event_loop().run_in_executor( + None, partial(func, *args, **kwargs)) + +async def request(method, url, **kwargs) -> AsyncResponse: + return AsyncResponse(await run_sync_func(requests.request, + method=method, url=url, **kwargs)) + + +url = "https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=&fun=sync&source=" + + +@on_command('hitokoto', aliases=['一言'], only_to_me=False) +async def _(session: CommandSession): + res = requests.get(url) + if not res.ok: + session.finish('获取失败') + session.finish(res.text) \ No newline at end of file -- cgit v1.2.3