mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✨ 提供一个插件好感度限制
This commit is contained in:
parent
ee55078b56
commit
fc3d8223c7
@ -15,6 +15,7 @@ from zhenxun.models.group_console import GroupConsole
|
|||||||
from zhenxun.models.level_user import LevelUser
|
from zhenxun.models.level_user import LevelUser
|
||||||
from zhenxun.models.plugin_info import PluginInfo
|
from zhenxun.models.plugin_info import PluginInfo
|
||||||
from zhenxun.models.plugin_limit import PluginLimit
|
from zhenxun.models.plugin_limit import PluginLimit
|
||||||
|
from zhenxun.models.sign_user import SignUser
|
||||||
from zhenxun.models.user_console import UserConsole
|
from zhenxun.models.user_console import UserConsole
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
from zhenxun.utils.enum import (
|
from zhenxun.utils.enum import (
|
||||||
@ -210,7 +211,9 @@ class AuthChecker:
|
|||||||
return False
|
return False
|
||||||
if plugin.plugin_type == PluginType.DEPENDANT:
|
if plugin.plugin_type == PluginType.DEPENDANT:
|
||||||
return False
|
return False
|
||||||
return plugin.module != "ai" if self._flmt_s.check(sid) else False
|
if plugin.ignore_prompt:
|
||||||
|
return False
|
||||||
|
return self._flmt_s.check(sid)
|
||||||
|
|
||||||
async def auth(
|
async def auth(
|
||||||
self,
|
self,
|
||||||
@ -358,14 +361,27 @@ class AuthChecker:
|
|||||||
group_id = channel_id
|
group_id = channel_id
|
||||||
channel_id = None
|
channel_id = None
|
||||||
if user_id := session.id1:
|
if user_id := session.id1:
|
||||||
is_poke = isinstance(event, PokeNotifyEvent)
|
if plugin.impression > 0:
|
||||||
|
sign_user = await SignUser.get_user(user_id)
|
||||||
|
if float(sign_user.impression) < plugin.impression:
|
||||||
|
if self.is_send_limit_message(plugin, user_id):
|
||||||
|
self._flmt_s.start_cd(user_id)
|
||||||
|
await MessageUtils.build_message(
|
||||||
|
"好感度不足哦,请继续签到提升好感度吧..."
|
||||||
|
).send(reply_to=True)
|
||||||
|
logger.debug(
|
||||||
|
f"{plugin.name}({plugin.module}) 用户好感度不足...",
|
||||||
|
"AuthChecker",
|
||||||
|
session=session,
|
||||||
|
)
|
||||||
|
raise IgnoredException("好感度不足...")
|
||||||
if group_id:
|
if group_id:
|
||||||
sid = group_id or user_id
|
sid = group_id or user_id
|
||||||
if await GroupConsole.is_superuser_block_plugin(
|
if await GroupConsole.is_superuser_block_plugin(
|
||||||
group_id, plugin.module
|
group_id, plugin.module
|
||||||
):
|
):
|
||||||
"""超级用户群组插件状态"""
|
"""超级用户群组插件状态"""
|
||||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
if self.is_send_limit_message(plugin, sid):
|
||||||
self._flmt_s.start_cd(group_id or user_id)
|
self._flmt_s.start_cd(group_id or user_id)
|
||||||
await MessageUtils.build_message(
|
await MessageUtils.build_message(
|
||||||
"超级管理员禁用了该群此功能..."
|
"超级管理员禁用了该群此功能..."
|
||||||
@ -378,7 +394,7 @@ class AuthChecker:
|
|||||||
raise IgnoredException("超级管理员禁用了该群此功能...")
|
raise IgnoredException("超级管理员禁用了该群此功能...")
|
||||||
if await GroupConsole.is_normal_block_plugin(group_id, plugin.module):
|
if await GroupConsole.is_normal_block_plugin(group_id, plugin.module):
|
||||||
"""群组插件状态"""
|
"""群组插件状态"""
|
||||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
if self.is_send_limit_message(plugin, sid):
|
||||||
self._flmt_s.start_cd(group_id or user_id)
|
self._flmt_s.start_cd(group_id or user_id)
|
||||||
await MessageUtils.build_message("该群未开启此功能...").send(
|
await MessageUtils.build_message("该群未开启此功能...").send(
|
||||||
reply_to=True
|
reply_to=True
|
||||||
@ -392,7 +408,7 @@ class AuthChecker:
|
|||||||
if plugin.block_type == BlockType.GROUP:
|
if plugin.block_type == BlockType.GROUP:
|
||||||
"""全局群组禁用"""
|
"""全局群组禁用"""
|
||||||
try:
|
try:
|
||||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
if self.is_send_limit_message(plugin, sid):
|
||||||
self._flmt_c.start_cd(group_id)
|
self._flmt_c.start_cd(group_id)
|
||||||
await MessageUtils.build_message(
|
await MessageUtils.build_message(
|
||||||
"该功能在群组中已被禁用..."
|
"该功能在群组中已被禁用..."
|
||||||
@ -415,7 +431,7 @@ class AuthChecker:
|
|||||||
if plugin.block_type == BlockType.PRIVATE:
|
if plugin.block_type == BlockType.PRIVATE:
|
||||||
"""全局私聊禁用"""
|
"""全局私聊禁用"""
|
||||||
try:
|
try:
|
||||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
if self.is_send_limit_message(plugin, sid):
|
||||||
self._flmt_c.start_cd(user_id)
|
self._flmt_c.start_cd(user_id)
|
||||||
await MessageUtils.build_message(
|
await MessageUtils.build_message(
|
||||||
"该功能在私聊中已被禁用..."
|
"该功能在私聊中已被禁用..."
|
||||||
@ -442,7 +458,7 @@ class AuthChecker:
|
|||||||
"AuthChecker",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
if self.is_send_limit_message(plugin, sid):
|
||||||
self._flmt_s.start_cd(group_id or user_id)
|
self._flmt_s.start_cd(group_id or user_id)
|
||||||
await MessageUtils.build_message("全局未开启此功能...").send()
|
await MessageUtils.build_message("全局未开启此功能...").send()
|
||||||
raise IgnoredException("全局未开启此功能...")
|
raise IgnoredException("全局未开启此功能...")
|
||||||
|
|||||||
@ -75,6 +75,7 @@ async def _handle_setting(
|
|||||||
is_show=extra_data.is_show,
|
is_show=extra_data.is_show,
|
||||||
ignore_prompt=extra_data.ignore_prompt,
|
ignore_prompt=extra_data.ignore_prompt,
|
||||||
parent=(plugin.parent_plugin.module_name if plugin.parent_plugin else None),
|
parent=(plugin.parent_plugin.module_name if plugin.parent_plugin else None),
|
||||||
|
impression=setting.impression,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if extra_data.limits:
|
if extra_data.limits:
|
||||||
@ -123,7 +124,6 @@ async def _():
|
|||||||
"admin_level",
|
"admin_level",
|
||||||
"plugin_type",
|
"plugin_type",
|
||||||
"is_show",
|
"is_show",
|
||||||
"ignore_prompt",
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
update_list.append(plugin)
|
update_list.append(plugin)
|
||||||
|
|||||||
@ -166,6 +166,8 @@ class PluginSetting(BaseModel):
|
|||||||
"""是否限制超级用户"""
|
"""是否限制超级用户"""
|
||||||
cost_gold: int = 0
|
cost_gold: int = 0
|
||||||
"""调用插件花费金币"""
|
"""调用插件花费金币"""
|
||||||
|
impression: float = 0.0
|
||||||
|
"""调用插件好感度限制"""
|
||||||
|
|
||||||
|
|
||||||
class SchedulerModel(BaseModel):
|
class SchedulerModel(BaseModel):
|
||||||
|
|||||||
@ -52,6 +52,8 @@ class PluginInfo(Model):
|
|||||||
"""父插件"""
|
"""父插件"""
|
||||||
is_show = fields.BooleanField(default=True, description="是否显示在帮助中")
|
is_show = fields.BooleanField(default=True, description="是否显示在帮助中")
|
||||||
"""是否显示在帮助中"""
|
"""是否显示在帮助中"""
|
||||||
|
impression = fields.FloatField(default=0, description="插件好感度限制")
|
||||||
|
"""插件好感度限制"""
|
||||||
|
|
||||||
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
class Meta: # pyright: ignore [reportIncompatibleVariableOverride]
|
||||||
table = "plugin_info"
|
table = "plugin_info"
|
||||||
@ -87,4 +89,5 @@ class PluginInfo(Model):
|
|||||||
"ALTER TABLE plugin_info ADD COLUMN parent character varying(255);",
|
"ALTER TABLE plugin_info ADD COLUMN parent character varying(255);",
|
||||||
"ALTER TABLE plugin_info ADD COLUMN is_show boolean DEFAULT true;",
|
"ALTER TABLE plugin_info ADD COLUMN is_show boolean DEFAULT true;",
|
||||||
"ALTER TABLE plugin_info ADD COLUMN ignore_prompt boolean DEFAULT false;",
|
"ALTER TABLE plugin_info ADD COLUMN ignore_prompt boolean DEFAULT false;",
|
||||||
|
"ALTER TABLE plugin_info ADD COLUMN impression float DEFAULT 0;",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -36,6 +36,24 @@ class SignUser(Model):
|
|||||||
table = "sign_users"
|
table = "sign_users"
|
||||||
table_description = "用户签到数据表"
|
table_description = "用户签到数据表"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_user(cls, user_id: str, platform: str | None = None) -> "SignUser":
|
||||||
|
"""获取签到用户
|
||||||
|
|
||||||
|
参数:
|
||||||
|
user_id: 用户id
|
||||||
|
platform: 平台.
|
||||||
|
|
||||||
|
返回:
|
||||||
|
Self: SignUser
|
||||||
|
"""
|
||||||
|
user_console = await UserConsole.get_user(user_id, platform)
|
||||||
|
user, _ = await SignUser.get_or_create(
|
||||||
|
user_id=user_id,
|
||||||
|
defaults={"user_console": user_console, "platform": platform},
|
||||||
|
)
|
||||||
|
return user
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def sign(
|
async def sign(
|
||||||
cls,
|
cls,
|
||||||
|
|||||||
@ -106,3 +106,19 @@ class SqlUtils:
|
|||||||
f"Unsupported database type: {db_class_name}", query.__module__
|
f"Unsupported database type: {db_class_name}", query.__module__
|
||||||
)
|
)
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def add_column(
|
||||||
|
cls,
|
||||||
|
table_name: str,
|
||||||
|
column_name: str,
|
||||||
|
column_type: str,
|
||||||
|
default: str | None = None,
|
||||||
|
not_null: bool = False,
|
||||||
|
) -> str:
|
||||||
|
sql = f"ALTER TABLE {table_name} ADD COLUMN {column_name} {column_type}"
|
||||||
|
if default:
|
||||||
|
sql += f" DEFAULT {default}"
|
||||||
|
if not_null:
|
||||||
|
sql += " NOT NULL"
|
||||||
|
return sql
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user