mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Delete plugins/search_image directory
This commit is contained in:
parent
0326bc2831
commit
1e9c99dec1
@ -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("连接失败")
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
@ -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/'
|
|
||||||
@ -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)
|
|
||||||
Loading…
Reference in New Issue
Block a user