summaryrefslogtreecommitdiff
path: root/AyaBot/plugins/hitokoto.py
diff options
context:
space:
mode:
Diffstat (limited to 'AyaBot/plugins/hitokoto.py')
-rw-r--r--AyaBot/plugins/hitokoto.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/AyaBot/plugins/hitokoto.py b/AyaBot/plugins/hitokoto.py
index d621bb5..d6dc5a4 100644
--- a/AyaBot/plugins/hitokoto.py
+++ b/AyaBot/plugins/hitokoto.py
@@ -1,30 +1,30 @@
import json
+import asyncio
import requests
-import pandas as pd
+from typing import Any
+from functools import partial
from nonebot import on_command, CommandSession
-from datetime import datetime
-url_1 = 'https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source='
-response_1 = requests.get(url=url_1).json()
-data_1 = json.load(response_1)
+class AsyncResponse:
+ def __init__(self, response: requests.Response):
+ self.raw_response = response
-filename1 = "data_1.json"
+async def run_sync_func(func, *args, **kwargs) -> Any:
+ return await asyncio.get_event_loop().run_in_executor(
+ None, partial(func, *args, **kwargs))
-LIST = """一言
-{hitokoto}
-by {source}
-"""
+async def request(method, url, **kwargs) -> AsyncResponse:
+ return AsyncResponse(await run_sync_func(requests.request,
+ method=method, url=url, **kwargs))
-@on_command('hitokoto', aliases=['一言'], only_to_me=False)
-async def _(session: CommandSession):
- f = open(filename1, encoding='utf-8')
- setting = json.load(f)
- await session.send(LIST.format(
- hitokoto=setting["hitokoto"],
- source=setting["source"]
- )
- )
+
+url = "https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=&fun=sync&source="
-#开发ing \ No newline at end of file
+@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