mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 03:39:59 +08:00
fit nonebot.beta2
This commit is contained in:
@@ -2,11 +2,6 @@ from configs.config import Config
|
||||
import nonebot
|
||||
|
||||
|
||||
__zx_plugin_name__ = "更新扩展图库Omega [Hidden]"
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
|
||||
|
||||
Config.add_plugin_config(
|
||||
"hibiapi",
|
||||
"HIBIAPI",
|
||||
|
||||
Executable → Regular
+396
-396
@@ -1,396 +1,396 @@
|
||||
from asyncpg.exceptions import UniqueViolationError
|
||||
from .model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from asyncio.locks import Semaphore
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from .model.pixiv import Pixiv
|
||||
from typing import List, Optional
|
||||
from utils.utils import change_pixiv_image_links
|
||||
from utils.image_utils import BuildImage
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from services.log import logger
|
||||
from configs.config import Config
|
||||
from configs.path_config import TEMP_PATH
|
||||
import aiofiles
|
||||
import platform
|
||||
import asyncio
|
||||
import math
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
if str(platform.system()).lower() == "windows":
|
||||
policy = asyncio.WindowsSelectorEventLoopPolicy()
|
||||
asyncio.set_event_loop_policy(policy)
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
|
||||
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
|
||||
"Referer": "https://www.pixiv.net",
|
||||
}
|
||||
|
||||
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(
|
||||
current_keyword: List[str], black_pid: List[str]
|
||||
) -> "int, int":
|
||||
"""
|
||||
开始更新图片url
|
||||
:param current_keyword: 关键词
|
||||
:param black_pid: 黑名单pid
|
||||
:return: pid数量和图片数量
|
||||
"""
|
||||
global HIBIAPI
|
||||
pid_count = 0
|
||||
pic_count = 0
|
||||
tasks = []
|
||||
semaphore = asyncio.Semaphore(10)
|
||||
for keyword in current_keyword:
|
||||
for page in range(1, 110):
|
||||
if keyword.startswith("uid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/member_illust"
|
||||
params = {"id": keyword[4:], "page": page}
|
||||
if page == 30:
|
||||
break
|
||||
elif keyword.startswith("pid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/illust"
|
||||
params = {"id": keyword[4:]}
|
||||
else:
|
||||
url = f"{HIBIAPI}/api/pixiv/search"
|
||||
params = {"word": keyword, "page": page}
|
||||
tasks.append(
|
||||
asyncio.ensure_future(
|
||||
search_image(
|
||||
url, keyword, params, semaphore, page, black_pid
|
||||
)
|
||||
)
|
||||
)
|
||||
if keyword.startswith("pid:"):
|
||||
break
|
||||
result = await asyncio.gather(*tasks)
|
||||
for x in result:
|
||||
pid_count += x[0]
|
||||
pic_count += x[1]
|
||||
return pid_count, pic_count
|
||||
|
||||
|
||||
async def search_image(
|
||||
url: str,
|
||||
keyword: str,
|
||||
params: dict,
|
||||
semaphore: Semaphore,
|
||||
page: int = 1,
|
||||
black: List[str] = None,
|
||||
) -> "int, int":
|
||||
"""
|
||||
搜索图片
|
||||
:param url: 搜索url
|
||||
:param keyword: 关键词
|
||||
:param params: params参数
|
||||
:param semaphore: semaphore
|
||||
:param page: 页面
|
||||
:param black: pid黑名单
|
||||
:return: pid数量和图片数量
|
||||
"""
|
||||
tmp_pid = []
|
||||
pic_count = 0
|
||||
pid_count = 0
|
||||
async with semaphore:
|
||||
try:
|
||||
data = (await AsyncHttpx.get(url, params=params)).json()
|
||||
if (
|
||||
not data
|
||||
or data.get("error")
|
||||
or (not data.get("illusts") and not data.get("illust"))
|
||||
):
|
||||
return 0, 0
|
||||
if url != f"{HIBIAPI}/api/pixiv/illust":
|
||||
logger.info(f'{keyword}: 获取数据成功...数据总量:{len(data["illusts"])}')
|
||||
data = data["illusts"]
|
||||
else:
|
||||
logger.info(f'获取数据成功...PID:{params.get("id")}')
|
||||
data = [data["illust"]]
|
||||
img_data = {}
|
||||
for x in data:
|
||||
pid = x["id"]
|
||||
title = x["title"]
|
||||
width = x["width"]
|
||||
height = x["height"]
|
||||
view = x["total_view"]
|
||||
bookmarks = x["total_bookmarks"]
|
||||
uid = x["user"]["id"]
|
||||
author = x["user"]["name"]
|
||||
tags = []
|
||||
for tag in x["tags"]:
|
||||
for i in tag:
|
||||
if tag[i]:
|
||||
tags.append(tag[i])
|
||||
img_urls = []
|
||||
if x["page_count"] == 1:
|
||||
img_urls.append(x["meta_single_page"]["original_image_url"])
|
||||
else:
|
||||
for urls in x["meta_pages"]:
|
||||
img_urls.append(urls["image_urls"]["original"])
|
||||
if (
|
||||
(
|
||||
bookmarks
|
||||
>= Config.get_config("pix", "SEARCH_HIBIAPI_BOOKMARKS")
|
||||
or (
|
||||
url == f"{HIBIAPI}/api/pixiv/member_illust"
|
||||
and bookmarks >= 1500
|
||||
)
|
||||
or (url == f"{HIBIAPI}/api/pixiv/illust")
|
||||
)
|
||||
and len(img_urls) < 10
|
||||
and _check_black(img_urls, black)
|
||||
):
|
||||
img_data[pid] = {
|
||||
"pid": pid,
|
||||
"title": title,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"view": view,
|
||||
"bookmarks": bookmarks,
|
||||
"img_urls": img_urls,
|
||||
"uid": uid,
|
||||
"author": author,
|
||||
"tags": tags,
|
||||
}
|
||||
else:
|
||||
continue
|
||||
for x in img_data.keys():
|
||||
data = img_data[x]
|
||||
for img_url in data["img_urls"]:
|
||||
img_p = img_url[img_url.rfind("_") + 1 : img_url.rfind(".")]
|
||||
try:
|
||||
if await Pixiv.add_image_data(
|
||||
data["pid"],
|
||||
data["title"],
|
||||
data["width"],
|
||||
data["height"],
|
||||
data["view"],
|
||||
data["bookmarks"],
|
||||
img_url,
|
||||
img_p,
|
||||
data["uid"],
|
||||
data["author"],
|
||||
",".join(data["tags"]),
|
||||
):
|
||||
if data["pid"] not in tmp_pid:
|
||||
pid_count += 1
|
||||
tmp_pid.append(data["pid"])
|
||||
pic_count += 1
|
||||
logger.info(f'存储图片PID:{data["pid"]} IMG_P:{img_p}')
|
||||
except UniqueViolationError:
|
||||
logger.warning(f'{data["pid"]} | {img_url} 已存在...')
|
||||
except Exception as e:
|
||||
logger.warning(f"PIX在线搜索图片错误,已再次调用 {type(e)}:{e}")
|
||||
await search_image(url, keyword, params, semaphore, page, black)
|
||||
return pid_count, pic_count
|
||||
|
||||
|
||||
async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
"""
|
||||
下载图片
|
||||
:param img_url:
|
||||
:param user_id:
|
||||
:return: 图片名称
|
||||
"""
|
||||
if "https://www.pixiv.net/artworks" in img_url:
|
||||
pid = img_url.rsplit("/", maxsplit=1)[-1]
|
||||
params = {"id": pid}
|
||||
for _ in range(3):
|
||||
try:
|
||||
response = await AsyncHttpx.get(f"{HIBIAPI}/api/pixiv/illust", params=params)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get("illust"):
|
||||
if data["illust"]["page_count"] == 1:
|
||||
img_url = data["illust"]["meta_single_page"][
|
||||
"original_image_url"
|
||||
]
|
||||
else:
|
||||
img_url = data["illust"]["meta_pages"][0][
|
||||
"image_urls"
|
||||
]["original"]
|
||||
break
|
||||
except TimeoutError:
|
||||
pass
|
||||
old_img_url = img_url
|
||||
img_url = change_pixiv_image_links(
|
||||
img_url, Config.get_config("pix", "PIX_IMAGE_SIZE"), Config.get_config("pixiv", "PIXIV_NGINX_URL")
|
||||
)
|
||||
old_img_url = change_pixiv_image_links(
|
||||
old_img_url, None, Config.get_config("pixiv", "PIXIV_NGINX_URL")
|
||||
)
|
||||
for _ in range(3):
|
||||
try:
|
||||
response = await AsyncHttpx.get(img_url, headers=headers, timeout=Config.get_config("pix", "TIMEOUT"),)
|
||||
if response.status_code == 404:
|
||||
img_url = old_img_url
|
||||
continue
|
||||
async with aiofiles.open(
|
||||
f"{TEMP_PATH}/pix_{user_id}_{img_url[-10:-4]}.jpg", "wb"
|
||||
) as f:
|
||||
await f.write(response.content)
|
||||
return f"pix_{user_id}_{img_url[-10:-4]}.jpg"
|
||||
except TimeoutError:
|
||||
logger.warning(f"PIX:{img_url} 图片下载超时...")
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
async def uid_pid_exists(id_: str) -> bool:
|
||||
"""
|
||||
检测 pid/uid 是否有效
|
||||
:param id_: pid/uid
|
||||
"""
|
||||
if id_.startswith("uid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/member"
|
||||
elif id_.startswith("pid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/illust"
|
||||
else:
|
||||
return False
|
||||
params = {"id": int(id_[4:])}
|
||||
data = (await AsyncHttpx.get(url, params=params)).json()
|
||||
if data.get("error"):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def get_keyword_num(keyword: str) -> "int, int, int, int, int":
|
||||
"""
|
||||
查看图片相关 tag 数量
|
||||
:param keyword: 关键词tag
|
||||
"""
|
||||
count, r18_count = await Pixiv.get_keyword_num(keyword.split())
|
||||
count_, setu_count, r18_count_ = await OmegaPixivIllusts.get_keyword_num(
|
||||
keyword.split()
|
||||
)
|
||||
return count, r18_count, count_, setu_count, r18_count_
|
||||
|
||||
|
||||
async def remove_image(pid: int, img_p: str) -> bool:
|
||||
"""
|
||||
删除置顶图片
|
||||
:param pid: pid
|
||||
:param img_p: 图片 p 如 p0,p1 等
|
||||
"""
|
||||
if img_p:
|
||||
if "p" not in img_p:
|
||||
img_p = f"p{img_p}"
|
||||
return await Pixiv.remove_image_data(pid, img_p)
|
||||
|
||||
|
||||
def gen_keyword_pic(
|
||||
_pass_keyword: List[str], not_pass_keyword: List[str], is_superuser: bool
|
||||
):
|
||||
"""
|
||||
已通过或未通过的所有关键词/uid/pid
|
||||
:param _pass_keyword: 通过列表
|
||||
:param not_pass_keyword: 未通过列表
|
||||
:param is_superuser: 是否超级用户
|
||||
"""
|
||||
_keyword = [
|
||||
x
|
||||
for x in _pass_keyword
|
||||
if not x.startswith("uid:")
|
||||
and not x.startswith("pid:")
|
||||
and not x.startswith("black:")
|
||||
]
|
||||
_uid = [x for x in _pass_keyword if x.startswith("uid:")]
|
||||
_pid = [x for x in _pass_keyword if x.startswith("pid:")]
|
||||
_n_keyword = [
|
||||
x
|
||||
for x in not_pass_keyword
|
||||
if not x.startswith("uid:")
|
||||
and not x.startswith("pid:")
|
||||
and not x.startswith("black:")
|
||||
]
|
||||
_n_uid = [
|
||||
x
|
||||
for x in not_pass_keyword
|
||||
if x.startswith("uid:") and not x.startswith("black:")
|
||||
]
|
||||
_n_pid = [
|
||||
x
|
||||
for x in not_pass_keyword
|
||||
if x.startswith("pid:") and not x.startswith("black:")
|
||||
]
|
||||
img_width = 0
|
||||
img_data = {
|
||||
"_keyword": {"width": 0, "data": _keyword},
|
||||
"_uid": {"width": 0, "data": _uid},
|
||||
"_pid": {"width": 0, "data": _pid},
|
||||
"_n_keyword": {"width": 0, "data": _n_keyword},
|
||||
"_n_uid": {"width": 0, "data": _n_uid},
|
||||
"_n_pid": {"width": 0, "data": _n_pid},
|
||||
}
|
||||
for x in list(img_data.keys()):
|
||||
img_data[x]["width"] = math.ceil(len(img_data[x]["data"]) / 40)
|
||||
img_width += img_data[x]["width"] * 200
|
||||
if not is_superuser:
|
||||
img_width = (
|
||||
img_width
|
||||
- (
|
||||
img_data["_n_keyword"]["width"]
|
||||
+ img_data["_n_uid"]["width"]
|
||||
+ img_data["_n_pid"]["width"]
|
||||
)
|
||||
* 200
|
||||
)
|
||||
del img_data["_n_keyword"]
|
||||
del img_data["_n_pid"]
|
||||
del img_data["_n_uid"]
|
||||
current_width = 0
|
||||
A = BuildImage(img_width, 1100)
|
||||
for x in list(img_data.keys()):
|
||||
if img_data[x]["data"]:
|
||||
img = BuildImage(img_data[x]["width"] * 200, 1100, 200, 1100, font_size=40)
|
||||
start_index = 0
|
||||
end_index = 40
|
||||
total_index = img_data[x]["width"] * 40
|
||||
for _ in range(img_data[x]["width"]):
|
||||
tmp = BuildImage(198, 1100, font_size=20)
|
||||
text_img = BuildImage(198, 100, font_size=50)
|
||||
key_str = "\n".join(
|
||||
[key for key in img_data[x]["data"][start_index:end_index]]
|
||||
)
|
||||
tmp.text((10, 100), key_str)
|
||||
if x.find("_n") == -1:
|
||||
text_img.text((24, 24), "已收录")
|
||||
else:
|
||||
text_img.text((24, 24), "待收录")
|
||||
tmp.paste(text_img, (0, 0))
|
||||
start_index += 40
|
||||
end_index = (
|
||||
end_index + 40 if end_index + 40 <= total_index else total_index
|
||||
)
|
||||
background_img = BuildImage(200, 1100, color="#FFE4C4")
|
||||
background_img.paste(tmp, (1, 1))
|
||||
img.paste(background_img)
|
||||
A.paste(img, (current_width, 0))
|
||||
current_width += img_data[x]["width"] * 200
|
||||
return A.pic2bs4()
|
||||
|
||||
|
||||
def _check_black(img_urls: List[str], black: List[str]) -> bool:
|
||||
"""
|
||||
检测pid是否在黑名单中
|
||||
:param img_urls: 图片img列表
|
||||
:param black: 黑名单
|
||||
:return:
|
||||
"""
|
||||
for b in black:
|
||||
for img_url in img_urls:
|
||||
if b in img_url:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
from asyncpg.exceptions import UniqueViolationError
|
||||
from ._model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from asyncio.locks import Semaphore
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from ._model.pixiv import Pixiv
|
||||
from typing import List, Optional
|
||||
from utils.utils import change_pixiv_image_links
|
||||
from utils.image_utils import BuildImage
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from services.log import logger
|
||||
from configs.config import Config
|
||||
from configs.path_config import TEMP_PATH
|
||||
import aiofiles
|
||||
import platform
|
||||
import asyncio
|
||||
import math
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
if str(platform.system()).lower() == "windows":
|
||||
policy = asyncio.WindowsSelectorEventLoopPolicy()
|
||||
asyncio.set_event_loop_policy(policy)
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6;"
|
||||
" rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
|
||||
"Referer": "https://www.pixiv.net",
|
||||
}
|
||||
|
||||
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(
|
||||
current_keyword: List[str], black_pid: List[str]
|
||||
) -> "int, int":
|
||||
"""
|
||||
开始更新图片url
|
||||
:param current_keyword: 关键词
|
||||
:param black_pid: 黑名单pid
|
||||
:return: pid数量和图片数量
|
||||
"""
|
||||
global HIBIAPI
|
||||
pid_count = 0
|
||||
pic_count = 0
|
||||
tasks = []
|
||||
semaphore = asyncio.Semaphore(10)
|
||||
for keyword in current_keyword:
|
||||
for page in range(1, 110):
|
||||
if keyword.startswith("uid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/member_illust"
|
||||
params = {"id": keyword[4:], "page": page}
|
||||
if page == 30:
|
||||
break
|
||||
elif keyword.startswith("pid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/illust"
|
||||
params = {"id": keyword[4:]}
|
||||
else:
|
||||
url = f"{HIBIAPI}/api/pixiv/search"
|
||||
params = {"word": keyword, "page": page}
|
||||
tasks.append(
|
||||
asyncio.ensure_future(
|
||||
search_image(
|
||||
url, keyword, params, semaphore, page, black_pid
|
||||
)
|
||||
)
|
||||
)
|
||||
if keyword.startswith("pid:"):
|
||||
break
|
||||
result = await asyncio.gather(*tasks)
|
||||
for x in result:
|
||||
pid_count += x[0]
|
||||
pic_count += x[1]
|
||||
return pid_count, pic_count
|
||||
|
||||
|
||||
async def search_image(
|
||||
url: str,
|
||||
keyword: str,
|
||||
params: dict,
|
||||
semaphore: Semaphore,
|
||||
page: int = 1,
|
||||
black: List[str] = None,
|
||||
) -> "int, int":
|
||||
"""
|
||||
搜索图片
|
||||
:param url: 搜索url
|
||||
:param keyword: 关键词
|
||||
:param params: params参数
|
||||
:param semaphore: semaphore
|
||||
:param page: 页面
|
||||
:param black: pid黑名单
|
||||
:return: pid数量和图片数量
|
||||
"""
|
||||
tmp_pid = []
|
||||
pic_count = 0
|
||||
pid_count = 0
|
||||
async with semaphore:
|
||||
try:
|
||||
data = (await AsyncHttpx.get(url, params=params)).json()
|
||||
if (
|
||||
not data
|
||||
or data.get("error")
|
||||
or (not data.get("illusts") and not data.get("illust"))
|
||||
):
|
||||
return 0, 0
|
||||
if url != f"{HIBIAPI}/api/pixiv/illust":
|
||||
logger.info(f'{keyword}: 获取数据成功...数据总量:{len(data["illusts"])}')
|
||||
data = data["illusts"]
|
||||
else:
|
||||
logger.info(f'获取数据成功...PID:{params.get("id")}')
|
||||
data = [data["illust"]]
|
||||
img_data = {}
|
||||
for x in data:
|
||||
pid = x["id"]
|
||||
title = x["title"]
|
||||
width = x["width"]
|
||||
height = x["height"]
|
||||
view = x["total_view"]
|
||||
bookmarks = x["total_bookmarks"]
|
||||
uid = x["user"]["id"]
|
||||
author = x["user"]["name"]
|
||||
tags = []
|
||||
for tag in x["tags"]:
|
||||
for i in tag:
|
||||
if tag[i]:
|
||||
tags.append(tag[i])
|
||||
img_urls = []
|
||||
if x["page_count"] == 1:
|
||||
img_urls.append(x["meta_single_page"]["original_image_url"])
|
||||
else:
|
||||
for urls in x["meta_pages"]:
|
||||
img_urls.append(urls["image_urls"]["original"])
|
||||
if (
|
||||
(
|
||||
bookmarks
|
||||
>= Config.get_config("pix", "SEARCH_HIBIAPI_BOOKMARKS")
|
||||
or (
|
||||
url == f"{HIBIAPI}/api/pixiv/member_illust"
|
||||
and bookmarks >= 1500
|
||||
)
|
||||
or (url == f"{HIBIAPI}/api/pixiv/illust")
|
||||
)
|
||||
and len(img_urls) < 10
|
||||
and _check_black(img_urls, black)
|
||||
):
|
||||
img_data[pid] = {
|
||||
"pid": pid,
|
||||
"title": title,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"view": view,
|
||||
"bookmarks": bookmarks,
|
||||
"img_urls": img_urls,
|
||||
"uid": uid,
|
||||
"author": author,
|
||||
"tags": tags,
|
||||
}
|
||||
else:
|
||||
continue
|
||||
for x in img_data.keys():
|
||||
data = img_data[x]
|
||||
for img_url in data["img_urls"]:
|
||||
img_p = img_url[img_url.rfind("_") + 1 : img_url.rfind(".")]
|
||||
try:
|
||||
if await Pixiv.add_image_data(
|
||||
data["pid"],
|
||||
data["title"],
|
||||
data["width"],
|
||||
data["height"],
|
||||
data["view"],
|
||||
data["bookmarks"],
|
||||
img_url,
|
||||
img_p,
|
||||
data["uid"],
|
||||
data["author"],
|
||||
",".join(data["tags"]),
|
||||
):
|
||||
if data["pid"] not in tmp_pid:
|
||||
pid_count += 1
|
||||
tmp_pid.append(data["pid"])
|
||||
pic_count += 1
|
||||
logger.info(f'存储图片PID:{data["pid"]} IMG_P:{img_p}')
|
||||
except UniqueViolationError:
|
||||
logger.warning(f'{data["pid"]} | {img_url} 已存在...')
|
||||
except Exception as e:
|
||||
logger.warning(f"PIX在线搜索图片错误,已再次调用 {type(e)}:{e}")
|
||||
await search_image(url, keyword, params, semaphore, page, black)
|
||||
return pid_count, pic_count
|
||||
|
||||
|
||||
async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
"""
|
||||
下载图片
|
||||
:param img_url:
|
||||
:param user_id:
|
||||
:return: 图片名称
|
||||
"""
|
||||
if "https://www.pixiv.net/artworks" in img_url:
|
||||
pid = img_url.rsplit("/", maxsplit=1)[-1]
|
||||
params = {"id": pid}
|
||||
for _ in range(3):
|
||||
try:
|
||||
response = await AsyncHttpx.get(f"{HIBIAPI}/api/pixiv/illust", params=params)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get("illust"):
|
||||
if data["illust"]["page_count"] == 1:
|
||||
img_url = data["illust"]["meta_single_page"][
|
||||
"original_image_url"
|
||||
]
|
||||
else:
|
||||
img_url = data["illust"]["meta_pages"][0][
|
||||
"image_urls"
|
||||
]["original"]
|
||||
break
|
||||
except TimeoutError:
|
||||
pass
|
||||
old_img_url = img_url
|
||||
img_url = change_pixiv_image_links(
|
||||
img_url, Config.get_config("pix", "PIX_IMAGE_SIZE"), Config.get_config("pixiv", "PIXIV_NGINX_URL")
|
||||
)
|
||||
old_img_url = change_pixiv_image_links(
|
||||
old_img_url, None, Config.get_config("pixiv", "PIXIV_NGINX_URL")
|
||||
)
|
||||
for _ in range(3):
|
||||
try:
|
||||
response = await AsyncHttpx.get(img_url, headers=headers, timeout=Config.get_config("pix", "TIMEOUT"),)
|
||||
if response.status_code == 404:
|
||||
img_url = old_img_url
|
||||
continue
|
||||
async with aiofiles.open(
|
||||
TEMP_PATH / f"pix_{user_id}_{img_url[-10:-4]}.jpg", "wb"
|
||||
) as f:
|
||||
await f.write(response.content)
|
||||
return f"pix_{user_id}_{img_url[-10:-4]}.jpg"
|
||||
except TimeoutError:
|
||||
logger.warning(f"PIX:{img_url} 图片下载超时...")
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
async def uid_pid_exists(id_: str) -> bool:
|
||||
"""
|
||||
检测 pid/uid 是否有效
|
||||
:param id_: pid/uid
|
||||
"""
|
||||
if id_.startswith("uid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/member"
|
||||
elif id_.startswith("pid:"):
|
||||
url = f"{HIBIAPI}/api/pixiv/illust"
|
||||
else:
|
||||
return False
|
||||
params = {"id": int(id_[4:])}
|
||||
data = (await AsyncHttpx.get(url, params=params)).json()
|
||||
if data.get("error"):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def get_keyword_num(keyword: str) -> "int, int, int, int, int":
|
||||
"""
|
||||
查看图片相关 tag 数量
|
||||
:param keyword: 关键词tag
|
||||
"""
|
||||
count, r18_count = await Pixiv.get_keyword_num(keyword.split())
|
||||
count_, setu_count, r18_count_ = await OmegaPixivIllusts.get_keyword_num(
|
||||
keyword.split()
|
||||
)
|
||||
return count, r18_count, count_, setu_count, r18_count_
|
||||
|
||||
|
||||
async def remove_image(pid: int, img_p: str) -> bool:
|
||||
"""
|
||||
删除置顶图片
|
||||
:param pid: pid
|
||||
:param img_p: 图片 p 如 p0,p1 等
|
||||
"""
|
||||
if img_p:
|
||||
if "p" not in img_p:
|
||||
img_p = f"p{img_p}"
|
||||
return await Pixiv.remove_image_data(pid, img_p)
|
||||
|
||||
|
||||
def gen_keyword_pic(
|
||||
_pass_keyword: List[str], not_pass_keyword: List[str], is_superuser: bool
|
||||
):
|
||||
"""
|
||||
已通过或未通过的所有关键词/uid/pid
|
||||
:param _pass_keyword: 通过列表
|
||||
:param not_pass_keyword: 未通过列表
|
||||
:param is_superuser: 是否超级用户
|
||||
"""
|
||||
_keyword = [
|
||||
x
|
||||
for x in _pass_keyword
|
||||
if not x.startswith("uid:")
|
||||
and not x.startswith("pid:")
|
||||
and not x.startswith("black:")
|
||||
]
|
||||
_uid = [x for x in _pass_keyword if x.startswith("uid:")]
|
||||
_pid = [x for x in _pass_keyword if x.startswith("pid:")]
|
||||
_n_keyword = [
|
||||
x
|
||||
for x in not_pass_keyword
|
||||
if not x.startswith("uid:")
|
||||
and not x.startswith("pid:")
|
||||
and not x.startswith("black:")
|
||||
]
|
||||
_n_uid = [
|
||||
x
|
||||
for x in not_pass_keyword
|
||||
if x.startswith("uid:") and not x.startswith("black:")
|
||||
]
|
||||
_n_pid = [
|
||||
x
|
||||
for x in not_pass_keyword
|
||||
if x.startswith("pid:") and not x.startswith("black:")
|
||||
]
|
||||
img_width = 0
|
||||
img_data = {
|
||||
"_keyword": {"width": 0, "data": _keyword},
|
||||
"_uid": {"width": 0, "data": _uid},
|
||||
"_pid": {"width": 0, "data": _pid},
|
||||
"_n_keyword": {"width": 0, "data": _n_keyword},
|
||||
"_n_uid": {"width": 0, "data": _n_uid},
|
||||
"_n_pid": {"width": 0, "data": _n_pid},
|
||||
}
|
||||
for x in list(img_data.keys()):
|
||||
img_data[x]["width"] = math.ceil(len(img_data[x]["data"]) / 40)
|
||||
img_width += img_data[x]["width"] * 200
|
||||
if not is_superuser:
|
||||
img_width = (
|
||||
img_width
|
||||
- (
|
||||
img_data["_n_keyword"]["width"]
|
||||
+ img_data["_n_uid"]["width"]
|
||||
+ img_data["_n_pid"]["width"]
|
||||
)
|
||||
* 200
|
||||
)
|
||||
del img_data["_n_keyword"]
|
||||
del img_data["_n_pid"]
|
||||
del img_data["_n_uid"]
|
||||
current_width = 0
|
||||
A = BuildImage(img_width, 1100)
|
||||
for x in list(img_data.keys()):
|
||||
if img_data[x]["data"]:
|
||||
img = BuildImage(img_data[x]["width"] * 200, 1100, 200, 1100, font_size=40)
|
||||
start_index = 0
|
||||
end_index = 40
|
||||
total_index = img_data[x]["width"] * 40
|
||||
for _ in range(img_data[x]["width"]):
|
||||
tmp = BuildImage(198, 1100, font_size=20)
|
||||
text_img = BuildImage(198, 100, font_size=50)
|
||||
key_str = "\n".join(
|
||||
[key for key in img_data[x]["data"][start_index:end_index]]
|
||||
)
|
||||
tmp.text((10, 100), key_str)
|
||||
if x.find("_n") == -1:
|
||||
text_img.text((24, 24), "已收录")
|
||||
else:
|
||||
text_img.text((24, 24), "待收录")
|
||||
tmp.paste(text_img, (0, 0))
|
||||
start_index += 40
|
||||
end_index = (
|
||||
end_index + 40 if end_index + 40 <= total_index else total_index
|
||||
)
|
||||
background_img = BuildImage(200, 1100, color="#FFE4C4")
|
||||
background_img.paste(tmp, (1, 1))
|
||||
img.paste(background_img)
|
||||
A.paste(img, (current_width, 0))
|
||||
current_width += img_data[x]["width"] * 200
|
||||
return A.pic2bs4()
|
||||
|
||||
|
||||
def _check_black(img_urls: List[str], black: List[str]) -> bool:
|
||||
"""
|
||||
检测pid是否在黑名单中
|
||||
:param img_urls: 图片img列表
|
||||
:param black: 黑名单
|
||||
:return:
|
||||
"""
|
||||
for b in black:
|
||||
for img_url in img_urls:
|
||||
if b in img_url:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+1
-1
@@ -1 +1 @@
|
||||
|
||||
|
||||
plugins/pix_gallery/model/omega_pixiv_illusts.py → plugins/pix_gallery/_model/omega_pixiv_illusts.py
Executable → Regular
+153
-153
@@ -1,153 +1,153 @@
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class OmegaPixivIllusts(db.Model):
|
||||
__tablename__ = "omega_pixiv_illusts"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
pid = db.Column(db.BigInteger(), nullable=False)
|
||||
uid = db.Column(db.BigInteger(), nullable=False)
|
||||
title = db.Column(db.String(), nullable=False)
|
||||
uname = db.Column(db.String(), nullable=False)
|
||||
nsfw_tag = db.Column(db.Integer(), nullable=False)
|
||||
width = db.Column(db.Integer(), nullable=False)
|
||||
height = db.Column(db.Integer(), nullable=False)
|
||||
tags = db.Column(db.String(), nullable=False)
|
||||
url = db.Column(db.String(), nullable=False)
|
||||
created_at = db.Column(db.DateTime(timezone=True))
|
||||
updated_at = db.Column(db.DateTime(timezone=True))
|
||||
|
||||
_idx1 = db.Index("omega_pixiv_illusts_idx1", "pid", "url", unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_image_data(
|
||||
cls,
|
||||
pid: int,
|
||||
title: str,
|
||||
width: int,
|
||||
height: int,
|
||||
url: str,
|
||||
uid: int,
|
||||
uname: str,
|
||||
nsfw_tag: int,
|
||||
tags: str,
|
||||
created_at: datetime,
|
||||
updated_at: datetime,
|
||||
):
|
||||
"""
|
||||
说明:
|
||||
添加图片信息
|
||||
参数:
|
||||
:param pid: pid
|
||||
:param title: 标题
|
||||
:param width: 宽度
|
||||
:param height: 长度
|
||||
:param url: url链接
|
||||
:param uid: 作者uid
|
||||
:param uname: 作者名称
|
||||
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
|
||||
:param tags: 相关tag
|
||||
:param created_at: 创建日期
|
||||
:param updated_at: 更新日期
|
||||
"""
|
||||
if not await cls.check_exists(pid):
|
||||
await cls.create(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
url=url,
|
||||
uid=uid,
|
||||
uname=uname,
|
||||
nsfw_tag=nsfw_tag,
|
||||
tags=tags,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def query_images(
|
||||
cls,
|
||||
keywords: Optional[List[str]] = None,
|
||||
uid: Optional[int] = None,
|
||||
pid: Optional[int] = None,
|
||||
nsfw_tag: Optional[int] = 0,
|
||||
num: int = 100
|
||||
) -> List[Optional["OmegaPixivIllusts"]]:
|
||||
"""
|
||||
说明:
|
||||
查找符合条件的图片
|
||||
参数:
|
||||
:param keywords: 关键词
|
||||
:param uid: 画师uid
|
||||
:param pid: 图片pid
|
||||
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
|
||||
:param num: 获取图片数量
|
||||
"""
|
||||
if nsfw_tag is not None:
|
||||
query = cls.query.where(cls.nsfw_tag == nsfw_tag)
|
||||
else:
|
||||
query = cls.query
|
||||
if keywords:
|
||||
for keyword in keywords:
|
||||
query = query.where(cls.tags.contains(keyword))
|
||||
elif uid:
|
||||
query = query.where(cls.uid == uid)
|
||||
elif pid:
|
||||
query = query.where(cls.uid == pid)
|
||||
query = query.order_by(db.func.random()).limit(num)
|
||||
return await query.gino.all()
|
||||
|
||||
@classmethod
|
||||
async def check_exists(cls, pid: int) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测pid是否已存在
|
||||
参数:
|
||||
:param pid: 图片PID
|
||||
"""
|
||||
query = await cls.query.where(cls.pid == pid).gino.all()
|
||||
return bool(query)
|
||||
|
||||
@classmethod
|
||||
async def get_keyword_num(cls, tags: List[str] = None) -> "int, int, int":
|
||||
"""
|
||||
说明:
|
||||
获取相关关键词(keyword, tag)在图库中的数量
|
||||
参数:
|
||||
:param tags: 关键词/Tag
|
||||
"""
|
||||
setattr(OmegaPixivIllusts, 'count', db.func.count(cls.pid).label('count'))
|
||||
query = cls.select('count')
|
||||
if tags:
|
||||
for tag in tags:
|
||||
query = query.where(cls.tags.contains(tag))
|
||||
count = await query.where(cls.nsfw_tag == 0).gino.first()
|
||||
setu_count = await query.where(cls.nsfw_tag == 1).gino.first()
|
||||
r18_count = await query.where(cls.nsfw_tag == 2).gino.first()
|
||||
return count[0], setu_count[0], r18_count[0]
|
||||
|
||||
@classmethod
|
||||
async def get_all_pid(cls) -> List[int]:
|
||||
"""
|
||||
说明:
|
||||
获取所有图片PID
|
||||
"""
|
||||
data = await cls.select('pid').gino.all()
|
||||
return [x[0] for x in data]
|
||||
|
||||
@classmethod
|
||||
async def test(cls, nsfw_tag: int = 1):
|
||||
if nsfw_tag is not None:
|
||||
query = cls.query.where(cls.nsfw_tag == nsfw_tag)
|
||||
else:
|
||||
query = cls.query
|
||||
query = query.where((cls.width - cls.height) < 50)
|
||||
for x in await query.gino.all():
|
||||
print(x.pid)
|
||||
|
||||
|
||||
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class OmegaPixivIllusts(db.Model):
|
||||
__tablename__ = "omega_pixiv_illusts"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
pid = db.Column(db.BigInteger(), nullable=False)
|
||||
uid = db.Column(db.BigInteger(), nullable=False)
|
||||
title = db.Column(db.String(), nullable=False)
|
||||
uname = db.Column(db.String(), nullable=False)
|
||||
nsfw_tag = db.Column(db.Integer(), nullable=False)
|
||||
width = db.Column(db.Integer(), nullable=False)
|
||||
height = db.Column(db.Integer(), nullable=False)
|
||||
tags = db.Column(db.String(), nullable=False)
|
||||
url = db.Column(db.String(), nullable=False)
|
||||
created_at = db.Column(db.DateTime(timezone=True))
|
||||
updated_at = db.Column(db.DateTime(timezone=True))
|
||||
|
||||
_idx1 = db.Index("omega_pixiv_illusts_idx1", "pid", "url", unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_image_data(
|
||||
cls,
|
||||
pid: int,
|
||||
title: str,
|
||||
width: int,
|
||||
height: int,
|
||||
url: str,
|
||||
uid: int,
|
||||
uname: str,
|
||||
nsfw_tag: int,
|
||||
tags: str,
|
||||
created_at: datetime,
|
||||
updated_at: datetime,
|
||||
):
|
||||
"""
|
||||
说明:
|
||||
添加图片信息
|
||||
参数:
|
||||
:param pid: pid
|
||||
:param title: 标题
|
||||
:param width: 宽度
|
||||
:param height: 长度
|
||||
:param url: url链接
|
||||
:param uid: 作者uid
|
||||
:param uname: 作者名称
|
||||
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
|
||||
:param tags: 相关tag
|
||||
:param created_at: 创建日期
|
||||
:param updated_at: 更新日期
|
||||
"""
|
||||
if not await cls.check_exists(pid):
|
||||
await cls.create(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
url=url,
|
||||
uid=uid,
|
||||
uname=uname,
|
||||
nsfw_tag=nsfw_tag,
|
||||
tags=tags,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def query_images(
|
||||
cls,
|
||||
keywords: Optional[List[str]] = None,
|
||||
uid: Optional[int] = None,
|
||||
pid: Optional[int] = None,
|
||||
nsfw_tag: Optional[int] = 0,
|
||||
num: int = 100
|
||||
) -> List[Optional["OmegaPixivIllusts"]]:
|
||||
"""
|
||||
说明:
|
||||
查找符合条件的图片
|
||||
参数:
|
||||
:param keywords: 关键词
|
||||
:param uid: 画师uid
|
||||
:param pid: 图片pid
|
||||
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
|
||||
:param num: 获取图片数量
|
||||
"""
|
||||
if nsfw_tag is not None:
|
||||
query = cls.query.where(cls.nsfw_tag == nsfw_tag)
|
||||
else:
|
||||
query = cls.query
|
||||
if keywords:
|
||||
for keyword in keywords:
|
||||
query = query.where(cls.tags.contains(keyword))
|
||||
elif uid:
|
||||
query = query.where(cls.uid == uid)
|
||||
elif pid:
|
||||
query = query.where(cls.uid == pid)
|
||||
query = query.order_by(db.func.random()).limit(num)
|
||||
return await query.gino.all()
|
||||
|
||||
@classmethod
|
||||
async def check_exists(cls, pid: int) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测pid是否已存在
|
||||
参数:
|
||||
:param pid: 图片PID
|
||||
"""
|
||||
query = await cls.query.where(cls.pid == pid).gino.all()
|
||||
return bool(query)
|
||||
|
||||
@classmethod
|
||||
async def get_keyword_num(cls, tags: List[str] = None) -> "int, int, int":
|
||||
"""
|
||||
说明:
|
||||
获取相关关键词(keyword, tag)在图库中的数量
|
||||
参数:
|
||||
:param tags: 关键词/Tag
|
||||
"""
|
||||
setattr(OmegaPixivIllusts, 'count', db.func.count(cls.pid).label('count'))
|
||||
query = cls.select('count')
|
||||
if tags:
|
||||
for tag in tags:
|
||||
query = query.where(cls.tags.contains(tag))
|
||||
count = await query.where(cls.nsfw_tag == 0).gino.first()
|
||||
setu_count = await query.where(cls.nsfw_tag == 1).gino.first()
|
||||
r18_count = await query.where(cls.nsfw_tag == 2).gino.first()
|
||||
return count[0], setu_count[0], r18_count[0]
|
||||
|
||||
@classmethod
|
||||
async def get_all_pid(cls) -> List[int]:
|
||||
"""
|
||||
说明:
|
||||
获取所有图片PID
|
||||
"""
|
||||
data = await cls.select('pid').gino.all()
|
||||
return [x[0] for x in data]
|
||||
|
||||
@classmethod
|
||||
async def test(cls, nsfw_tag: int = 1):
|
||||
if nsfw_tag is not None:
|
||||
query = cls.query.where(cls.nsfw_tag == nsfw_tag)
|
||||
else:
|
||||
query = cls.query
|
||||
query = query.where((cls.width - cls.height) < 50)
|
||||
for x in await query.gino.all():
|
||||
print(x.pid)
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+170
-170
@@ -1,170 +1,170 @@
|
||||
from typing import Optional, List
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class Pixiv(db.Model):
|
||||
__tablename__ = "pixiv"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
pid = db.Column(db.BigInteger(), nullable=False)
|
||||
title = db.Column(db.String(), nullable=False)
|
||||
width = db.Column(db.Integer(), nullable=False)
|
||||
height = db.Column(db.Integer(), nullable=False)
|
||||
view = db.Column(db.Integer(), nullable=False)
|
||||
bookmarks = db.Column(db.Integer(), nullable=False)
|
||||
img_url = db.Column(db.String(), nullable=False)
|
||||
img_p = db.Column(db.String(), nullable=False)
|
||||
uid = db.Column(db.BigInteger(), nullable=False)
|
||||
author = db.Column(db.String(), nullable=False)
|
||||
is_r18 = db.Column(db.Boolean(), nullable=False)
|
||||
tags = db.Column(db.String(), nullable=False)
|
||||
|
||||
_idx1 = db.Index("pixiv_idx1", "pid", "img_url", unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_image_data(
|
||||
cls,
|
||||
pid: int,
|
||||
title: str,
|
||||
width: int,
|
||||
height: int,
|
||||
view: int,
|
||||
bookmarks: int,
|
||||
img_url: str,
|
||||
img_p: str,
|
||||
uid: int,
|
||||
author: str,
|
||||
tags: str,
|
||||
):
|
||||
"""
|
||||
说明:
|
||||
添加图片信息
|
||||
参数:
|
||||
:param pid: pid
|
||||
:param title: 标题
|
||||
:param width: 宽度
|
||||
:param height: 长度
|
||||
:param view: 被查看次数
|
||||
:param bookmarks: 收藏数
|
||||
:param img_url: url链接
|
||||
:param img_p: 张数
|
||||
:param uid: 作者uid
|
||||
:param author: 作者名称
|
||||
:param tags: 相关tag
|
||||
"""
|
||||
if not await cls.check_exists(pid, img_p):
|
||||
await cls.create(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
view=view,
|
||||
bookmarks=bookmarks,
|
||||
img_url=img_url,
|
||||
img_p=img_p,
|
||||
uid=uid,
|
||||
author=author,
|
||||
is_r18=True if "R-18" in tags else False,
|
||||
tags=tags,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def remove_image_data(cls, pid: int, img_p: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
删除图片数据
|
||||
参数:
|
||||
:param pid: 图片pid
|
||||
:param img_p: 图片pid的张数,如:p0,p1
|
||||
"""
|
||||
try:
|
||||
if img_p:
|
||||
await cls.delete.where(
|
||||
(cls.pid == pid) & (cls.img_p == img_p)
|
||||
).gino.status()
|
||||
else:
|
||||
await cls.delete.where(cls.pid == pid).gino.status()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def get_all_pid(cls) -> List[int]:
|
||||
"""
|
||||
说明:
|
||||
获取所有PID
|
||||
"""
|
||||
query = await cls.query.select("pid").gino.first()
|
||||
pid = [x[0] for x in query]
|
||||
return list(set(pid))
|
||||
|
||||
# 0:非r18 1:r18 2:混合
|
||||
@classmethod
|
||||
async def query_images(
|
||||
cls,
|
||||
keywords: Optional[List[str]] = None,
|
||||
uid: Optional[int] = None,
|
||||
pid: Optional[int] = None,
|
||||
r18: Optional[int] = 0,
|
||||
num: int = 100
|
||||
) -> List[Optional["Pixiv"]]:
|
||||
"""
|
||||
说明:
|
||||
查找符合条件的图片
|
||||
参数:
|
||||
:param keywords: 关键词
|
||||
:param uid: 画师uid
|
||||
:param pid: 图片pid
|
||||
:param r18: 是否r18,0:非r18 1:r18 2:混合
|
||||
:param num: 查找图片的数量
|
||||
"""
|
||||
if r18 == 0:
|
||||
query = cls.query.where(cls.is_r18 == False)
|
||||
elif r18 == 1:
|
||||
query = cls.query.where(cls.is_r18 == True)
|
||||
else:
|
||||
query = cls.query
|
||||
if keywords:
|
||||
for keyword in keywords:
|
||||
query = query.where(cls.tags.contains(keyword))
|
||||
elif uid:
|
||||
query = query.where(cls.uid == uid)
|
||||
elif pid:
|
||||
query = query.where(cls.pid == pid)
|
||||
query = query.order_by(db.func.random()).limit(num)
|
||||
return await query.gino.all()
|
||||
|
||||
@classmethod
|
||||
async def check_exists(cls, pid: int, img_p: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测pid是否已存在
|
||||
参数:
|
||||
:param pid: 图片PID
|
||||
:param img_p: 张数
|
||||
"""
|
||||
query = await cls.query.where(
|
||||
(cls.pid == pid) & (cls.img_p == img_p)
|
||||
).gino.all()
|
||||
return bool(query)
|
||||
|
||||
@classmethod
|
||||
async def get_keyword_num(cls, tags: List[str] = None) -> "int, int":
|
||||
"""
|
||||
说明:
|
||||
获取相关关键词(keyword, tag)在图库中的数量
|
||||
参数:
|
||||
:param tags: 关键词/Tag
|
||||
"""
|
||||
setattr(Pixiv, 'count', db.func.count(cls.pid).label('count'))
|
||||
query = cls.select('count')
|
||||
if tags:
|
||||
for tag in tags:
|
||||
query = query.where(cls.tags.contains(tag))
|
||||
count = await query.where(cls.is_r18 == False).gino.first()
|
||||
r18_count = await query.where(cls.is_r18 == True).gino.first()
|
||||
return count[0], r18_count[0]
|
||||
|
||||
from typing import Optional, List
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class Pixiv(db.Model):
|
||||
__tablename__ = "pixiv"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
pid = db.Column(db.BigInteger(), nullable=False)
|
||||
title = db.Column(db.String(), nullable=False)
|
||||
width = db.Column(db.Integer(), nullable=False)
|
||||
height = db.Column(db.Integer(), nullable=False)
|
||||
view = db.Column(db.Integer(), nullable=False)
|
||||
bookmarks = db.Column(db.Integer(), nullable=False)
|
||||
img_url = db.Column(db.String(), nullable=False)
|
||||
img_p = db.Column(db.String(), nullable=False)
|
||||
uid = db.Column(db.BigInteger(), nullable=False)
|
||||
author = db.Column(db.String(), nullable=False)
|
||||
is_r18 = db.Column(db.Boolean(), nullable=False)
|
||||
tags = db.Column(db.String(), nullable=False)
|
||||
|
||||
_idx1 = db.Index("pixiv_idx1", "pid", "img_url", unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_image_data(
|
||||
cls,
|
||||
pid: int,
|
||||
title: str,
|
||||
width: int,
|
||||
height: int,
|
||||
view: int,
|
||||
bookmarks: int,
|
||||
img_url: str,
|
||||
img_p: str,
|
||||
uid: int,
|
||||
author: str,
|
||||
tags: str,
|
||||
):
|
||||
"""
|
||||
说明:
|
||||
添加图片信息
|
||||
参数:
|
||||
:param pid: pid
|
||||
:param title: 标题
|
||||
:param width: 宽度
|
||||
:param height: 长度
|
||||
:param view: 被查看次数
|
||||
:param bookmarks: 收藏数
|
||||
:param img_url: url链接
|
||||
:param img_p: 张数
|
||||
:param uid: 作者uid
|
||||
:param author: 作者名称
|
||||
:param tags: 相关tag
|
||||
"""
|
||||
if not await cls.check_exists(pid, img_p):
|
||||
await cls.create(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
view=view,
|
||||
bookmarks=bookmarks,
|
||||
img_url=img_url,
|
||||
img_p=img_p,
|
||||
uid=uid,
|
||||
author=author,
|
||||
is_r18=True if "R-18" in tags else False,
|
||||
tags=tags,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def remove_image_data(cls, pid: int, img_p: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
删除图片数据
|
||||
参数:
|
||||
:param pid: 图片pid
|
||||
:param img_p: 图片pid的张数,如:p0,p1
|
||||
"""
|
||||
try:
|
||||
if img_p:
|
||||
await cls.delete.where(
|
||||
(cls.pid == pid) & (cls.img_p == img_p)
|
||||
).gino.status()
|
||||
else:
|
||||
await cls.delete.where(cls.pid == pid).gino.status()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def get_all_pid(cls) -> List[int]:
|
||||
"""
|
||||
说明:
|
||||
获取所有PID
|
||||
"""
|
||||
query = await cls.query.select("pid").gino.first()
|
||||
pid = [x[0] for x in query]
|
||||
return list(set(pid))
|
||||
|
||||
# 0:非r18 1:r18 2:混合
|
||||
@classmethod
|
||||
async def query_images(
|
||||
cls,
|
||||
keywords: Optional[List[str]] = None,
|
||||
uid: Optional[int] = None,
|
||||
pid: Optional[int] = None,
|
||||
r18: Optional[int] = 0,
|
||||
num: int = 100
|
||||
) -> List[Optional["Pixiv"]]:
|
||||
"""
|
||||
说明:
|
||||
查找符合条件的图片
|
||||
参数:
|
||||
:param keywords: 关键词
|
||||
:param uid: 画师uid
|
||||
:param pid: 图片pid
|
||||
:param r18: 是否r18,0:非r18 1:r18 2:混合
|
||||
:param num: 查找图片的数量
|
||||
"""
|
||||
if r18 == 0:
|
||||
query = cls.query.where(cls.is_r18 == False)
|
||||
elif r18 == 1:
|
||||
query = cls.query.where(cls.is_r18 == True)
|
||||
else:
|
||||
query = cls.query
|
||||
if keywords:
|
||||
for keyword in keywords:
|
||||
query = query.where(cls.tags.contains(keyword))
|
||||
elif uid:
|
||||
query = query.where(cls.uid == uid)
|
||||
elif pid:
|
||||
query = query.where(cls.pid == pid)
|
||||
query = query.order_by(db.func.random()).limit(num)
|
||||
return await query.gino.all()
|
||||
|
||||
@classmethod
|
||||
async def check_exists(cls, pid: int, img_p: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测pid是否已存在
|
||||
参数:
|
||||
:param pid: 图片PID
|
||||
:param img_p: 张数
|
||||
"""
|
||||
query = await cls.query.where(
|
||||
(cls.pid == pid) & (cls.img_p == img_p)
|
||||
).gino.all()
|
||||
return bool(query)
|
||||
|
||||
@classmethod
|
||||
async def get_keyword_num(cls, tags: List[str] = None) -> "int, int":
|
||||
"""
|
||||
说明:
|
||||
获取相关关键词(keyword, tag)在图库中的数量
|
||||
参数:
|
||||
:param tags: 关键词/Tag
|
||||
"""
|
||||
setattr(Pixiv, 'count', db.func.count(cls.pid).label('count'))
|
||||
query = cls.select('count')
|
||||
if tags:
|
||||
for tag in tags:
|
||||
query = query.where(cls.tags.contains(tag))
|
||||
count = await query.where(cls.is_r18 == False).gino.first()
|
||||
r18_count = await query.where(cls.is_r18 == True).gino.first()
|
||||
return count[0], r18_count[0]
|
||||
|
||||
Executable → Regular
+127
-127
@@ -1,127 +1,127 @@
|
||||
from services.db_context import db
|
||||
from typing import Set, List
|
||||
|
||||
|
||||
class PixivKeywordUser(db.Model):
|
||||
__tablename__ = "pixiv_keyword_users"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
group_id = db.Column(db.BigInteger(), nullable=False)
|
||||
keyword = db.Column(db.String(), nullable=False)
|
||||
is_pass = db.Column(db.Boolean(), default=False)
|
||||
|
||||
_idx1 = db.Index("pixiv_keyword_users_idx1", "keyword", unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_keyword(
|
||||
cls, user_qq: int, group_id: int, keyword: str, superusers: Set[str]
|
||||
) -> bool:
|
||||
"""
|
||||
说明:
|
||||
添加搜图的关键词
|
||||
参数:
|
||||
:param user_qq: qq号
|
||||
:param group_id: 群号
|
||||
:param keyword: 关键词
|
||||
:param superusers: 是否为超级用户
|
||||
"""
|
||||
is_pass = True if str(user_qq) in superusers else False
|
||||
if not await cls._check_keyword_exists(keyword):
|
||||
await cls.create(
|
||||
user_qq=user_qq, group_id=group_id, keyword=keyword, is_pass=is_pass
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def delete_keyword(cls, keyword: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
删除关键词
|
||||
参数:
|
||||
:param keyword: 关键词
|
||||
"""
|
||||
if await cls._check_keyword_exists(keyword):
|
||||
query = cls.query.where(cls.keyword == keyword).with_for_update()
|
||||
query = await query.gino.first()
|
||||
await query.delete()
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def set_keyword_pass(cls, keyword: str, is_pass: bool) -> "int, int":
|
||||
"""
|
||||
说明:
|
||||
通过或禁用关键词
|
||||
参数:
|
||||
:param keyword: 关键词
|
||||
:param is_pass: 通过状态
|
||||
"""
|
||||
if await cls._check_keyword_exists(keyword):
|
||||
query = cls.query.where(cls.keyword == keyword).with_for_update()
|
||||
query = await query.gino.first()
|
||||
await query.update(
|
||||
is_pass=is_pass,
|
||||
).apply()
|
||||
return query.user_qq, query.group_id
|
||||
return 0, 0
|
||||
|
||||
@classmethod
|
||||
async def get_all_user_dict(cls) -> dict:
|
||||
"""
|
||||
说明:
|
||||
获取关键词数据库各个用户贡献的关键词字典
|
||||
"""
|
||||
tmp = {}
|
||||
query = await cls.query.gino.all()
|
||||
for user in query:
|
||||
if not tmp.get(user.user_qq):
|
||||
tmp[user.user_qq] = {"keyword": []}
|
||||
tmp[user.user_qq]["keyword"].append(user.keyword)
|
||||
return tmp
|
||||
|
||||
@classmethod
|
||||
async def get_current_keyword(cls) -> "List[str], List[str]":
|
||||
"""
|
||||
说明:
|
||||
获取当前通过与未通过的关键词
|
||||
"""
|
||||
pass_keyword = []
|
||||
not_pass_keyword = []
|
||||
query = await cls.query.gino.all()
|
||||
for user in query:
|
||||
if user.is_pass:
|
||||
pass_keyword.append(user.keyword)
|
||||
else:
|
||||
not_pass_keyword.append(user.keyword)
|
||||
return pass_keyword, not_pass_keyword
|
||||
|
||||
@classmethod
|
||||
async def get_black_pid(cls) -> List[str]:
|
||||
"""
|
||||
说明:
|
||||
获取黑名单PID
|
||||
"""
|
||||
black_pid = []
|
||||
query = await cls.query.where(cls.user_qq == 114514).gino.all()
|
||||
for image in query:
|
||||
black_pid.append(image.keyword[6:])
|
||||
return black_pid
|
||||
|
||||
@classmethod
|
||||
async def _check_keyword_exists(cls, keyword: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测关键词是否已存在
|
||||
参数:
|
||||
:param keyword: 关键词
|
||||
"""
|
||||
current_keyword = []
|
||||
query = await cls.query.gino.all()
|
||||
for user in query:
|
||||
current_keyword.append(user.keyword)
|
||||
if keyword in current_keyword:
|
||||
return True
|
||||
return False
|
||||
from services.db_context import db
|
||||
from typing import Set, List
|
||||
|
||||
|
||||
class PixivKeywordUser(db.Model):
|
||||
__tablename__ = "pixiv_keyword_users"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
group_id = db.Column(db.BigInteger(), nullable=False)
|
||||
keyword = db.Column(db.String(), nullable=False)
|
||||
is_pass = db.Column(db.Boolean(), default=False)
|
||||
|
||||
_idx1 = db.Index("pixiv_keyword_users_idx1", "keyword", unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_keyword(
|
||||
cls, user_qq: int, group_id: int, keyword: str, superusers: Set[str]
|
||||
) -> bool:
|
||||
"""
|
||||
说明:
|
||||
添加搜图的关键词
|
||||
参数:
|
||||
:param user_qq: qq号
|
||||
:param group_id: 群号
|
||||
:param keyword: 关键词
|
||||
:param superusers: 是否为超级用户
|
||||
"""
|
||||
is_pass = True if str(user_qq) in superusers else False
|
||||
if not await cls._check_keyword_exists(keyword):
|
||||
await cls.create(
|
||||
user_qq=user_qq, group_id=group_id, keyword=keyword, is_pass=is_pass
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def delete_keyword(cls, keyword: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
删除关键词
|
||||
参数:
|
||||
:param keyword: 关键词
|
||||
"""
|
||||
if await cls._check_keyword_exists(keyword):
|
||||
query = cls.query.where(cls.keyword == keyword).with_for_update()
|
||||
query = await query.gino.first()
|
||||
await query.delete()
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def set_keyword_pass(cls, keyword: str, is_pass: bool) -> "int, int":
|
||||
"""
|
||||
说明:
|
||||
通过或禁用关键词
|
||||
参数:
|
||||
:param keyword: 关键词
|
||||
:param is_pass: 通过状态
|
||||
"""
|
||||
if await cls._check_keyword_exists(keyword):
|
||||
query = cls.query.where(cls.keyword == keyword).with_for_update()
|
||||
query = await query.gino.first()
|
||||
await query.update(
|
||||
is_pass=is_pass,
|
||||
).apply()
|
||||
return query.user_qq, query.group_id
|
||||
return 0, 0
|
||||
|
||||
@classmethod
|
||||
async def get_all_user_dict(cls) -> dict:
|
||||
"""
|
||||
说明:
|
||||
获取关键词数据库各个用户贡献的关键词字典
|
||||
"""
|
||||
tmp = {}
|
||||
query = await cls.query.gino.all()
|
||||
for user in query:
|
||||
if not tmp.get(user.user_qq):
|
||||
tmp[user.user_qq] = {"keyword": []}
|
||||
tmp[user.user_qq]["keyword"].append(user.keyword)
|
||||
return tmp
|
||||
|
||||
@classmethod
|
||||
async def get_current_keyword(cls) -> "List[str], List[str]":
|
||||
"""
|
||||
说明:
|
||||
获取当前通过与未通过的关键词
|
||||
"""
|
||||
pass_keyword = []
|
||||
not_pass_keyword = []
|
||||
query = await cls.query.gino.all()
|
||||
for user in query:
|
||||
if user.is_pass:
|
||||
pass_keyword.append(user.keyword)
|
||||
else:
|
||||
not_pass_keyword.append(user.keyword)
|
||||
return pass_keyword, not_pass_keyword
|
||||
|
||||
@classmethod
|
||||
async def get_black_pid(cls) -> List[str]:
|
||||
"""
|
||||
说明:
|
||||
获取黑名单PID
|
||||
"""
|
||||
black_pid = []
|
||||
query = await cls.query.where(cls.user_qq == 114514).gino.all()
|
||||
for image in query:
|
||||
black_pid.append(image.keyword[6:])
|
||||
return black_pid
|
||||
|
||||
@classmethod
|
||||
async def _check_keyword_exists(cls, keyword: str) -> bool:
|
||||
"""
|
||||
说明:
|
||||
检测关键词是否已存在
|
||||
参数:
|
||||
:param keyword: 关键词
|
||||
"""
|
||||
current_keyword = []
|
||||
query = await cls.query.gino.all()
|
||||
for user in query:
|
||||
current_keyword.append(user.keyword)
|
||||
if keyword in current_keyword:
|
||||
return True
|
||||
return False
|
||||
@@ -1,18 +1,18 @@
|
||||
from nonebot.adapters.cqhttp.message import Message
|
||||
from utils.utils import get_message_text, is_number
|
||||
from utils.utils import is_number
|
||||
from configs.config import Config
|
||||
from .model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from ._model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from utils.message_builder import image
|
||||
from utils.manager import withdraw_message_manager
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import (
|
||||
from nonebot.adapters.onebot.v11 import (
|
||||
Bot,
|
||||
MessageEvent,
|
||||
GroupMessageEvent,
|
||||
Message
|
||||
)
|
||||
from nonebot.typing import T_State
|
||||
from .data_source import get_image
|
||||
from .model.pixiv import Pixiv
|
||||
from nonebot.params import CommandArg
|
||||
from ._data_source import get_image
|
||||
from ._model.pixiv import Pixiv
|
||||
from nonebot import on_command
|
||||
import random
|
||||
|
||||
@@ -59,7 +59,7 @@ OMEGA_RATIO = None
|
||||
|
||||
|
||||
@pix.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
global PIX_RATIO, OMEGA_RATIO
|
||||
if PIX_RATIO is None:
|
||||
pix_omega_pixiv_ratio = Config.get_config("pix", "PIX_OMEGA_PIXIV_RATIO")
|
||||
@@ -68,7 +68,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
)
|
||||
OMEGA_RATIO = 1 - PIX_RATIO
|
||||
num = 1
|
||||
keyword = get_message_text(event.json())
|
||||
keyword = arg.extract_plain_text().strip()
|
||||
x = keyword.split(" ")
|
||||
if "-s" in x:
|
||||
x.remove("-s")
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from nonebot import on_command
|
||||
from utils.utils import get_message_text, is_number
|
||||
from utils.utils import is_number
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from nonebot.typing import T_State
|
||||
from .data_source import uid_pid_exists
|
||||
from .model.pixiv_keyword_user import PixivKeywordUser
|
||||
from .model.pixiv import Pixiv
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg, Command
|
||||
from typing import Tuple
|
||||
from ._data_source import uid_pid_exists
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
from ._model.pixiv import Pixiv
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
__zx_plugin_name__ = "PIX关键词/UID/PID添加管理 [Superuser]"
|
||||
@@ -39,8 +40,8 @@ add_uid_pid = on_command(
|
||||
|
||||
|
||||
@add_keyword.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip()
|
||||
group_id = -1
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
group_id = event.group_id
|
||||
@@ -62,8 +63,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@add_uid_pid.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip()
|
||||
exists_flag = True
|
||||
if msg.find("-f") != -1 and str(event.user_id) in bot.config.superusers:
|
||||
exists_flag = False
|
||||
@@ -72,7 +73,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
for msg in msg.split():
|
||||
if not is_number(msg):
|
||||
await add_uid_pid.finish("UID只能是数字的说...", at_sender=True)
|
||||
if state["_prefix"]["raw_command"].lower().endswith("uid"):
|
||||
if cmd[0].lower().endswith("uid"):
|
||||
msg = f"uid:{msg}"
|
||||
else:
|
||||
msg = f"pid:{msg}"
|
||||
@@ -96,8 +97,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@add_black_pid.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
pid = get_message_text(event.json())
|
||||
async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
pid = arg.extract_plain_text().strip()
|
||||
img_p = ""
|
||||
if "p" in pid:
|
||||
img_p = pid.split("p")[-1]
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.cqhttp.message import Message
|
||||
from utils.utils import get_message_text, is_number
|
||||
from utils.utils import is_number
|
||||
from utils.message_builder import at
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg, Command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.typing import T_State
|
||||
from .data_source import remove_image
|
||||
from .model.pixiv_keyword_user import PixivKeywordUser
|
||||
from .model.pixiv import Pixiv
|
||||
from ._data_source import remove_image
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
from ._model.pixiv import Pixiv
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
__zx_plugin_name__ = "PIX关键词/UID/PID删除管理 [Superuser]"
|
||||
@@ -52,8 +52,8 @@ del_pic = on_command("删除pix图片", permission=SUPERUSER, priority=1, block=
|
||||
|
||||
|
||||
@del_keyword.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
async def _(event: MessageEvent, arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip()
|
||||
if not msg:
|
||||
await del_keyword.finish("好好输入要删除什么关键字啊笨蛋!")
|
||||
if is_number(msg):
|
||||
@@ -71,8 +71,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@del_pic.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
pid_arr = get_message_text(event.json())
|
||||
async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
pid_arr = arg.extract_plain_text().strip()
|
||||
if pid_arr:
|
||||
msg = ""
|
||||
black_pid = ""
|
||||
@@ -127,13 +127,13 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@pass_keyword.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message = CommandArg()):
|
||||
tmp = {"group": {}, "private": {}}
|
||||
msg = get_message_text(event.json())
|
||||
msg = arg.extract_plain_text().strip()
|
||||
if not msg:
|
||||
await pass_keyword.finish("通过虚空的关键词/UID?离谱...")
|
||||
msg = msg.split()
|
||||
flag = True if state["_prefix"]["raw_command"][:2] == "通过" else False
|
||||
flag = cmd[0][:2] == "通过"
|
||||
for x in msg:
|
||||
if x.lower().startswith("uid"):
|
||||
x = x.replace("uid", "").replace(":", "")
|
||||
@@ -163,7 +163,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
else:
|
||||
tmp["group"][group_id][user_id]["keyword"].append(x)
|
||||
msg = " ".join(msg)
|
||||
await pass_keyword.send(f'已成功{state["_prefix"]["raw_command"][:2]}搜图关键词:{msg}....')
|
||||
await pass_keyword.send(f'已成功{cmd[0][:2]}搜图关键词:{msg}....')
|
||||
for user in tmp["private"]:
|
||||
x = ",".join(tmp["private"][user]["keyword"])
|
||||
await bot.send_private_msg(
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from nonebot import on_command
|
||||
from utils.utils import get_message_text
|
||||
from utils.message_builder import image
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent
|
||||
from nonebot.typing import T_State
|
||||
from .data_source import gen_keyword_pic, get_keyword_num
|
||||
from .model.pixiv_keyword_user import PixivKeywordUser
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, Message
|
||||
from ._data_source import gen_keyword_pic, get_keyword_num
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
from nonebot.params import CommandArg
|
||||
import asyncio
|
||||
|
||||
|
||||
@@ -35,7 +34,7 @@ show_pix = on_command("查看pix图库", priority=1, block=True)
|
||||
|
||||
|
||||
@my_keyword.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _(event: MessageEvent):
|
||||
data = await PixivKeywordUser.get_all_user_dict()
|
||||
if data.get(event.user_id) is None or not data[event.user_id]["keyword"]:
|
||||
await my_keyword.finish("您目前没有提供任何Pixiv搜图关键字...", at_sender=True)
|
||||
@@ -45,7 +44,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@show_keyword.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _(bot: Bot, event: MessageEvent):
|
||||
_pass_keyword, not_pass_keyword = await PixivKeywordUser.get_current_keyword()
|
||||
if _pass_keyword or not_pass_keyword:
|
||||
await show_keyword.send(
|
||||
@@ -67,8 +66,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@show_pix.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
keyword = get_message_text(event.json())
|
||||
async def _(arg: Message = CommandArg()):
|
||||
keyword = arg.extract_plain_text().strip()
|
||||
count, r18_count, count_, setu_count, r18_count_ = await get_keyword_num(keyword)
|
||||
await show_pix.send(
|
||||
f"PIX图库:{keyword}\n"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from nonebot import on_command
|
||||
from utils.utils import get_message_text, is_number
|
||||
from utils.utils import is_number
|
||||
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
|
||||
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.onebot.v11 import Message
|
||||
from nonebot.params import CommandArg
|
||||
import time
|
||||
from services.log import logger
|
||||
from pathlib import Path
|
||||
@@ -47,8 +47,8 @@ check_omega = on_command("检测omega图库", permission=SUPERUSER, priority=1,
|
||||
|
||||
|
||||
@start_update.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg_sp = get_message_text(event.json()).split()
|
||||
async def _(arg: Message = CommandArg()):
|
||||
msg_sp = arg.extract_plain_text().strip().split()
|
||||
_pass_keyword, _ = await PixivKeywordUser.get_current_keyword()
|
||||
_pass_keyword.reverse()
|
||||
black_pid = await PixivKeywordUser.get_black_pid()
|
||||
@@ -105,8 +105,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@check_not_update_uid_pid.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
async def _(arg: Message = CommandArg()):
|
||||
msg = arg.extract_plain_text().strip()
|
||||
flag = False
|
||||
if msg == "update":
|
||||
flag = True
|
||||
@@ -142,7 +142,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
|
||||
|
||||
@check_omega.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
async def _():
|
||||
async def _tasks(line: str, all_pid: List[int], length: int, index: int):
|
||||
data = line.split("VALUES", maxsplit=1)[-1].strip()
|
||||
if data.startswith("("):
|
||||
|
||||
Reference in New Issue
Block a user