diff options
author | Kyomotoi <1172294279@qq.com> | 2020-07-17 21:36:55 +0800 |
---|---|---|
committer | Kyomotoi <1172294279@qq.com> | 2020-07-17 21:36:55 +0800 |
commit | 77514e99f0308ed90dc031810f71c67771971878 (patch) | |
tree | 1611339c44a607dc313c11500c5b0284431fb623 /ATRIbot/plugins/hitokoto.py | |
parent | 0efc5d2b0f3d7395715c30bd453d0c4a78d6101d (diff) | |
download | ATRI-77514e99f0308ed90dc031810f71c67771971878.tar.gz ATRI-77514e99f0308ed90dc031810f71c67771971878.tar.bz2 ATRI-77514e99f0308ed90dc031810f71c67771971878.zip |
[FIX]
Diffstat (limited to 'ATRIbot/plugins/hitokoto.py')
-rw-r--r-- | ATRIbot/plugins/hitokoto.py | 30 |
1 files changed, 30 insertions, 0 deletions
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 |