mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
update
This commit is contained in:
@@ -13,6 +13,11 @@ import re
|
||||
from models.count_user import UserCount
|
||||
from aiohttp.client_exceptions import ClientConnectorError
|
||||
from configs.config import MAX_SETU_R_COUNT
|
||||
from configs.path_config import TXT_PATH
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
__plugin_name__ = '色图'
|
||||
__plugin_usage__ = f'''示例:
|
||||
@@ -59,7 +64,11 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
if _ulmt.check(event.user_id):
|
||||
await setu.finish(f"您有色图正在处理,请稍等")
|
||||
_ulmt.set_True(event.user_id)
|
||||
setu_img, index = get_setu(img_id)
|
||||
try:
|
||||
setu_data = json.load(open(f'{TXT_PATH}/setu_data.json', 'r', encoding='utf8'))
|
||||
except Exception:
|
||||
setu_data = {}
|
||||
setu_img, index = get_setu(img_id, setu_data)
|
||||
if setu_img:
|
||||
try:
|
||||
await setu.send(setu_img)
|
||||
@@ -114,7 +123,11 @@ async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
if _ulmt.check(event.user_id):
|
||||
await setu.finish(f"您有色图正在处理,请稍等")
|
||||
_ulmt.set_True(event.user_id)
|
||||
setu_img, index = get_setu(img_id)
|
||||
try:
|
||||
setu_data = json.load(open(f'{TXT_PATH}/setu_data.json', 'r', encoding='utf8'))
|
||||
except Exception:
|
||||
setu_data = {}
|
||||
setu_img, index = get_setu(img_id, setu_data)
|
||||
if setu_img:
|
||||
await setu.send(setu_img)
|
||||
logger.info(
|
||||
@@ -221,10 +234,14 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
else:
|
||||
return
|
||||
# try:
|
||||
try:
|
||||
setu_data = json.load(open(f'{TXT_PATH}/setu_data.json', 'r', encoding='utf8'))
|
||||
except Exception:
|
||||
setu_data = {}
|
||||
if not keyword:
|
||||
for _ in range(num):
|
||||
try:
|
||||
img, index = get_setu('')
|
||||
img, index = get_setu('', setu_data)
|
||||
if not img:
|
||||
break
|
||||
await setu_reg.send(img)
|
||||
|
||||
@@ -115,7 +115,7 @@ async def search_online_setu(url: str):
|
||||
return '\n图片被小怪兽恰掉啦..!QAQ', -1
|
||||
|
||||
|
||||
def get_setu(index: str):
|
||||
def get_setu(index: str, setu_data: dict):
|
||||
length = len(os.listdir(IMAGE_PATH + path))
|
||||
if length == 0:
|
||||
return None, None
|
||||
@@ -125,7 +125,14 @@ def get_setu(index: str):
|
||||
if int(index) > length or int(index) < 0:
|
||||
return f"超过当前上下限!({length - 1})", 999
|
||||
else:
|
||||
return f'id:{index}' + image(f'{index}.jpg', 'setu'), index
|
||||
if setu_data:
|
||||
index = str(index)
|
||||
return f'id:{index}\n' \
|
||||
f'title:{setu_data[index]["title"]}\n' \
|
||||
f'author:{setu_data[index]["author"]}\n' \
|
||||
f'PID:{setu_data[index]["pid"]}' + image(f'{index}.jpg', path), index
|
||||
else:
|
||||
return f'id:{index}' + image(f'{index}.jpg', path), index
|
||||
return None, None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user