mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-09 22:00:01 +08:00
modified: basic_plugins/admin_bot_manage/_data_source.py
modified: basic_plugins/admin_bot_manage/admin_config.py modified: basic_plugins/admin_bot_manage/custom_welcome_message.py modified: basic_plugins/admin_bot_manage/timing_task.py modified: basic_plugins/apscheduler/__init__.py modified: basic_plugins/ban/__init__.py modified: basic_plugins/ban/data_source.py modified: basic_plugins/chat_history/chat_message.py modified: basic_plugins/chat_history/chat_message_handle.py modified: basic_plugins/group_handle/__init__.py modified: basic_plugins/hooks/_utils.py modified: basic_plugins/hooks/ban_hook.py modified: basic_plugins/hooks/chkdsk_hook.py modified: basic_plugins/init_plugin_config/__init__.py deleted: basic_plugins/init_plugin_config/init_group_manager.py modified: basic_plugins/invite_manager/__init__.py new file: basic_plugins/invite_manager/utils.py modified: basic_plugins/nickname.py modified: basic_plugins/plugin_shop/__init__.py modified: basic_plugins/plugin_shop/data_source.py modified: basic_plugins/scripts.py modified: basic_plugins/shop/__init__.py modified: basic_plugins/shop/buy.py modified: basic_plugins/shop/gold.py modified: basic_plugins/shop/my_props/__init__.py deleted: basic_plugins/shop/reset_today_gold.py modified: basic_plugins/shop/shop_handle/__init__.py modified: basic_plugins/shop/shop_handle/data_source.py modified: basic_plugins/shop/use/__init__.py modified: basic_plugins/shop/use/data_source.py modified: basic_plugins/super_cmd/__init__.py modified: basic_plugins/super_cmd/bot_friend_group.py modified: basic_plugins/super_cmd/clear_data.py modified: basic_plugins/super_cmd/exec_sql.py modified: basic_plugins/super_cmd/manager_group.py modified: basic_plugins/super_cmd/reload_setting.py modified: basic_plugins/super_cmd/set_admin_permissions.py deleted: basic_plugins/super_cmd/super_task_switch.py modified: basic_plugins/super_cmd/update_friend_group_info.py modified: basic_plugins/super_help/__init__.py modified: basic_plugins/update_info.py modified: configs/config.py modified: configs/utils/__init__.py modified: models/bag_user.py modified: models/ban_user.py modified: models/chat_history.py modified: models/friend_user.py modified: models/goods_info.py modified: models/group_info.py modified: models/group_member_info.py modified: models/level_user.py modified: models/sign_group_user.py modified: models/user_shop_gold_log.py modified: plugins/aconfig/__init__.py modified: plugins/ai/__init__.py modified: plugins/ai/data_source.py modified: plugins/bilibili_sub/__init__.py modified: plugins/bilibili_sub/data_source.py modified: plugins/bilibili_sub/model.py modified: plugins/black_word/__init__.py modified: plugins/black_word/model.py modified: plugins/black_word/utils.py modified: plugins/bt/data_source.py modified: plugins/genshin/almanac/__init__.py modified: plugins/genshin/material_remind/__init__.py modified: plugins/genshin/query_user/_models/__init__.py modified: plugins/genshin/query_user/_utils/__init__.py modified: plugins/genshin/query_user/bind/__init__.py modified: plugins/genshin/query_user/genshin_sign/__init__.py modified: plugins/genshin/query_user/genshin_sign/data_source.py modified: plugins/genshin/query_user/genshin_sign/init_task.py modified: plugins/genshin/query_user/mihoyobbs_sign/__init__.py modified: plugins/genshin/query_user/query_memo/__init__.py modified: plugins/genshin/query_user/query_memo/data_source.py modified: plugins/genshin/query_user/query_role/__init__.py modified: plugins/genshin/query_user/query_role/data_source.py modified: plugins/genshin/query_user/reset_today_query_user_data/__init__.py modified: plugins/genshin/query_user/resin_remind/__init__.py modified: plugins/genshin/query_user/resin_remind/init_task.py modified: plugins/gold_redbag/model.py modified: plugins/image_management/send_image/__init__.py modified: plugins/my_info/__init__.py modified: plugins/open_cases/models/buff_prices.py modified: plugins/open_cases/models/open_cases_user.py modified: plugins/open_cases/open_cases_c.py modified: plugins/open_cases/utils.py modified: plugins/parse_bilibili_json.py modified: plugins/pid_search.py modified: plugins/pix_gallery/__init__.py modified: plugins/pix_gallery/_data_source.py modified: plugins/pix_gallery/_model/omega_pixiv_illusts.py modified: plugins/pix_gallery/_model/pixiv.py modified: plugins/pix_gallery/_model/pixiv_keyword_user.py modified: plugins/pix_gallery/pix_add_keyword.py modified: plugins/pix_gallery/pix_pass_del_keyword.py modified: plugins/pix_gallery/pix_show_info.py modified: plugins/pix_gallery/pix_update.py modified: plugins/pixiv_rank_search/data_source.py modified: plugins/poke/__init__.py modified: plugins/russian/__init__.py modified: plugins/russian/data_source.py modified: plugins/russian/model.py modified: plugins/send_dinggong_voice/__init__.py modified: plugins/send_setu_/_model.py modified: plugins/send_setu_/send_setu/__init__.py modified: plugins/send_setu_/send_setu/data_source.py modified: plugins/send_setu_/update_setu/data_source.py modified: plugins/sign_in/goods_register.py modified: plugins/sign_in/group_user_checkin.py modified: plugins/sign_in/random_event.py modified: plugins/sign_in/utils.py modified: plugins/statistics/_model.py modified: plugins/statistics/statistics_handle.py modified: plugins/statistics/statistics_hook.py modified: plugins/update_picture.py modified: plugins/web_ui/api/request.py modified: plugins/word_bank/_model.py deleted: plugins/word_bank/_old_model.py modified: plugins/word_bank/_rule.py modified: plugins/word_bank/word_handle.py modified: plugins/word_clouds/data_source.py modified: resources/image/sign/sign_res/bar.png modified: resources/image/sign/sign_res/bar_white.png modified: services/db_context.py modified: services/log.py modified: utils/browser.py modified: utils/data_utils.py modified: utils/depends/__init__.py modified: utils/http_utils.py modified: utils/image_utils.py modified: utils/manager/admin_manager.py modified: utils/message_builder.py modified: utils/utils.py
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from configs.config import Config
|
||||
from utils.utils import GDict
|
||||
import nonebot
|
||||
|
||||
from configs.config import Config
|
||||
from utils.utils import GDict
|
||||
|
||||
Config.add_plugin_config(
|
||||
"hibiapi",
|
||||
@@ -10,59 +10,42 @@ Config.add_plugin_config(
|
||||
help_="如果没有自建或其他hibiapi请不要修改",
|
||||
default_value="https://api.obfs.dev",
|
||||
)
|
||||
Config.add_plugin_config(
|
||||
"pixiv",
|
||||
"PIXIV_NGINX_URL",
|
||||
"i.pximg.cf",
|
||||
help_="Pixiv反向代理"
|
||||
)
|
||||
Config.add_plugin_config("pixiv", "PIXIV_NGINX_URL", "i.pximg.cf", help_="Pixiv反向代理")
|
||||
Config.add_plugin_config(
|
||||
"pix",
|
||||
"PIX_IMAGE_SIZE",
|
||||
"master",
|
||||
name="PIX图库",
|
||||
help_="PIX图库下载的画质 可能的值:original:原图,master:缩略图(加快发送速度)",
|
||||
default_value="master"
|
||||
default_value="master",
|
||||
)
|
||||
Config.add_plugin_config(
|
||||
"pix",
|
||||
"SEARCH_HIBIAPI_BOOKMARKS",
|
||||
5000,
|
||||
help_="最低收藏,PIX使用HIBIAPI搜索图片时达到最低收藏才会添加至图库",
|
||||
default_value=5000
|
||||
default_value=5000,
|
||||
)
|
||||
Config.add_plugin_config(
|
||||
"pix",
|
||||
"WITHDRAW_PIX_MESSAGE",
|
||||
(0, 1),
|
||||
help_="自动撤回,参1:延迟撤回色图时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
|
||||
default_value=(0, 1)
|
||||
default_value=(0, 1),
|
||||
)
|
||||
Config.add_plugin_config(
|
||||
"pix",
|
||||
"PIX_OMEGA_PIXIV_RATIO",
|
||||
(10, 0),
|
||||
help_="PIX图库 与 额外图库OmegaPixivIllusts 混合搜索的比例 参1:PIX图库 参2:OmegaPixivIllusts扩展图库(没有此图库请设置为0)",
|
||||
default_value=(10, 0)
|
||||
)
|
||||
Config.add_plugin_config(
|
||||
"pix",
|
||||
"TIMEOUT",
|
||||
10,
|
||||
help_="下载图片超时限制(秒)",
|
||||
default_value=10
|
||||
default_value=(10, 0),
|
||||
)
|
||||
Config.add_plugin_config("pix", "TIMEOUT", 10, help_="下载图片超时限制(秒)", default_value=10)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"pix",
|
||||
"SHOW_INFO",
|
||||
True,
|
||||
help_="是否显示图片的基本信息,如PID等",
|
||||
default_value=True
|
||||
"pix", "SHOW_INFO", True, help_="是否显示图片的基本信息,如PID等", default_value=True
|
||||
)
|
||||
|
||||
GDict['run_sql'].append("ALTER TABLE omega_pixiv_illusts ADD classified Integer;")
|
||||
GDict["run_sql"].append("ALTER TABLE omega_pixiv_illusts ADD classified Integer;")
|
||||
|
||||
nonebot.load_plugins("plugins/pix_gallery")
|
||||
|
||||
|
||||
|
||||
+123
-116
@@ -1,19 +1,23 @@
|
||||
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, change_img_md5
|
||||
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
|
||||
import platform
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from asyncio.locks import Semaphore
|
||||
from copy import deepcopy
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
import aiofiles
|
||||
from asyncpg.exceptions import UniqueViolationError
|
||||
|
||||
from configs.config import Config
|
||||
from configs.path_config import TEMP_PATH
|
||||
from services.log import logger
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from utils.image_utils import BuildImage
|
||||
from utils.utils import change_img_md5, change_pixiv_image_links
|
||||
|
||||
from ._model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from ._model.pixiv import Pixiv
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
@@ -65,9 +69,7 @@ async def start_update_image_url(
|
||||
params = {"word": keyword, "page": page}
|
||||
tasks.append(
|
||||
asyncio.ensure_future(
|
||||
search_image(
|
||||
url, keyword, params, semaphore, page, black_pid
|
||||
)
|
||||
search_image(url, keyword, params, semaphore, page, black_pid)
|
||||
)
|
||||
)
|
||||
if keyword.startswith("pid:"):
|
||||
@@ -101,96 +103,91 @@ async def search_image(
|
||||
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"]
|
||||
# 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:
|
||||
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")
|
||||
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
|
||||
)
|
||||
and len(img_urls) < 10
|
||||
and _check_black(img_urls, black)
|
||||
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]
|
||||
data_copy = deepcopy(data)
|
||||
del data_copy["img_urls"]
|
||||
for img_url in data["img_urls"]:
|
||||
img_p = img_url[img_url.rfind("_") + 1 : img_url.rfind(".")]
|
||||
data_copy["img_url"] = img_url
|
||||
data_copy["img_p"] = img_p
|
||||
data_copy["is_r18"] = "R-18" in data["tags"]
|
||||
if not await Pixiv.exists(
|
||||
pid=data["pid"], img_url=img_url, img_p=img_p
|
||||
):
|
||||
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,
|
||||
}
|
||||
data_copy["img_url"] = img_url
|
||||
await Pixiv.create(**data_copy)
|
||||
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}')
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
@@ -206,7 +203,9 @@ async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
params = {"id": pid}
|
||||
for _ in range(3):
|
||||
try:
|
||||
response = await AsyncHttpx.get(f"{HIBIAPI}/api/pixiv/illust", params=params)
|
||||
response = await AsyncHttpx.get(
|
||||
f"{HIBIAPI}/api/pixiv/illust", params=params
|
||||
)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get("illust"):
|
||||
@@ -215,22 +214,28 @@ async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
"original_image_url"
|
||||
]
|
||||
else:
|
||||
img_url = data["illust"]["meta_pages"][0][
|
||||
"image_urls"
|
||||
]["original"]
|
||||
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")
|
||||
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"),)
|
||||
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
|
||||
@@ -238,7 +243,9 @@ async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg", "wb"
|
||||
) as f:
|
||||
await f.write(response.content)
|
||||
change_img_md5(TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg")
|
||||
change_img_md5(
|
||||
TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg"
|
||||
)
|
||||
return TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg"
|
||||
except TimeoutError:
|
||||
logger.warning(f"PIX:{img_url} 图片下载超时...")
|
||||
@@ -264,7 +271,7 @@ async def uid_pid_exists(id_: str) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def get_keyword_num(keyword: str) -> "int, int, int, int, int":
|
||||
async def get_keyword_num(keyword: str) -> Tuple[int, int, int, int, int]:
|
||||
"""
|
||||
查看图片相关 tag 数量
|
||||
:param keyword: 关键词tag
|
||||
@@ -276,7 +283,7 @@ async def get_keyword_num(keyword: str) -> "int, int, int, int, int":
|
||||
return count, r18_count, count_, setu_count, r18_count_
|
||||
|
||||
|
||||
async def remove_image(pid: int, img_p: str) -> bool:
|
||||
async def remove_image(pid: int, img_p: Optional[str]):
|
||||
"""
|
||||
删除置顶图片
|
||||
:param pid: pid
|
||||
@@ -285,7 +292,10 @@ async def remove_image(pid: int, img_p: str) -> bool:
|
||||
if img_p:
|
||||
if "p" not in img_p:
|
||||
img_p = f"p{img_p}"
|
||||
return await Pixiv.remove_image_data(pid, img_p)
|
||||
if img_p:
|
||||
await Pixiv.filter(pid=pid, img_p=img_p).delete()
|
||||
else:
|
||||
await Pixiv.filter(pid=pid).delete()
|
||||
|
||||
|
||||
def gen_keyword_pic(
|
||||
@@ -392,6 +402,3 @@ def _check_black(img_urls: List[str], black: List[str]) -> bool:
|
||||
if b in img_url:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,79 +1,50 @@
|
||||
from typing import Optional, List, Tuple
|
||||
from services.db_context import db
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from tortoise import fields
|
||||
from tortoise.contrib.postgres.functions import Random
|
||||
|
||||
from services.db_context import Model
|
||||
|
||||
|
||||
class OmegaPixivIllusts(db.Model):
|
||||
__tablename__ = "omega_pixiv_illusts"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
class OmegaPixivIllusts(Model):
|
||||
|
||||
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)
|
||||
classified = db.Column(db.Integer(), 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)
|
||||
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
||||
"""自增id"""
|
||||
pid = fields.BigIntField()
|
||||
"""pid"""
|
||||
uid = fields.BigIntField()
|
||||
"""uid"""
|
||||
title = fields.CharField(255)
|
||||
"""标题"""
|
||||
uname = fields.CharField(255)
|
||||
"""画师名称"""
|
||||
classified = fields.IntField()
|
||||
"""标记标签, 0=未标记, 1=已人工标记或从可信已标记来源获取"""
|
||||
nsfw_tag = fields.IntField()
|
||||
"""nsfw标签,-1=未标记, 0=safe, 1=setu. 2=r18"""
|
||||
width = fields.IntField()
|
||||
"""宽度"""
|
||||
height = fields.IntField()
|
||||
"""高度"""
|
||||
tags = fields.TextField()
|
||||
"""tags"""
|
||||
url = fields.CharField(255)
|
||||
"""pixiv url链接"""
|
||||
|
||||
_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,
|
||||
classified: int,
|
||||
nsfw_tag: int,
|
||||
tags: str,
|
||||
):
|
||||
"""
|
||||
说明:
|
||||
添加图片信息
|
||||
参数:
|
||||
:param pid: pid
|
||||
:param title: 标题
|
||||
:param width: 宽度
|
||||
:param height: 长度
|
||||
:param url: url链接
|
||||
:param uid: 作者uid
|
||||
:param uname: 作者名称
|
||||
:param classified: 标记标签, 0=未标记, 1=已人工标记或从可信已标记来源获取
|
||||
:param nsfw_tag: nsfw标签,-1=未标记, 0=safe, 1=setu. 2=r18
|
||||
:param tags: 相关tag
|
||||
"""
|
||||
if not await cls.check_exists(pid):
|
||||
await cls.create(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
url=url,
|
||||
uid=uid,
|
||||
uname=uname,
|
||||
classified=classified,
|
||||
nsfw_tag=nsfw_tag,
|
||||
tags=tags,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
class Meta:
|
||||
table = "omega_pixiv_illusts"
|
||||
table_description = "omega图库数据表"
|
||||
unique_together = ("pid", "url")
|
||||
|
||||
@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"]]:
|
||||
cls,
|
||||
keywords: Optional[List[str]] = None,
|
||||
uid: Optional[int] = None,
|
||||
pid: Optional[int] = None,
|
||||
nsfw_tag: Optional[int] = 0,
|
||||
num: int = 100,
|
||||
) -> List["OmegaPixivIllusts"]:
|
||||
"""
|
||||
说明:
|
||||
查找符合条件的图片
|
||||
@@ -84,66 +55,38 @@ class OmegaPixivIllusts(db.Model):
|
||||
:param nsfw_tag: nsfw标签, 0=safe, 1=setu. 2=r18
|
||||
:param num: 获取图片数量
|
||||
"""
|
||||
if not num:
|
||||
return []
|
||||
query = cls
|
||||
if nsfw_tag is not None:
|
||||
query = cls.query.where(cls.nsfw_tag == nsfw_tag)
|
||||
else:
|
||||
query = cls.query
|
||||
query = cls.filter(nsfw_tag=nsfw_tag)
|
||||
if keywords:
|
||||
for keyword in keywords:
|
||||
query = query.where(cls.tags.contains(keyword))
|
||||
query = query.filter(tags__contains=keyword)
|
||||
elif uid:
|
||||
query = query.where(cls.uid == uid)
|
||||
query = query.filter(uid=uid)
|
||||
elif pid:
|
||||
query = query.where(cls.uid == pid)
|
||||
query = query.order_by(db.func.random()).limit(num)
|
||||
return await query.gino.all()
|
||||
query = query.filter(pid=pid)
|
||||
query = query.annotate(rand=Random()).limit(num)
|
||||
return await query.all() # type: ignore
|
||||
|
||||
@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) -> Tuple[int, int, int]:
|
||||
async def get_keyword_num(
|
||||
cls, tags: Optional[List[str]] = None
|
||||
) -> Tuple[int, int, int]:
|
||||
"""
|
||||
说明:
|
||||
获取相关关键词(keyword, tag)在图库中的数量
|
||||
参数:
|
||||
:param tags: 关键词/Tag
|
||||
"""
|
||||
setattr(OmegaPixivIllusts, 'count', db.func.count(cls.pid).label('count'))
|
||||
query = cls.select('count')
|
||||
query = cls
|
||||
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]
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
|
||||
query = query.filter(tags__contains=tag)
|
||||
else:
|
||||
query = query.all()
|
||||
count = await query.filter(nsfw_tag=0).count()
|
||||
setu_count = await query.filter(nsfw_tag=1).count()
|
||||
r18_count = await query.filter(nsfw_tag=2).count()
|
||||
return count, setu_count, r18_count
|
||||
|
||||
@@ -1,105 +1,43 @@
|
||||
from typing import Optional, List
|
||||
from services.db_context import db
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from tortoise import fields
|
||||
from tortoise.contrib.postgres.functions import Random
|
||||
|
||||
from services.db_context import Model
|
||||
|
||||
|
||||
class Pixiv(db.Model):
|
||||
__tablename__ = "pixiv"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
class Pixiv(Model):
|
||||
|
||||
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)
|
||||
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
||||
"""自增id"""
|
||||
pid = fields.BigIntField()
|
||||
"""pid"""
|
||||
uid = fields.BigIntField()
|
||||
"""uid"""
|
||||
author = fields.CharField(255)
|
||||
"""作者"""
|
||||
title = fields.CharField(255)
|
||||
"""标题"""
|
||||
width = fields.IntField()
|
||||
"""宽度"""
|
||||
height = fields.IntField()
|
||||
"""高度"""
|
||||
view = fields.IntField()
|
||||
"""pixiv查看数"""
|
||||
bookmarks = fields.IntField()
|
||||
"""收藏数"""
|
||||
tags = fields.TextField()
|
||||
"""tags"""
|
||||
img_url = fields.CharField(255)
|
||||
"""pixiv url链接"""
|
||||
img_p = fields.CharField(255)
|
||||
"""图片pN"""
|
||||
is_r18 = fields.BooleanField()
|
||||
|
||||
_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))
|
||||
class Meta:
|
||||
table = "pixiv"
|
||||
table_description = "pix图库数据表"
|
||||
unique_together = ("pid", "img_url", "img_p")
|
||||
|
||||
# 0:非r18 1:r18 2:混合
|
||||
@classmethod
|
||||
@@ -109,7 +47,7 @@ class Pixiv(db.Model):
|
||||
uid: Optional[int] = None,
|
||||
pid: Optional[int] = None,
|
||||
r18: Optional[int] = 0,
|
||||
num: int = 100
|
||||
num: int = 100,
|
||||
) -> List[Optional["Pixiv"]]:
|
||||
"""
|
||||
说明:
|
||||
@@ -121,50 +59,37 @@ class Pixiv(db.Model):
|
||||
:param r18: 是否r18,0:非r18 1:r18 2:混合
|
||||
:param num: 查找图片的数量
|
||||
"""
|
||||
if not num:
|
||||
return []
|
||||
query = cls
|
||||
if r18 == 0:
|
||||
query = cls.query.where(cls.is_r18 == False)
|
||||
query = query.filter(is_r18=False)
|
||||
elif r18 == 1:
|
||||
query = cls.query.where(cls.is_r18 == True)
|
||||
else:
|
||||
query = cls.query
|
||||
query = query.filter(is_r18=True)
|
||||
if keywords:
|
||||
for keyword in keywords:
|
||||
query = query.where(cls.tags.contains(keyword))
|
||||
query = query.filter(tags__contains=keyword)
|
||||
elif uid:
|
||||
query = query.where(cls.uid == uid)
|
||||
query = query.filter(uid=uid)
|
||||
elif pid:
|
||||
query = query.where(cls.pid == pid)
|
||||
query = query.order_by(db.func.random()).limit(num)
|
||||
return await query.gino.all()
|
||||
query = query.filter(pid=pid)
|
||||
query = query.annotate(rand=Random()).limit(num)
|
||||
return await query.all() # type: ignore
|
||||
|
||||
@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":
|
||||
async def get_keyword_num(cls, tags: Optional[List[str]] = None) -> Tuple[int, int]:
|
||||
"""
|
||||
说明:
|
||||
获取相关关键词(keyword, tag)在图库中的数量
|
||||
参数:
|
||||
:param tags: 关键词/Tag
|
||||
"""
|
||||
setattr(Pixiv, 'count', db.func.count(cls.pid).label('count'))
|
||||
query = cls.select('count')
|
||||
query = cls
|
||||
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]
|
||||
|
||||
query = query.filter(tags__contains=tag)
|
||||
else:
|
||||
query = query.all()
|
||||
count = await query.filter(is_r18=False).count()
|
||||
r18_count = await query.filter(is_r18=True).count()
|
||||
return count, r18_count
|
||||
|
||||
@@ -1,101 +1,42 @@
|
||||
from services.db_context import db
|
||||
from typing import Set, List
|
||||
from typing import List, Set, Tuple
|
||||
|
||||
from tortoise import fields
|
||||
|
||||
from services.db_context import Model
|
||||
|
||||
|
||||
class PixivKeywordUser(db.Model):
|
||||
class PixivKeywordUser(Model):
|
||||
__tablename__ = "pixiv_keyword_users"
|
||||
__table_args__ = {'extend_existing': True}
|
||||
__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)
|
||||
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
||||
"""自增id"""
|
||||
user_qq = fields.BigIntField()
|
||||
"""用户id"""
|
||||
group_id = fields.BigIntField()
|
||||
"""群聊id"""
|
||||
keyword = fields.CharField(255, unique=True)
|
||||
"""关键词"""
|
||||
is_pass = fields.BooleanField()
|
||||
"""是否通过"""
|
||||
|
||||
_idx1 = db.Index("pixiv_keyword_users_idx1", "keyword", unique=True)
|
||||
class Meta:
|
||||
table = "pixiv_keyword_users"
|
||||
table_description = "pixiv关键词数据表"
|
||||
|
||||
@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]":
|
||||
async def get_current_keyword(cls) -> Tuple[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)
|
||||
for data in await cls.all().values_list("keyword", "is_pass"):
|
||||
if data[1]:
|
||||
pass_keyword.append(data[0])
|
||||
else:
|
||||
not_pass_keyword.append(user.keyword)
|
||||
not_pass_keyword.append(data[0])
|
||||
return pass_keyword, not_pass_keyword
|
||||
|
||||
@classmethod
|
||||
@@ -105,23 +46,9 @@ class PixivKeywordUser(db.Model):
|
||||
获取黑名单PID
|
||||
"""
|
||||
black_pid = []
|
||||
query = await cls.query.where(cls.user_qq == 114514).gino.all()
|
||||
for image in query:
|
||||
black_pid.append(image.keyword[6:])
|
||||
keyword_list = await cls.filter(user_qq=114514).values_list(
|
||||
"keyword", flat=True
|
||||
)
|
||||
for image in keyword_list:
|
||||
black_pid.append(image[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,14 +1,17 @@
|
||||
from nonebot import on_command
|
||||
from utils.utils import is_number
|
||||
from services.log import logger
|
||||
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 import on_command
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message, MessageEvent
|
||||
from nonebot.params import Command, CommandArg
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from services.log import logger
|
||||
from utils.utils import is_number
|
||||
|
||||
from ._data_source import uid_pid_exists
|
||||
from ._model.pixiv import Pixiv
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
|
||||
__zx_plugin_name__ = "PIX关键词/UID/PID添加管理 [Superuser]"
|
||||
__plugin_usage__ = """
|
||||
usage:
|
||||
@@ -46,9 +49,16 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
group_id = event.group_id
|
||||
if msg:
|
||||
if await PixivKeywordUser.add_keyword(
|
||||
event.user_id, group_id, msg, bot.config.superusers
|
||||
):
|
||||
# if await PixivKeywordUser.add_keyword(
|
||||
# event.user_id, group_id, msg, bot.config.superusers
|
||||
# ):
|
||||
if not await PixivKeywordUser.exists(keyword=msg):
|
||||
await PixivKeywordUser.create(
|
||||
user_qq=event.user_id,
|
||||
group_id=group_id,
|
||||
keyword=msg,
|
||||
is_pass=str(event.user_id) in bot.config.superusers,
|
||||
)
|
||||
await add_keyword.send(
|
||||
f"已成功添加pixiv搜图关键词:{msg},请等待管理员通过该关键词!", at_sender=True
|
||||
)
|
||||
@@ -63,7 +73,12 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
|
||||
|
||||
@add_uid_pid.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message = CommandArg()):
|
||||
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:
|
||||
@@ -77,16 +92,23 @@ async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg
|
||||
msg = f"uid:{msg}"
|
||||
else:
|
||||
msg = f"pid:{msg}"
|
||||
if await Pixiv.check_exists(int(msg[4:]), "p0"):
|
||||
if await Pixiv.get_or_none(pid=int(msg[4:]), img_p="p0"):
|
||||
await add_uid_pid.finish(f"该PID:{msg[4:]}已存在...", at_sender=True)
|
||||
if not await uid_pid_exists(msg) and exists_flag:
|
||||
await add_uid_pid.finish("画师或作品不存在或搜索正在CD,请稍等...", at_sender=True)
|
||||
group_id = -1
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
group_id = event.group_id
|
||||
if await PixivKeywordUser.add_keyword(
|
||||
event.user_id, group_id, msg, bot.config.superusers
|
||||
):
|
||||
# if await PixivKeywordUser.add_keyword(
|
||||
# event.user_id, group_id, msg, bot.config.superusers
|
||||
# ):
|
||||
if not await PixivKeywordUser.exists(keyword=msg):
|
||||
await PixivKeywordUser.create(
|
||||
user_qq=event.user_id,
|
||||
group_id=group_id,
|
||||
keyword=msg,
|
||||
is_pass=str(event.user_id) in bot.config.superusers,
|
||||
)
|
||||
await add_uid_pid.send(
|
||||
f"已成功添加pixiv搜图UID/PID:{msg[4:]},请等待管理员通过!", at_sender=True
|
||||
)
|
||||
@@ -106,12 +128,21 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
pid = pid[: pid.find("p")]
|
||||
if not is_number(pid):
|
||||
await add_black_pid.finish("PID必须全部是数字!", at_sender=True)
|
||||
if await PixivKeywordUser.add_keyword(
|
||||
114514,
|
||||
114514,
|
||||
f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
bot.config.superusers,
|
||||
# if await PixivKeywordUser.add_keyword(
|
||||
# 114514,
|
||||
# 114514,
|
||||
# f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
# bot.config.superusers,
|
||||
# ):
|
||||
if not await PixivKeywordUser.exists(
|
||||
keyword=f"black:{pid}{f'_p{img_p}' if img_p else ''}"
|
||||
):
|
||||
await PixivKeywordUser.create(
|
||||
user_qq=114514,
|
||||
group_id=114514,
|
||||
keyword=f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
is_pass=str(event.user_id) in bot.config.superusers,
|
||||
)
|
||||
await add_black_pid.send(f"已添加PID:{pid} 至黑名单中...")
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
from nonebot import on_command
|
||||
from utils.utils import is_number
|
||||
from utils.message_builder import at
|
||||
from services.log import logger
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg, Command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from ._data_source import remove_image
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
from ._model.pixiv import Pixiv
|
||||
from typing import Tuple
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message, MessageEvent
|
||||
from nonebot.params import Command, CommandArg
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from services.log import logger
|
||||
from utils.message_builder import at
|
||||
from utils.utils import is_number
|
||||
|
||||
from ._data_source import remove_image
|
||||
from ._model.pixiv import Pixiv
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
|
||||
__zx_plugin_name__ = "PIX关键词/UID/PID删除管理 [Superuser]"
|
||||
__plugin_usage__ = """
|
||||
@@ -60,7 +62,8 @@ async def _(event: MessageEvent, arg: Message = CommandArg()):
|
||||
msg = f"uid:{msg}"
|
||||
if msg.lower().startswith("pid"):
|
||||
msg = "pid:" + msg.replace("pid", "").replace(":", "")
|
||||
if await PixivKeywordUser.delete_keyword(msg):
|
||||
if data := await PixivKeywordUser.get_or_none(keyword=msg):
|
||||
await data.delete()
|
||||
await del_keyword.send(f"删除搜图关键词/UID:{msg} 成功...")
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
@@ -97,22 +100,31 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
if await remove_image(int(pid), img_p):
|
||||
msg += f'{pid}{f"_p{img_p}" if img_p else ""},'
|
||||
if flag:
|
||||
if await PixivKeywordUser.add_keyword(
|
||||
114514,
|
||||
114514,
|
||||
f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
bot.config.superusers,
|
||||
# if await PixivKeywordUser.add_keyword(
|
||||
# 114514,
|
||||
# 114514,
|
||||
# f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
# bot.config.superusers,
|
||||
# ):
|
||||
if await PixivKeywordUser.exists(
|
||||
keyword=f"black:{pid}{f'_p{img_p}' if img_p else ''}"
|
||||
):
|
||||
await PixivKeywordUser.create(
|
||||
user_qq=114514,
|
||||
group_id=114514,
|
||||
keyword=f"black:{pid}{f'_p{img_p}' if img_p else ''}",
|
||||
is_pass=False,
|
||||
)
|
||||
black_pid += f'{pid}{f"_p{img_p}" if img_p else ""},'
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 删除了PIX图片 PID:{pid}{f'_p{img_p}' if img_p else ''}"
|
||||
)
|
||||
else:
|
||||
await del_pic.send(
|
||||
f"PIX:删除pid:{pid}{f'_p{img_p}' if img_p else ''} 失败.."
|
||||
)
|
||||
# else:
|
||||
# await del_pic.send(
|
||||
# f"PIX:删除pid:{pid}{f'_p{img_p}' if img_p else ''} 失败.."
|
||||
# )
|
||||
else:
|
||||
await del_pic.send(
|
||||
f"PIX:图片pix:{pid}{f'_p{img_p}' if img_p else ''} 不存在...无法删除.."
|
||||
@@ -127,7 +139,12 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
|
||||
|
||||
@pass_keyword.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message = CommandArg()):
|
||||
async def _(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
cmd: Tuple[str, ...] = Command(),
|
||||
arg: Message = CommandArg(),
|
||||
):
|
||||
tmp = {"group": {}, "private": {}}
|
||||
msg = arg.extract_plain_text().strip()
|
||||
if not msg:
|
||||
@@ -145,7 +162,13 @@ async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg
|
||||
if not is_number(x[4:]):
|
||||
await pass_keyword.send(f"UID/PID:{x} 非全数字,跳过该关键词...")
|
||||
continue
|
||||
user_id, group_id = await PixivKeywordUser.set_keyword_pass(x, flag)
|
||||
data = await PixivKeywordUser.get_or_none(keyword=x)
|
||||
user_id = 0
|
||||
group_id = 0
|
||||
if data:
|
||||
data.is_pass = flag
|
||||
await data.save(update_fields=["is_pass"])
|
||||
user_id, group_id = data.user_qq, data.group_id
|
||||
if not user_id:
|
||||
await pass_keyword.send(f"未找到关键词/UID:{x},请检查关键词/UID是否存在...")
|
||||
continue
|
||||
@@ -163,7 +186,7 @@ async def _(bot: Bot, event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg
|
||||
else:
|
||||
tmp["group"][group_id][user_id]["keyword"].append(x)
|
||||
msg = " ".join(msg)
|
||||
await pass_keyword.send(f'已成功{cmd[0][: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,11 +1,13 @@
|
||||
from nonebot import on_command
|
||||
from utils.message_builder import image
|
||||
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
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent
|
||||
from nonebot.params import CommandArg
|
||||
|
||||
from utils.message_builder import image
|
||||
|
||||
from ._data_source import gen_keyword_pic, get_keyword_num
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
|
||||
__zx_plugin_name__ = "查看pix图库"
|
||||
__plugin_usage__ = """
|
||||
@@ -35,12 +37,12 @@ show_pix = on_command("查看pix图库", priority=1, block=True)
|
||||
|
||||
@my_keyword.handle()
|
||||
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)
|
||||
await my_keyword.send(
|
||||
f"您目前提供的如下关键字:\n\t" + ",".join(data[event.user_id]["keyword"])
|
||||
data = await PixivKeywordUser.filter(user_qq=event.user_id).values_list(
|
||||
"keyword", flat=True
|
||||
)
|
||||
if not data:
|
||||
await my_keyword.finish("您目前没有提供任何Pixiv搜图关键字...", at_sender=True)
|
||||
await my_keyword.send(f"您目前提供的如下关键字:\n\t" + ",".join(data))
|
||||
|
||||
|
||||
@show_keyword.handle()
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import re
|
||||
|
||||
from nonebot import on_command
|
||||
from utils.utils import is_number
|
||||
from nonebot.permission import SUPERUSER
|
||||
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
|
||||
from typing import List
|
||||
import asyncio
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.onebot.v11 import Message
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from services.log import logger
|
||||
from utils.utils import is_number
|
||||
|
||||
from ._data_source import start_update_image_url
|
||||
from ._model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from ._model.pixiv import Pixiv
|
||||
from ._model.pixiv_keyword_user import PixivKeywordUser
|
||||
|
||||
__zx_plugin_name__ = "pix检查更新 [Superuser]"
|
||||
__plugin_usage__ = """
|
||||
@@ -146,11 +147,11 @@ async def _(arg: Message = CommandArg()):
|
||||
async def _():
|
||||
async def _tasks(line: str, all_pid: List[int], length: int, index: int):
|
||||
data = line.split("VALUES", maxsplit=1)[-1].strip()[1:-2]
|
||||
num_list = re.findall(r'(\d+)', data)
|
||||
num_list = re.findall(r"(\d+)", data)
|
||||
pid = int(num_list[1])
|
||||
uid = int(num_list[2])
|
||||
id_ = 3
|
||||
while num_list[id_] not in ['0', '1']:
|
||||
while num_list[id_] not in ["0", "1"]:
|
||||
id_ += 1
|
||||
classified = int(num_list[id_])
|
||||
nsfw_tag = int(num_list[id_ + 1])
|
||||
@@ -164,23 +165,25 @@ async def _():
|
||||
if pid in all_pid:
|
||||
logger.info(f"添加OmegaPixivIllusts图库数据已存在 ---> pid:{pid}")
|
||||
return
|
||||
if await OmegaPixivIllusts.add_image_data(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
url=url,
|
||||
uid=uid,
|
||||
nsfw_tag=nsfw_tag,
|
||||
tags=tags,
|
||||
uname=uname,
|
||||
classified=classified
|
||||
):
|
||||
_, is_create = await OmegaPixivIllusts.get_or_create(
|
||||
pid=pid,
|
||||
title=title,
|
||||
width=width,
|
||||
height=height,
|
||||
url=url,
|
||||
uid=uid,
|
||||
nsfw_tag=nsfw_tag,
|
||||
tags=tags,
|
||||
uname=uname,
|
||||
classified=classified,
|
||||
)
|
||||
if is_create:
|
||||
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_artwork" in file and ".sql" in file:
|
||||
@@ -190,13 +193,13 @@ async def _():
|
||||
lines = f.readlines()
|
||||
tasks = []
|
||||
length = len([x for x in lines if "INSERT INTO" in x.upper()])
|
||||
all_pid = await OmegaPixivIllusts.get_all_pid()
|
||||
all_pid = await OmegaPixivIllusts.all().values_list("pid", flat=True)
|
||||
index = 0
|
||||
logger.info("检测到OmegaPixivIllusts数据库,准备开始更新....")
|
||||
for line in lines:
|
||||
if "INSERT INTO" in line.upper():
|
||||
index += 1
|
||||
logger.info(f'line: {line} 加入更新计划')
|
||||
logger.info(f"line: {line} 加入更新计划")
|
||||
tasks.append(
|
||||
asyncio.ensure_future(_tasks(line, all_pid, length, index))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user