From 0d3d479a9b98aab47fb84ce0f5eadff17ff5d046 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Tue, 18 Aug 2020 22:47:39 +0800 Subject: [Update] --- ATRI/plugins/hitokoto.py | 59 +++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'ATRI/plugins/hitokoto.py') diff --git a/ATRI/plugins/hitokoto.py b/ATRI/plugins/hitokoto.py index e5fbe36..e72a37e 100644 --- a/ATRI/plugins/hitokoto.py +++ b/ATRI/plugins/hitokoto.py @@ -1,6 +1,7 @@ import json from datetime import datetime from random import choice +from pathlib import Path from nonebot import on_command, on_natural_language, CommandSession from nonebot import NLPSession, NLPResult @@ -21,33 +22,45 @@ url = 'https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json& @on_command('hitokoto', aliases = ['一言'], only_to_me = False) async def hitokoto(session: CommandSession): user = session.event.user_id - if 0 <= now_time() < 5.5: - await session.send( - choice( - [ - 'zzzz......', - 'zzzzzzzz......', - 'zzz...好涩哦..zzz....', - '别...不要..zzz..那..zzz..', - '嘻嘻..zzz..呐~..zzzz..' - ] - ) - ) - else: - with open('ATRI/plugins/noobList/noobList.json', 'r') as f: + group = session.event.group_id + try: + with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobGroup.json', 'r') as f: data = json.load(f) + except: + data = {} + try: + with open(Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobList.json', 'r') as f: + data1 = json.load(f) + except: + data1 = {} - if str(user) in data.keys(): + if str(group) in data.keys(): + pass + else: + if str(user) in data1.keys(): pass else: - rep = response.request_api(url) - - if not rep: - session.finish('获取失败') - - dc = json.loads(response.request_api(url)) - - await session.send(dc["hitokoto"]) + if 0 <= now_time() < 5.5: + await session.send( + choice( + [ + 'zzzz......', + 'zzzzzzzz......', + 'zzz...好涩哦..zzz....', + '别...不要..zzz..那..zzz..', + '嘻嘻..zzz..呐~..zzzz..' + ] + ) + ) + else: + rep = response.request_api(url) + + if not rep: + session.finish('获取失败') + + dc = json.loads(response.request_api(url)) + + await session.send(dc["hitokoto"]) @on_natural_language('一言', only_to_me = False) async def _(session: NLPSession): -- cgit v1.2.3