mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 13:42:56 +08:00
🚨 Add specific ignore items in pyright ignore
🚨 Make pyright happy ♻️ Remove unused adapter
This commit is contained in:
parent
e814469b75
commit
ccee16bed2
8
bot.py
8
bot.py
@ -1,8 +1,8 @@
|
|||||||
import nonebot
|
import nonebot
|
||||||
|
|
||||||
# from nonebot.adapters.discord import Adapter as DiscordAdapter
|
# from nonebot.adapters.discord import Adapter as DiscordAdapter
|
||||||
from nonebot.adapters.dodo import Adapter as DoDoAdapter
|
# from nonebot.adapters.dodo import Adapter as DoDoAdapter
|
||||||
from nonebot.adapters.kaiheila import Adapter as KaiheilaAdapter
|
# from nonebot.adapters.kaiheila import Adapter as KaiheilaAdapter
|
||||||
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
|
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
|
||||||
|
|
||||||
nonebot.init()
|
nonebot.init()
|
||||||
@ -10,8 +10,8 @@ nonebot.init()
|
|||||||
|
|
||||||
driver = nonebot.get_driver()
|
driver = nonebot.get_driver()
|
||||||
driver.register_adapter(OneBotV11Adapter)
|
driver.register_adapter(OneBotV11Adapter)
|
||||||
driver.register_adapter(KaiheilaAdapter)
|
# driver.register_adapter(KaiheilaAdapter)
|
||||||
driver.register_adapter(DoDoAdapter)
|
# driver.register_adapter(DoDoAdapter)
|
||||||
# driver.register_adapter(DiscordAdapter)
|
# driver.register_adapter(DiscordAdapter)
|
||||||
|
|
||||||
from zhenxun.services.db_context import disconnect, init
|
from zhenxun.services.db_context import disconnect, init
|
||||||
|
|||||||
@ -68,8 +68,8 @@ plugins = [
|
|||||||
plugin_dirs = ["zhenxun/services", "zhenxun/builtin_plugins", "zhenxun/plugins"]
|
plugin_dirs = ["zhenxun/services", "zhenxun/builtin_plugins", "zhenxun/plugins"]
|
||||||
adapters = [
|
adapters = [
|
||||||
{ name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" },
|
{ name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" },
|
||||||
{ name = "DoDo", module_name = "nonebot.adapters.dodo" },
|
# { name = "DoDo", module_name = "nonebot.adapters.dodo" },
|
||||||
{ name = "开黑啦", module_name = "nonebot.adapters.kaiheila" },
|
# { name = "开黑啦", module_name = "nonebot.adapters.kaiheila" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
|
|||||||
@ -3,10 +3,6 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import nonebot
|
import nonebot
|
||||||
|
|
||||||
# from nonebot.adapters.discord import Adapter as DiscordAdapter
|
|
||||||
from nonebot.adapters.dodo import Adapter as DoDoAdapter
|
|
||||||
from nonebot.adapters.kaiheila import Adapter as KaiheilaAdapter
|
|
||||||
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
|
from nonebot.adapters.onebot.v11 import Adapter as OneBotV11Adapter
|
||||||
from nonebot.log import logger
|
from nonebot.log import logger
|
||||||
|
|
||||||
@ -17,8 +13,6 @@ from zhenxun.services.db_context import disconnect, init
|
|||||||
driver = nonebot.get_driver()
|
driver = nonebot.get_driver()
|
||||||
|
|
||||||
driver.register_adapter(OneBotV11Adapter)
|
driver.register_adapter(OneBotV11Adapter)
|
||||||
driver.register_adapter(KaiheilaAdapter)
|
|
||||||
driver.register_adapter(DoDoAdapter)
|
|
||||||
|
|
||||||
|
|
||||||
driver.on_startup(init)
|
driver.on_startup(init)
|
||||||
|
|||||||
@ -206,6 +206,8 @@ class Manager:
|
|||||||
返回:
|
返回:
|
||||||
list: 消息内容
|
list: 消息内容
|
||||||
"""
|
"""
|
||||||
|
if not session.group:
|
||||||
|
return None
|
||||||
json_data = cls.__get_data(session)
|
json_data = cls.__get_data(session)
|
||||||
if not json_data:
|
if not json_data:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@ -23,7 +23,7 @@ ARM_KEY = "aarch64"
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CPUInfo:
|
class CPUInfo:
|
||||||
core: int
|
core: int | None
|
||||||
"""CPU 物理核心数"""
|
"""CPU 物理核心数"""
|
||||||
usage: float
|
usage: float
|
||||||
"""CPU 占用百分比,取值范围(0,100]"""
|
"""CPU 占用百分比,取值范围(0,100]"""
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
from nonebot.adapters import Bot, Event
|
from nonebot.adapters import Bot, Event
|
||||||
from nonebot.adapters.onebot.v11 import PokeNotifyEvent
|
from nonebot.adapters.onebot.v11 import PokeNotifyEvent
|
||||||
from nonebot.exception import IgnoredException
|
from nonebot.exception import IgnoredException
|
||||||
@ -38,11 +40,11 @@ class Limit(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class LimitManage:
|
class LimitManage:
|
||||||
add_module = [] # noqa: RUF012
|
add_module: ClassVar[list] = []
|
||||||
|
|
||||||
cd_limit: dict[str, Limit] = {} # noqa: RUF012
|
cd_limit: ClassVar[dict[str, Limit]] = {}
|
||||||
block_limit: dict[str, Limit] = {} # noqa: RUF012
|
block_limit: ClassVar[dict[str, Limit]] = {}
|
||||||
count_limit: dict[str, Limit] = {} # noqa: RUF012
|
count_limit: ClassVar[dict[str, Limit]] = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_limit(cls, limit: PluginLimit):
|
def add_limit(cls, limit: PluginLimit):
|
||||||
|
|||||||
@ -16,7 +16,9 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from nonebot.adapters.qq import Bot # noqa: F401
|
from nonebot.adapters.qq import ( # noqa: F401 # pyright: ignore [reportMissingImports]
|
||||||
|
Bot,
|
||||||
|
)
|
||||||
|
|
||||||
nonebot.load_plugins(str((path / "qq_api").resolve()))
|
nonebot.load_plugins(str((path / "qq_api").resolve()))
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class SqlLog(Model):
|
|||||||
create_time = fields.DatetimeField(auto_now_add=True)
|
create_time = fields.DatetimeField(auto_now_add=True)
|
||||||
"""创建时间"""
|
"""创建时间"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "sql_log"
|
table = "sql_log"
|
||||||
table_description = "sql执行日志"
|
table_description = "sql执行日志"
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
from collections import defaultdict
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import copy
|
import copy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -95,7 +96,7 @@ class ConfigGroup(BaseModel):
|
|||||||
"""模块名"""
|
"""模块名"""
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
"""插件名"""
|
"""插件名"""
|
||||||
configs: dict[str, ConfigModel] = {}
|
configs: dict[str, ConfigModel] = defaultdict()
|
||||||
"""配置项列表"""
|
"""配置项列表"""
|
||||||
|
|
||||||
def get(self, c: str, default: Any = None) -> Any:
|
def get(self, c: str, default: Any = None) -> Any:
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class BagUser(Model):
|
|||||||
property: dict[str, int] = fields.JSONField(default={}) # type: ignore
|
property: dict[str, int] = fields.JSONField(default={}) # type: ignore
|
||||||
"""道具"""
|
"""道具"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "bag_users"
|
table = "bag_users"
|
||||||
table_description = "用户道具数据表"
|
table_description = "用户道具数据表"
|
||||||
unique_together = ("user_id", "group_id")
|
unique_together = ("user_id", "group_id")
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class BanConsole(Model):
|
|||||||
operator = fields.CharField(255)
|
operator = fields.CharField(255)
|
||||||
"""使用Ban命令的用户"""
|
"""使用Ban命令的用户"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "ban_console"
|
table = "ban_console"
|
||||||
table_description = "封禁人员/群组数据表"
|
table_description = "封禁人员/群组数据表"
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,6 @@ class BotConnectLog(Model):
|
|||||||
create_time = fields.DatetimeField(auto_now_add=True)
|
create_time = fields.DatetimeField(auto_now_add=True)
|
||||||
"""创建时间"""
|
"""创建时间"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "bot_connect_log"
|
table = "bot_connect_log"
|
||||||
table_description = "bot连接表"
|
table_description = "bot连接表"
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class BotConsole(Model):
|
|||||||
available_tasks = fields.TextField(default="", description="可用被动技能")
|
available_tasks = fields.TextField(default="", description="可用被动技能")
|
||||||
"""可用被动技能"""
|
"""可用被动技能"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "bot_console"
|
table = "bot_console"
|
||||||
table_description = "Bot数据表"
|
table_description = "Bot数据表"
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class ChatHistory(Model):
|
|||||||
platform = fields.CharField(255, null=True)
|
platform = fields.CharField(255, null=True)
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "chat_history"
|
table = "chat_history"
|
||||||
table_description = "聊天记录数据表"
|
table_description = "聊天记录数据表"
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class FgRequest(Model):
|
|||||||
)
|
)
|
||||||
"""处理类型"""
|
"""处理类型"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "fg_request"
|
table = "fg_request"
|
||||||
table_description = "好友群组请求"
|
table_description = "好友群组请求"
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class FriendUser(Model):
|
|||||||
platform = fields.CharField(255, null=True, description="平台")
|
platform = fields.CharField(255, null=True, description="平台")
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "friend_users"
|
table = "friend_users"
|
||||||
table_description = "好友信息数据表"
|
table_description = "好友信息数据表"
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class GoodsInfo(Model):
|
|||||||
icon = fields.TextField(null=True)
|
icon = fields.TextField(null=True)
|
||||||
"""图标路径"""
|
"""图标路径"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "goods_info"
|
table = "goods_info"
|
||||||
table_description = "商品数据表"
|
table_description = "商品数据表"
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ class GroupConsole(Model):
|
|||||||
platform = fields.CharField(255, default="qq", description="所属平台")
|
platform = fields.CharField(255, default="qq", description="所属平台")
|
||||||
"""所属平台"""
|
"""所属平台"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "group_console"
|
table = "group_console"
|
||||||
table_description = "群组信息表"
|
table_description = "群组信息表"
|
||||||
unique_together = ("group_id", "channel_id")
|
unique_together = ("group_id", "channel_id")
|
||||||
|
|||||||
@ -23,7 +23,7 @@ class GroupInfo(Model):
|
|||||||
platform = fields.CharField(255, default="qq", description="所属平台")
|
platform = fields.CharField(255, default="qq", description="所属平台")
|
||||||
"""所属平台"""
|
"""所属平台"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "group_info"
|
table = "group_info"
|
||||||
table_description = "群聊信息表"
|
table_description = "群聊信息表"
|
||||||
|
|
||||||
@ -75,8 +75,8 @@ class GroupInfo(Model):
|
|||||||
group_id=group_id, defaults={"platform": platform}
|
group_id=group_id, defaults={"platform": platform}
|
||||||
)
|
)
|
||||||
if is_superuser:
|
if is_superuser:
|
||||||
if "module," not in group.superuser_block_plugin:
|
if "module," not in group.superuser_block_plugin: # type: ignore
|
||||||
group.superuser_block_plugin += f"{module},"
|
group.superuser_block_plugin += f"{module}," # type: ignore
|
||||||
elif "module," not in group.block_plugin:
|
elif "module," not in group.block_plugin:
|
||||||
group.block_plugin += f"{module},"
|
group.block_plugin += f"{module},"
|
||||||
await group.save(update_fields=["block_plugin", "superuser_block_plugin"])
|
await group.save(update_fields=["block_plugin", "superuser_block_plugin"])
|
||||||
@ -99,8 +99,8 @@ class GroupInfo(Model):
|
|||||||
group_id=group_id, defaults={"platform": platform}
|
group_id=group_id, defaults={"platform": platform}
|
||||||
)
|
)
|
||||||
if is_superuser:
|
if is_superuser:
|
||||||
if "module," in group.superuser_block_plugin:
|
if "module," in group.superuser_block_plugin: # type: ignore
|
||||||
group.superuser_block_plugin = group.superuser_block_plugin.replace(
|
group.superuser_block_plugin = group.superuser_block_plugin.replace( # type: ignore
|
||||||
f"{module},", ""
|
f"{module},", ""
|
||||||
)
|
)
|
||||||
elif "module," in group.block_plugin:
|
elif "module," in group.block_plugin:
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class GroupInfoUser(Model):
|
|||||||
platform = fields.CharField(255, null=True, description="平台")
|
platform = fields.CharField(255, null=True, description="平台")
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "group_info_users"
|
table = "group_info_users"
|
||||||
table_description = "群员信息数据表"
|
table_description = "群员信息数据表"
|
||||||
unique_together = ("user_id", "group_id")
|
unique_together = ("user_id", "group_id")
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class LevelUser(Model):
|
|||||||
group_flag = fields.IntField(default=0)
|
group_flag = fields.IntField(default=0)
|
||||||
"""特殊标记,是否随群管理员变更而设置权限"""
|
"""特殊标记,是否随群管理员变更而设置权限"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "level_users"
|
table = "level_users"
|
||||||
table_description = "用户权限数据库"
|
table_description = "用户权限数据库"
|
||||||
unique_together = ("user_id", "group_id")
|
unique_together = ("user_id", "group_id")
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class PluginInfo(Model):
|
|||||||
is_show = fields.BooleanField(default=True, description="是否显示在帮助中")
|
is_show = fields.BooleanField(default=True, description="是否显示在帮助中")
|
||||||
"""是否显示在帮助中"""
|
"""是否显示在帮助中"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "plugin_info"
|
table = "plugin_info"
|
||||||
table_description = "插件基本信息"
|
table_description = "插件基本信息"
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,6 @@ class PluginLimit(Model):
|
|||||||
max_count = fields.IntField(null=True, description="最大调用次数")
|
max_count = fields.IntField(null=True, description="最大调用次数")
|
||||||
"""最大调用次数"""
|
"""最大调用次数"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "plugin_limit"
|
table = "plugin_limit"
|
||||||
table_description = "插件限制"
|
table_description = "插件限制"
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class SignGroupUser(Model):
|
|||||||
"""使用指定双倍概率"""
|
"""使用指定双倍概率"""
|
||||||
# specify_probability = fields.DecimalField(10, 3, default=0)
|
# specify_probability = fields.DecimalField(10, 3, default=0)
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "sign_group_users"
|
table = "sign_group_users"
|
||||||
table_description = "群员签到数据表"
|
table_description = "群员签到数据表"
|
||||||
unique_together = ("user_id", "group_id")
|
unique_together = ("user_id", "group_id")
|
||||||
|
|||||||
@ -17,6 +17,6 @@ class SignLog(Model):
|
|||||||
platform = fields.CharField(255, null=True, description="平台")
|
platform = fields.CharField(255, null=True, description="平台")
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "sign_log"
|
table = "sign_log"
|
||||||
table_description = "用户签到记录表"
|
table_description = "用户签到记录表"
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class SignUser(Model):
|
|||||||
platform = fields.CharField(255, null=True, description="平台")
|
platform = fields.CharField(255, null=True, description="平台")
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "sign_users"
|
table = "sign_users"
|
||||||
table_description = "用户签到数据表"
|
table_description = "用户签到数据表"
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class Statistics(Model):
|
|||||||
bot_id = fields.CharField(255, null=True)
|
bot_id = fields.CharField(255, null=True)
|
||||||
"""Bot Id"""
|
"""Bot Id"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "statistics"
|
table = "statistics"
|
||||||
table_description = "插件调用统计数据库"
|
table_description = "插件调用统计数据库"
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class TaskInfo(Model):
|
|||||||
run_count = fields.IntField(default=0, description="运行次数")
|
run_count = fields.IntField(default=0, description="运行次数")
|
||||||
"""运行次数"""
|
"""运行次数"""
|
||||||
|
|
||||||
class Meta: # type: ignore
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "task_info"
|
table = "task_info"
|
||||||
table_description = "被动技能基本信息"
|
table_description = "被动技能基本信息"
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class UserConsole(Model):
|
|||||||
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
||||||
"""创建时间"""
|
"""创建时间"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "user_console"
|
table = "user_console"
|
||||||
table_description = "用户数据表"
|
table_description = "用户数据表"
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,6 @@ class UserGoldLog(Model):
|
|||||||
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
||||||
"""创建时间"""
|
"""创建时间"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "user_gold_log"
|
table = "user_gold_log"
|
||||||
table_description = "用户金币记录表"
|
table_description = "用户金币记录表"
|
||||||
|
|||||||
@ -15,6 +15,6 @@ class UserProps(Model):
|
|||||||
platform = fields.CharField(255, null=True)
|
platform = fields.CharField(255, null=True)
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "user_props"
|
table = "user_props"
|
||||||
table_description = "用户道具表"
|
table_description = "用户道具表"
|
||||||
|
|||||||
@ -20,6 +20,6 @@ class UserPropsLog(Model):
|
|||||||
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
||||||
"""创建时间"""
|
"""创建时间"""
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "user_props_log"
|
table = "user_props_log"
|
||||||
table_description = "用户道具记录表"
|
table_description = "用户道具记录表"
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import uuid
|
|||||||
from nonebot.utils import run_sync
|
from nonebot.utils import run_sync
|
||||||
from PIL import Image, ImageDraw, ImageFilter, ImageFont
|
from PIL import Image, ImageDraw, ImageFilter, ImageFont
|
||||||
from PIL.Image import Image as tImage
|
from PIL.Image import Image as tImage
|
||||||
|
from PIL.Image import Resampling, Transpose
|
||||||
from PIL.ImageFont import FreeTypeFont
|
from PIL.ImageFont import FreeTypeFont
|
||||||
|
|
||||||
from zhenxun.configs.path_config import FONT_PATH
|
from zhenxun.configs.path_config import FONT_PATH
|
||||||
@ -62,7 +63,7 @@ class BuildImage:
|
|||||||
else:
|
else:
|
||||||
self.markImg = Image.open(background)
|
self.markImg = Image.open(background)
|
||||||
if width and height:
|
if width and height:
|
||||||
self.markImg = self.markImg.resize((width, height), Image.LANCZOS)
|
self.markImg = self.markImg.resize((width, height), Resampling.LANCZOS)
|
||||||
else:
|
else:
|
||||||
self.width = self.markImg.width
|
self.width = self.markImg.width
|
||||||
self.height = self.markImg.height
|
self.height = self.markImg.height
|
||||||
@ -487,7 +488,7 @@ class BuildImage:
|
|||||||
x, y = self.markImg.size
|
x, y = self.markImg.size
|
||||||
for i, k in itertools.product(range(n, x - n), range(n, y - n)):
|
for i, k in itertools.product(range(n, x - n), range(n, y - n)):
|
||||||
color = self.markImg.getpixel((i, k))
|
color = self.markImg.getpixel((i, k))
|
||||||
color = color[:-1] + (int(100 * alpha_ratio),)
|
color = color[:-1] + (int(100 * alpha_ratio),) # type: ignore
|
||||||
self.markImg.putpixel((i, k), color)
|
self.markImg.putpixel((i, k), color)
|
||||||
self.draw = ImageDraw.Draw(self.markImg)
|
self.draw = ImageDraw.Draw(self.markImg)
|
||||||
return self
|
return self
|
||||||
@ -623,7 +624,7 @@ class BuildImage:
|
|||||||
left, top = ((value + offset) * antialias for value in ellipse_box[:2])
|
left, top = ((value + offset) * antialias for value in ellipse_box[:2])
|
||||||
right, bottom = ((value - offset) * antialias for value in ellipse_box[2:])
|
right, bottom = ((value - offset) * antialias for value in ellipse_box[2:])
|
||||||
draw.ellipse([left, top, right, bottom], fill=fill)
|
draw.ellipse([left, top, right, bottom], fill=fill)
|
||||||
mask = mask.resize(self.markImg.size, Image.LANCZOS)
|
mask = mask.resize(self.markImg.size, Resampling.LANCZOS)
|
||||||
with contextlib.suppress(ValueError):
|
with contextlib.suppress(ValueError):
|
||||||
self.markImg.putalpha(mask)
|
self.markImg.putalpha(mask)
|
||||||
return self
|
return self
|
||||||
@ -685,7 +686,7 @@ class BuildImage:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
@run_sync
|
@run_sync
|
||||||
def transpose(self, angle: Literal[0, 1, 2, 3, 4, 5, 6]) -> Self:
|
def transpose(self, angle: Transpose) -> Self:
|
||||||
"""
|
"""
|
||||||
旋转图片(包括边框)
|
旋转图片(包括边框)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user