Compare commits

...
10 Commits
Author SHA1 Message Date
HibiKier fbd7c568d9 Update pix_update.py 2021-11-24 18:26:52 +08:00
HibiKier 2941774913 Update __init__.py 2021-11-24 18:26:38 +08:00
HibiKier b96d910401 Update __version__ 2021-11-24 14:40:53 +08:00
HibiKier 9275d0782b Update README.md 2021-11-24 14:40:39 +08:00
HibiKier 7acc6cf6af Update data_source.py 2021-11-24 14:33:10 +08:00
HibiKier d380a9aacc Update data_source.py 2021-11-24 14:32:46 +08:00
HibiKier 495377da13 Update README.md 2021-11-24 10:25:00 +08:00
HibiKier 218eed4068 Add files via upload 2021-11-24 10:24:40 +08:00
HibiKier 1e9c99dec1 Delete plugins/search_image directory 2021-11-24 10:07:47 +08:00
HibiKier 0326bc2831 Update __init__.py 2021-11-24 09:56:50 +08:00
11 changed files with 88 additions and 265 deletions
+6 -1
View File
@@ -1,4 +1,4 @@
<div align=center><img width="320" height="320" src="https://raw.githubusercontent.com/HibiKier/zhenxun_bot/main/docs/zhenxun.jpg"/></div>
<div align=center><img width="320" height="320" src="https://raw.githubusercontent.com/HibiKier/zhenxun_bot/main/logo.png"/></div>
![maven](https://img.shields.io/badge/python-3.8%2B-blue)
![maven](https://img.shields.io/badge/nonebot-2.0.0-yellow)
@@ -321,6 +321,11 @@ python bot.py
## 更新
### 2021/11/24 \[v0.0.6.3]
* 修复在线搜索色图出错
* 修复pix无法正确获取HIBIAPI
### 2021/11/23 \[v0.0.6.2]
* 替换cos API
+1 -1
View File
@@ -1 +1 @@
__version__: v0.0.6.2
__version__: v0.0.6.3
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 694 KiB

@@ -67,7 +67,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
if length == 0:
logger.warning(f"图库 {path} 为空,调用取消!")
await send_img.finish("该图库中没有图片噢")
index = img_id if img_id else str(random.randint(0, length))
index = img_id if img_id else str(random.randint(0, length - 1))
if not is_number(index):
return
if int(index) > length - 1 or int(index) < 0:
-73
View File
@@ -1,13 +1,5 @@
from configs.config import Config
from services.log import logger
from .model.omega_pixiv_illusts import OmegaPixivIllusts
from pathlib import Path
from nonebot import Driver
from typing import List
from datetime import datetime
import nonebot
import asyncio
import os
__zx_plugin_name__ = "更新扩展图库Omega [Hidden]"
@@ -67,69 +59,4 @@ Config.add_plugin_config(
nonebot.load_plugins("plugins/pix_gallery")
driver: Driver = nonebot.get_driver()
@driver.on_startup
async def _init_omega_pixiv_illusts():
omega_pixiv_illusts = None
for file in os.listdir("."):
if "omega_pixiv_illusts" in file and ".sql" in file:
omega_pixiv_illusts = Path() / file
if omega_pixiv_illusts:
with open(omega_pixiv_illusts, "r", encoding="utf8") as f:
lines = f.readlines()
tasks = []
length = len([x for x in lines if "INSERT INTO" in x.upper()])
all_pid = await OmegaPixivIllusts.get_all_pid()
index = 0
logger.info("检测到OmegaPixivIllusts数据库,准备开始更新....")
for line in lines:
if "INSERT INTO" in line.upper():
index += 1
tasks.append(
asyncio.ensure_future(_tasks(line, all_pid, length, index))
)
await asyncio.gather(*tasks)
omega_pixiv_illusts.unlink()
async def _tasks(line: str, all_pid: List[int], length: int, index: int):
data = line.split("VALUES", maxsplit=1)[-1].strip()
if data.startswith("("):
data = data[1:]
if data.endswith(");"):
data = data[:-2]
x = data.split(maxsplit=3)
pid = int(x[1][:-1].strip())
if pid in all_pid:
logger.info(f"添加OmegaPixivIllusts图库数据已存在 ---> pid:{pid}")
return
uid = int(x[2][:-1].strip())
x = x[3].split(", '")
title = x[0].strip()[1:-1]
tmp = x[1].split(", ")
author = tmp[0].strip()[:-1]
nsfw_tag = int(tmp[1])
width = int(tmp[2])
height = int(tmp[3])
tags = x[2][:-1]
url = x[3][:-1]
if await OmegaPixivIllusts.add_image_data(
pid,
title,
width,
height,
url,
uid,
author,
nsfw_tag,
tags,
datetime.min,
datetime.min,
):
logger.info(
f"成功添加OmegaPixivIllusts图库数据 pid:{pid} 本次预计存储 {length} 张,已更新第 {index} 张"
)
else:
logger.info(f"添加OmegaPixivIllusts图库数据已存在 ---> pid:{pid}")
+7 -4
View File
@@ -30,7 +30,10 @@ headers = {
"Referer": "https://www.pixiv.net",
}
HIBIAPI = None
HIBIAPI = Config.get_config("hibiapi", "HIBIAPI")
if not HIBIAPI:
HIBIAPI = "https://api.obfs.dev"
HIBIAPI = HIBIAPI[:-1] if HIBIAPI[-1] == "/" else HIBIAPI
async def start_update_image_url(
@@ -47,9 +50,6 @@ async def start_update_image_url(
pic_count = 0
tasks = []
semaphore = asyncio.Semaphore(10)
if not HIBIAPI:
HIBIAPI = Config.get_config("hibiapi", "HIBIAPI")
HIBIAPI = HIBIAPI[:-1] if HIBIAPI[-1] else HIBIAPI
for keyword in current_keyword:
for page in range(1, 110):
if keyword.startswith("uid:"):
@@ -390,3 +390,6 @@ def _check_black(img_urls: List[str], black: List[str]) -> bool:
if b in img_url:
return False
return True
+72
View File
@@ -4,9 +4,16 @@ from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from .data_source import start_update_image_url
from .model.pixiv_keyword_user import PixivKeywordUser
from .model.omega_pixiv_illusts import OmegaPixivIllusts
from .model.pixiv import Pixiv
from nonebot.adapters.cqhttp import Bot, MessageEvent
import time
from services.log import logger
from pathlib import Path
from typing import List
from datetime import datetime
import asyncio
import os
__zx_plugin_name__ = "pix检查更新 [Superuser]"
@@ -36,6 +43,8 @@ check_not_update_uid_pid = on_command(
block=True,
)
check_omega = on_command("检测omega图库", permission=SUPERUSER, priority=1, block=True)
@start_update.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
@@ -130,3 +139,66 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
f"累计更新PID {pid_count} 个\n"
f"累计更新图片 {pic_count} 张" + "\n耗时:{:.2f}秒".format((time.time() - start_time))
)
@check_omega.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
async def _tasks(line: str, all_pid: List[int], length: int, index: int):
data = line.split("VALUES", maxsplit=1)[-1].strip()
if data.startswith("("):
data = data[1:]
if data.endswith(");"):
data = data[:-2]
x = data.split(maxsplit=3)
pid = int(x[1][:-1].strip())
if pid in all_pid:
logger.info(f"添加OmegaPixivIllusts图库数据已存在 ---> pid:{pid}")
return
uid = int(x[2][:-1].strip())
x = x[3].split(", '")
title = x[0].strip()[1:-1]
tmp = x[1].split(", ")
author = tmp[0].strip()[:-1]
nsfw_tag = int(tmp[1])
width = int(tmp[2])
height = int(tmp[3])
tags = x[2][:-1]
url = x[3][:-1]
if await OmegaPixivIllusts.add_image_data(
pid,
title,
width,
height,
url,
uid,
author,
nsfw_tag,
tags,
datetime.min,
datetime.min,
):
logger.info(
f"成功添加OmegaPixivIllusts图库数据 pid:{pid} 本次预计存储 {length} 张,已更新第 {index} 张"
)
else:
logger.info(f"添加OmegaPixivIllusts图库数据已存在 ---> pid:{pid}")
omega_pixiv_illusts = None
for file in os.listdir("."):
if "omega_pixiv_illusts" in file and ".sql" in file:
omega_pixiv_illusts = Path() / file
if omega_pixiv_illusts:
with open(omega_pixiv_illusts, "r", encoding="utf8") as f:
lines = f.readlines()
tasks = []
length = len([x for x in lines if "INSERT INTO" in x.upper()])
all_pid = await OmegaPixivIllusts.get_all_pid()
index = 0
logger.info("检测到OmegaPixivIllusts数据库,准备开始更新....")
for line in lines:
if "INSERT INTO" in line.upper():
index += 1
tasks.append(
asyncio.ensure_future(_tasks(line, all_pid, length, index))
)
await asyncio.gather(*tasks)
omega_pixiv_illusts.unlink()
-133
View File
@@ -1,133 +0,0 @@
# # -*- coding: utf-8 -*-
# from typing import Dict
#
# from aiohttp.client_exceptions import ClientError
# from nonebot.plugin import on_command, on_message
# from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
# from nonebot.typing import T_State
# from services.log import logger
# from utils.utils import get_message_text, get_message_imgs
# from configs.config import Config
# from nonebot.rule import to_me
#
#
#
# __zx_plugin_name__ = "识图"
# __plugin_usage__ = """
# usage:
# 识别图片 [二次元图片]
# 指令:
# 识图 [图片]
# """.strip()
# __plugin_des__ = "以图搜图,看破本源"
# __plugin_cmd__ = ["识图"]
# __plugin_type__ = ("一些工具",)
# __plugin_version__ = 0.1
# __plugin_author__ = "synodriver"
# __plugin_settings__ = {
# "level": 5,
# "default_status": True,
# "limit_superuser": False,
# "cmd": ["识图"],
# }
# __plugin_configs__ = {
# "MAX_FIND_IMAGE_COUNT": {"value": 3, "help": "识图返回的最大结果数", "default_value": 3}
# }
#
#
# async def get_des(url: str, mode: str, user_id: int):
# """
# :param url: 图片链接
# :param mode: 图源
# :param user_id: 用户 id
# """
# if mode == "iqdb":
# async for msg in get_des_iqdb(url):
# yield msg
# elif mode == "ex":
# async for msg in get_des_ex(url):
# yield msg
# elif mode == "trace":
# async for msg in get_des_trace(url):
# yield msg
# elif mode == "yandex":
# async for msg in get_des_yandex(url):
# yield msg
# elif mode.startswith("asc"):
# async for msg in get_des_asc(url, user_id):
# yield msg
# else:
# async for msg in get_des_sau(url, user_id):
# yield msg
#
#
# setu = on_command("识图", aliases={"search"}, block=True, priority=5)
#
#
# @setu.handle()
# async def handle_first_receive(bot: Bot, event: MessageEvent, state: T_State):
# msg = get_message_text(event.json())
# imgs = get_message_imgs(event.json())
# if imgs:
# state["setu"] = imgs[0]
# if msg:
# state["mod"] = msg
#
#
# # ex/nao/trace/iqdb/ascii2d
# # @setu.got("mod", prompt="从哪里查找呢? ex/nao/trace/iqdb/ascii2d")
# # async def get_func(bot: Bot, event: MessageEvent, state: dict):
# # pass
#
#
# @setu.args_parser
# async def get_setu(bot: Bot, event: MessageEvent, state: T_State):
# imgs = get_message_imgs(event.json())
# msg = get_message_text(event.json())
# if not imgs:
# await setu.reject()
# if msg:
# state["mod"] = msg
# state["setu"] = imgs[0]
#
#
# @setu.got("setu", prompt="图呢?")
# async def get_setu(bot: Bot, event: MessageEvent, state: T_State):
# """
# 发现没有的时候要发问
# :return:
# """
# url: str = state["setu"]
# mod: str = state["mod"] if state.get("mod") else "nao" # 模式
# try:
# await bot.send(event=event, message="正在处理图片")
# idx = 1
# async for msg in get_des(url, mod, event.user_id):
# if msg:
# await bot.send(event=event, message=msg)
# if idx == Config.get_config(
# "nonebot_plugin_picsearcher", "MAX_FIND_IMAGE_COUNT"
# ):
# break
# idx += 1
# if id == 1:
# await bot.send(event=event, message="没找着.")
# logger.info(
# f"(USER {event.user_id}, GROUP "
# f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) 识图:{url}"
# )
# # image_data: List[Tuple] = await get_pic_from_url(url)
# # await setu.finish("hso")
# except IndexError:
# # await bot.send(event, traceback.format_exc())
# await setu.finish("参数错误")
# except ClientError:
# await setu.finish("连接失败")
#
#
#
#
#
#
#
#
-4
View File
@@ -1,4 +0,0 @@
API_URL_SAUCENAO = 'https://saucenao.com/search.php'
API_URL_ASCII2D = 'https://ascii2d.net/search/url/'
API_URL_IQDB = 'https://iqdb.org/'
-47
View File
@@ -1,47 +0,0 @@
from utils.user_agent import get_user_agent
from utils.utils import get_local_proxy
async def get_saucenao_identify_result(url: str) -> Result.DictListResult:
fetcher = HttpFetcher(timeout=10, flag='search_image_saucenao', headers=HEADERS)
if not API_KEY:
logger.opt(colors=True).warning(f'<r>Saucenao API KEY未配置</r>, <y>无法使用Saucenao API进行识图!</y>')
return Result.DictListResult(error=True, info='Saucenao API KEY未配置', result=[])
__payload = {'output_type': 2,
'api_key': API_KEY,
'testmode': 1,
'numres': 6,
'db': 999,
'url': url}
saucenao_result = await fetcher.get_json(url=API_URL_SAUCENAO, params=__payload)
if saucenao_result.error:
logger.warning(f'get_saucenao_identify_result failed, Network error: {saucenao_result.info}')
return Result.DictListResult(error=True, info=f'Network error: {saucenao_result.info}', result=[])
__result_json = saucenao_result.result
if __result_json['header']['status'] != 0:
logger.error(f"get_saucenao_identify_result failed, DataSource error, "
f"status code: {__result_json['header']['status']}")
return Result.DictListResult(
error=True, info=f"DataSource error, status code: {__result_json['header']['status']}", result=[])
__result = []
for __item in __result_json['results']:
try:
if int(float(__item['header']['similarity'])) < 75:
continue
else:
__result.append({'similarity': __item['header']['similarity'],
'thumbnail': __item['header']['thumbnail'],
'index_name': __item['header']['index_name'],
'ext_urls': __item['data']['ext_urls']})
except Exception as res_err:
logger.warning(f"get_saucenao_identify_result failed: {repr(res_err)}, can not resolve results")
continue
return Result.DictListResult(error=False, info='Success', result=__result)
+1 -1
View File
@@ -41,7 +41,7 @@ async def get_setu_urls(
url, timeout=Config.get_config("send_setu", "TIMEOUT"), params=params
)
if response.status_code == 200:
data = await response.json()
data = response.json()
if not data["error"]:
data = data["data"]
(