mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
🐛 修改bug
This commit is contained in:
parent
96ca33f878
commit
6d58f6a188
@ -174,7 +174,7 @@ async def _():
|
||||
if update_list:
|
||||
await TaskInfo.bulk_update(
|
||||
update_list,
|
||||
["run_time", "status", "name"],
|
||||
["run_time", "name"],
|
||||
10,
|
||||
)
|
||||
await data_migration()
|
||||
|
||||
@ -17,7 +17,6 @@ __plugin_meta__ = PluginMetadata(
|
||||
插件商店 : 查看当前的插件商店
|
||||
添加插件 id : 添加插件
|
||||
移除插件 id : 移除插件
|
||||
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier",
|
||||
|
||||
@ -19,10 +19,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.HIDDEN,
|
||||
tasks=[
|
||||
Task(module="group_welcome", name="进群欢迎"),
|
||||
Task(module="refund_group_remind", name="退群提醒"),
|
||||
],
|
||||
tasks=[Task(module="morning_goodnight", name="早晚安")],
|
||||
).dict(),
|
||||
)
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ from nonebot_plugin_session import EventSession
|
||||
from tortoise import Tortoise
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.db_context import TestSQL
|
||||
from zhenxun.models.ban_console import BanConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.image_utils import ImageTemplate
|
||||
@ -60,7 +60,7 @@ async def _(session: EventSession, message: UniMsg):
|
||||
logger.info(f"执行SQL语句: {sql_text}", "exec", session=session)
|
||||
try:
|
||||
if not sql_text.lower().startswith("select"):
|
||||
await TestSQL.raw(sql_text)
|
||||
await BanConsole.raw(sql_text)
|
||||
else:
|
||||
db = Tortoise.get_connection("default")
|
||||
res = await db.execute_query_dict(sql_text)
|
||||
@ -74,10 +74,12 @@ async def _(session: EventSession, message: UniMsg):
|
||||
for c in _column:
|
||||
data.append(r.get(c))
|
||||
data_list.append(data)
|
||||
if not data_list:
|
||||
return await MessageUtils.build_message("查询结果为空!").send()
|
||||
table = await ImageTemplate.table_page(
|
||||
"EXEC", f"总共有 {len(data_list)} 条数据捏", list(_column), data_list
|
||||
)
|
||||
await MessageUtils.build_message(table).send()
|
||||
return await MessageUtils.build_message(table).send()
|
||||
except Exception as e:
|
||||
logger.error("执行 SQL 语句失败...", session=session, e=e)
|
||||
await MessageUtils.build_message(f"执行 SQL 语句失败... {type(e)}").finish()
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
from typing import Any
|
||||
|
||||
from tortoise import fields
|
||||
from tortoise.backends.base.client import BaseDBAsyncClient
|
||||
from typing_extensions import Self
|
||||
|
||||
from zhenxun.services.db_context import Model
|
||||
@ -40,8 +43,39 @@ class GroupConsole(Model):
|
||||
table_description = "群组信息表"
|
||||
unique_together = ("group_id", "channel_id")
|
||||
|
||||
# @classmethod
|
||||
# async def create( # type: ignore
|
||||
# cls,
|
||||
# using_db: BaseDBAsyncClient | None = None,
|
||||
# **kwargs: Any,
|
||||
# ) -> Self:
|
||||
# group, _ = await super().create(using_db, **kwargs)
|
||||
# return group
|
||||
|
||||
# @classmethod
|
||||
# async def get_or_create( # type: ignore
|
||||
# cls,
|
||||
# defaults: dict | None = None,
|
||||
# using_db: BaseDBAsyncClient | None = None,
|
||||
# **kwargs: Any,
|
||||
# ) -> tuple[Self, bool]:
|
||||
# group, is_create = await super().get_or_create(defaults, using_db, **kwargs)
|
||||
# return group, is_create
|
||||
|
||||
# @classmethod
|
||||
# async def update_or_create( # type: ignore
|
||||
# cls,
|
||||
# defaults: dict | None = None,
|
||||
# using_db: BaseDBAsyncClient | None = None,
|
||||
# **kwargs: Any,
|
||||
# ) -> tuple[Self, bool]:
|
||||
# group, is_create = await super().update_or_create(defaults, using_db, **kwargs)
|
||||
# return group, is_create
|
||||
|
||||
@classmethod
|
||||
async def get_group(cls, group_id: str, channel_id: str | None = None) -> Self:
|
||||
async def get_group(
|
||||
cls, group_id: str, channel_id: str | None = None
|
||||
) -> Self | None:
|
||||
"""获取群组
|
||||
|
||||
参数:
|
||||
@ -52,21 +86,20 @@ class GroupConsole(Model):
|
||||
Self: GroupConsole
|
||||
"""
|
||||
if channel_id:
|
||||
return await cls.get(group_id=group_id, channel_id=channel_id)
|
||||
return await cls.get(group_id=group_id, channel_id__isnull=True)
|
||||
return await cls.get_or_none(group_id=group_id, channel_id=channel_id)
|
||||
return await cls.get_or_none(group_id=group_id, channel_id__isnull=True)
|
||||
|
||||
@classmethod
|
||||
async def is_super_group(cls, group_id: str, channel_id: str | None = None) -> bool:
|
||||
async def is_super_group(cls, group_id: str) -> bool:
|
||||
"""是否超级用户指定群
|
||||
|
||||
参数:
|
||||
group_id: 群组id
|
||||
channel_id: 频道id.
|
||||
|
||||
返回:
|
||||
bool: 是否超级用户指定群
|
||||
"""
|
||||
if group := await cls.get_or_none(group_id=group_id):
|
||||
if group := await cls.get_group(group_id):
|
||||
return group.is_super
|
||||
return False
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ class TaskInfo(Model):
|
||||
"""被动技能名称"""
|
||||
status = fields.BooleanField(default=True, description="全局开关状态")
|
||||
"""全局开关状态"""
|
||||
# default_status = fields.BooleanField(default=True, description="进群默认状态")
|
||||
# """进群默认状态"""
|
||||
run_time = fields.CharField(255, null=True, description="运行时间")
|
||||
"""运行时间"""
|
||||
run_count = fields.IntField(default=0, description="运行次数")
|
||||
@ -53,3 +55,9 @@ class TaskInfo(Model):
|
||||
"""群组是否被ban"""
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def _run_script(cls):
|
||||
return [
|
||||
# "ALTER TABLE task_info ADD default_status boolean NOT NULL DEFAULT true;",
|
||||
]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import ujson as json
|
||||
from nonebot.utils import is_coroutine_callable
|
||||
from tortoise import Tortoise, fields
|
||||
from tortoise import Tortoise
|
||||
from tortoise.connection import connections
|
||||
from tortoise.models import Model as Model_
|
||||
|
||||
@ -17,10 +17,8 @@ from zhenxun.configs.path_config import DATA_PATH
|
||||
|
||||
from .log import logger
|
||||
|
||||
MODELS: list[str] = []
|
||||
|
||||
SCRIPT_METHOD = []
|
||||
|
||||
MODELS: list[str] = []
|
||||
DATABASE_SETTING_FILE = DATA_PATH / "database.json"
|
||||
|
||||
|
||||
@ -39,16 +37,6 @@ class Model(Model_):
|
||||
SCRIPT_METHOD.append((cls.__module__, func))
|
||||
|
||||
|
||||
class TestSQL(Model):
|
||||
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
||||
"""自增id"""
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
table = "test_sql"
|
||||
table_description = "执行SQL命令,不记录任何数据"
|
||||
|
||||
|
||||
async def init():
|
||||
if DATABASE_SETTING_FILE.exists():
|
||||
with open(DATABASE_SETTING_FILE, "r", encoding="utf-8") as f:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user