summaryrefslogtreecommitdiff
path: root/ATRI/plugins/hitokoto.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-08-02 00:29:45 +0800
committerKyomotoi <[email protected]>2020-08-02 00:29:45 +0800
commitcec3a97227dd3f9a88bbafe7f2bc96bf513f53ae (patch)
tree66033fde43c45418fcf7716d14180a611be9adc0 /ATRI/plugins/hitokoto.py
parentb9c98687b9b25c86146b849dd40b248e13d2d136 (diff)
downloadATRI-cec3a97227dd3f9a88bbafe7f2bc96bf513f53ae.tar.gz
ATRI-cec3a97227dd3f9a88bbafe7f2bc96bf513f53ae.tar.bz2
ATRI-cec3a97227dd3f9a88bbafe7f2bc96bf513f53ae.zip
[Update] Refactor this project
Diffstat (limited to 'ATRI/plugins/hitokoto.py')
-rw-r--r--ATRI/plugins/hitokoto.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/ATRI/plugins/hitokoto.py b/ATRI/plugins/hitokoto.py
new file mode 100644
index 0000000..2f542c3
--- /dev/null
+++ b/ATRI/plugins/hitokoto.py
@@ -0,0 +1,33 @@
+# -*- coding:utf-8 -*-
+import json
+from nonebot import on_command, on_natural_language, CommandSession
+from nonebot import NLPSession, NLPResult
+from ATRI.modules import response
+
+
+url = f'https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source='
+
+
+HITOKOTO_REPLY = """{hitokoto}
+ from {author}"""
+
+
+@on_command('hitokoto', aliases = ['一言'], only_to_me = False)
+async def hitokoto(session: CommandSession):
+ rep = response.request_api(url)
+
+ if not rep:
+ session.finish('获取失败')
+
+ dc = json.loads(response.request_api(url))
+
+ await session.send(
+ HITOKOTO_REPLY.format(
+ hitokoto = dc["hitokoto"],
+ author = dc["author"]
+ )
+ )
+
+@on_natural_language('一言', only_to_me = False)
+async def _(session: NLPSession):
+ return NLPResult(60.0, ('hitokoto',), None) \ No newline at end of file