mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
perf👌: 添加shortcut
This commit is contained in:
parent
2501a72bb8
commit
499e51e996
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -15,6 +15,7 @@
|
|||||||
"nonebot",
|
"nonebot",
|
||||||
"onebot",
|
"onebot",
|
||||||
"tobytes",
|
"tobytes",
|
||||||
|
"unban",
|
||||||
"userinfo",
|
"userinfo",
|
||||||
"zhenxun"
|
"zhenxun"
|
||||||
],
|
],
|
||||||
|
|||||||
@ -29,12 +29,31 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
name="封禁用户/群组",
|
name="封禁用户/群组",
|
||||||
description="你被逮捕了!丢进小黑屋!封禁用户以及群组,屏蔽消息",
|
description="你被逮捕了!丢进小黑屋!封禁用户以及群组,屏蔽消息",
|
||||||
usage="""
|
usage="""
|
||||||
.ban [at] ?[小时] ?[分钟]
|
普通管理员
|
||||||
.unban
|
格式:
|
||||||
示例:.ban @user
|
ban [At用户] [时长]
|
||||||
示例:.ban @user 6
|
|
||||||
示例:.ban @user 3 10
|
示例:
|
||||||
示例:.unban @user
|
ban @用户 : 永久拉黑用户
|
||||||
|
ban @用户 100 : 拉黑用户100分钟
|
||||||
|
unban @用户 : 从小黑屋中拉出来
|
||||||
|
|
||||||
|
超级管理员额外命令
|
||||||
|
格式:
|
||||||
|
ban [At用户/用户Id] [时长]
|
||||||
|
ban列表: 获取所有Ban数据
|
||||||
|
群组ban列表: 获取群组Ban数据
|
||||||
|
用户ban列表: 获取用户Ban数据
|
||||||
|
|
||||||
|
私聊下:
|
||||||
|
示例:
|
||||||
|
ban 123456789 : 永久拉黑用户123456789
|
||||||
|
ban 123456789 100 : 拉黑用户123456789 100分钟
|
||||||
|
|
||||||
|
ban -g 999999 : 拉黑群组为999999的群组
|
||||||
|
|
||||||
|
unban 123456789 : 从小黑屋中拉出来
|
||||||
|
unban -g 999999 : 将群组9999999从小黑屋中拉出来
|
||||||
""".strip(),
|
""".strip(),
|
||||||
extra=PluginExtraData(
|
extra=PluginExtraData(
|
||||||
author="HibiKier",
|
author="HibiKier",
|
||||||
@ -54,19 +73,22 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_matcher = on_alconna(
|
_ban_matcher = on_alconna(
|
||||||
Alconna(
|
Alconna(
|
||||||
"ban-console",
|
"ban",
|
||||||
Subcommand(
|
Args["user?", [str, At]]["duration?", int],
|
||||||
"ban",
|
Option("-g|--group", Args["group_id", str]),
|
||||||
Args["user?", [str, At]]["duration?", int],
|
),
|
||||||
Option("-g|--group", Args["group_id", str]),
|
rule=admin_check("ban", "BAN_LEVEL"),
|
||||||
),
|
priority=5,
|
||||||
Subcommand(
|
block=True,
|
||||||
"unban",
|
)
|
||||||
Args["user?", [str, At]],
|
|
||||||
Option("-g|--group", Args["group_id", str]),
|
_unban_matcher = on_alconna(
|
||||||
),
|
Alconna(
|
||||||
|
"unban",
|
||||||
|
Args["user?", [str, At]],
|
||||||
|
Option("-g|--group", Args["group_id", str]),
|
||||||
),
|
),
|
||||||
rule=admin_check("ban", "BAN_LEVEL"),
|
rule=admin_check("ban", "BAN_LEVEL"),
|
||||||
priority=5,
|
priority=5,
|
||||||
@ -76,14 +98,35 @@ _matcher = on_alconna(
|
|||||||
_status_matcher = on_alconna(
|
_status_matcher = on_alconna(
|
||||||
Alconna(
|
Alconna(
|
||||||
"ban-status",
|
"ban-status",
|
||||||
Option("-u|--user", Args["user_id", str]),
|
Option("-u|--user", action=store_true, help_text="过滤用户"),
|
||||||
Option("-g|--group", Args["group_id", str]),
|
Option("-g|--group", action=store_true, help_text="过滤群组"),
|
||||||
),
|
),
|
||||||
permission=SUPERUSER,
|
permission=SUPERUSER,
|
||||||
priority=1,
|
priority=1,
|
||||||
block=True,
|
block=True,
|
||||||
)
|
)
|
||||||
# TODO: shortcut
|
|
||||||
|
_status_matcher.shortcut(
|
||||||
|
"ban列表",
|
||||||
|
command="ban-status",
|
||||||
|
arguments=[],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_status_matcher.shortcut(
|
||||||
|
"用户ban列表",
|
||||||
|
command="ban-status",
|
||||||
|
arguments=["--user"],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
_status_matcher.shortcut(
|
||||||
|
"群组ban列表",
|
||||||
|
command="ban-status",
|
||||||
|
arguments=["--group"],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@_status_matcher.handle()
|
@_status_matcher.handle()
|
||||||
@ -94,15 +137,20 @@ async def _(
|
|||||||
user_id: Match[str],
|
user_id: Match[str],
|
||||||
group_id: Match[str],
|
group_id: Match[str],
|
||||||
):
|
):
|
||||||
|
filter_type = None
|
||||||
|
if arparma.find("user"):
|
||||||
|
filter_type = "user"
|
||||||
|
if arparma.find("group"):
|
||||||
|
filter_type = "group"
|
||||||
_user_id = user_id.result if user_id.available else None
|
_user_id = user_id.result if user_id.available else None
|
||||||
_group_id = group_id.result if group_id.available else None
|
_group_id = group_id.result if group_id.available else None
|
||||||
if image := await BanManage.build_ban_image(_user_id, _group_id):
|
if image := await BanManage.build_ban_image(filter_type):
|
||||||
await Image(image.pic2bs4()).finish(reply=True)
|
await Image(image.pic2bs4()).finish(reply=True)
|
||||||
else:
|
else:
|
||||||
await Text("数据为空捏...").finish(reply=True)
|
await Text("数据为空捏...").finish(reply=True)
|
||||||
|
|
||||||
|
|
||||||
@_matcher.assign("ban")
|
@_ban_matcher.handle()
|
||||||
async def _(
|
async def _(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
session: EventSession,
|
session: EventSession,
|
||||||
@ -150,7 +198,7 @@ async def _(
|
|||||||
await Text(f"对 {at_msg} 狠狠惩戒了一番,一脚踢进了小黑屋!").finish(reply=True)
|
await Text(f"对 {at_msg} 狠狠惩戒了一番,一脚踢进了小黑屋!").finish(reply=True)
|
||||||
|
|
||||||
|
|
||||||
@_matcher.assign("unban")
|
@_unban_matcher.handle()
|
||||||
async def _(
|
async def _(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
session: EventSession,
|
session: EventSession,
|
||||||
|
|||||||
@ -1,33 +1,35 @@
|
|||||||
import time
|
import time
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from nonebot_plugin_session import EventSession
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
from zhenxun.models.ban_console import BanConsole
|
from zhenxun.models.ban_console import BanConsole
|
||||||
from zhenxun.models.level_user import LevelUser
|
from zhenxun.models.level_user import LevelUser
|
||||||
from zhenxun.utils.image_utils import ImageTemplate
|
from zhenxun.utils.image_utils import BuildImage, ImageTemplate
|
||||||
|
|
||||||
|
|
||||||
class BanManage:
|
class BanManage:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def build_ban_image(cls, user_id: str | None, group_id: str | None):
|
async def build_ban_image(
|
||||||
|
cls,
|
||||||
|
filter_type: Literal["group", "user"] | None,
|
||||||
|
) -> BuildImage | None:
|
||||||
|
"""构造Ban列表图片
|
||||||
|
|
||||||
|
参数:
|
||||||
|
filter_type: 过滤类型
|
||||||
|
|
||||||
|
返回:
|
||||||
|
BuildImage | None: Ban列表图片
|
||||||
|
"""
|
||||||
data_list = None
|
data_list = None
|
||||||
if not user_id and not group_id:
|
if not filter_type:
|
||||||
data_list = await BanConsole.all()
|
data_list = await BanConsole.all()
|
||||||
elif user_id:
|
elif filter_type == "user":
|
||||||
if group_id:
|
data_list = await BanConsole.filter(group_id__isnull=True).all()
|
||||||
data_list = await BanConsole.filter(
|
elif filter_type == "group":
|
||||||
user_id=user_id, group_id=group_id
|
data_list = await BanConsole.filter(user_id__isnull=True).all()
|
||||||
).all()
|
|
||||||
else:
|
|
||||||
data_list = await BanConsole.filter(
|
|
||||||
user_id=user_id, group_id__isnull=True
|
|
||||||
).all()
|
|
||||||
else:
|
|
||||||
if group_id:
|
|
||||||
data_list = await BanConsole.filter(
|
|
||||||
user_id__isnull=True, group_id=group_id
|
|
||||||
).all()
|
|
||||||
if not data_list:
|
if not data_list:
|
||||||
return None
|
return None
|
||||||
column_name = [
|
column_name = [
|
||||||
@ -41,8 +43,8 @@ class BanManage:
|
|||||||
row_data = []
|
row_data = []
|
||||||
for data in data_list:
|
for data in data_list:
|
||||||
duration = int((data.ban_time + data.duration - time.time()) / 60)
|
duration = int((data.ban_time + data.duration - time.time()) / 60)
|
||||||
if duration < 0:
|
if data.duration < 0:
|
||||||
duration = 0
|
duration = "∞"
|
||||||
row_data.append(
|
row_data.append(
|
||||||
[
|
[
|
||||||
data.id,
|
data.id,
|
||||||
|
|||||||
@ -19,11 +19,28 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
name="功能开关",
|
name="功能开关",
|
||||||
description="对群组内的功能限制,超级用户可以对群组以及全局的功能被动开关限制",
|
description="对群组内的功能限制,超级用户可以对群组以及全局的功能被动开关限制",
|
||||||
usage="""
|
usage="""
|
||||||
开启/关闭[功能]
|
普通管理员
|
||||||
群被动状态
|
格式:
|
||||||
开启全部被动
|
开启/关闭[功能名称] : 开关功能
|
||||||
关闭全部被动
|
群被动状态 : 查看被动技能开关状态
|
||||||
醒来/休息吧
|
醒来 : 结束休眠
|
||||||
|
休息吧 : 群组休眠, 不会再响应命令
|
||||||
|
|
||||||
|
示例:
|
||||||
|
开启签到 : 开启签到
|
||||||
|
关闭签到 : 关闭签到
|
||||||
|
|
||||||
|
超级管理员额外命令
|
||||||
|
格式:
|
||||||
|
插件列表
|
||||||
|
开启/关闭[功能名称] ?[-t ["private", "p", "group", "g"](关闭类型)] ?[-g 群组Id]
|
||||||
|
|
||||||
|
私聊下:
|
||||||
|
示例:
|
||||||
|
开启签到 : 全局开启签到
|
||||||
|
关闭签到 : 全局关闭签到
|
||||||
|
关闭签到 p : 全局私聊关闭签到
|
||||||
|
关闭签到 -g 12345678 : 关闭群组12345678的签到功能(普通管理员无法开启)
|
||||||
""".strip(),
|
""".strip(),
|
||||||
extra=PluginExtraData(
|
extra=PluginExtraData(
|
||||||
author="HibiKier",
|
author="HibiKier",
|
||||||
@ -43,9 +60,6 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: shortcut
|
|
||||||
|
|
||||||
|
|
||||||
@_status_matcher.assign("$main")
|
@_status_matcher.assign("$main")
|
||||||
async def _(bot: Bot, session: EventSession, arparma: Arparma):
|
async def _(bot: Bot, session: EventSession, arparma: Arparma):
|
||||||
image = None
|
image = None
|
||||||
|
|||||||
@ -40,8 +40,6 @@ _status_matcher = on_alconna(
|
|||||||
block=True,
|
block=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: shortcut
|
|
||||||
|
|
||||||
_group_status_matcher = on_alconna(
|
_group_status_matcher = on_alconna(
|
||||||
Alconna("group-status", Args["status", ["sleep", "wake"]]),
|
Alconna("group-status", Args["status", ["sleep", "wake"]]),
|
||||||
rule=admin_check("admin_bot_manage", "CHANGE_GROUP_SWITCH_LEVEL")
|
rule=admin_check("admin_bot_manage", "CHANGE_GROUP_SWITCH_LEVEL")
|
||||||
|
|||||||
@ -5,10 +5,12 @@ from nonebot.adapters import Bot
|
|||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
from nonebot_plugin_alconna import (
|
from nonebot_plugin_alconna import (
|
||||||
Alconna,
|
Alconna,
|
||||||
|
AlconnaMatch,
|
||||||
Args,
|
Args,
|
||||||
Arparma,
|
Arparma,
|
||||||
Match,
|
Match,
|
||||||
Option,
|
Option,
|
||||||
|
Query,
|
||||||
on_alconna,
|
on_alconna,
|
||||||
store_true,
|
store_true,
|
||||||
)
|
)
|
||||||
@ -39,13 +41,20 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
_matcher = on_alconna(
|
_matcher = on_alconna(
|
||||||
Alconna(
|
Alconna(
|
||||||
"消息排行",
|
"消息排行",
|
||||||
Option("--des", default=False, action=store_true),
|
Option("--des", action=store_true, help_text="逆序"),
|
||||||
Args["type?", ["日", "周", "月", "年"]]["count?", int, 10],
|
Args["type?", ["日", "周", "月", "年"]]["count?", int, 10],
|
||||||
),
|
),
|
||||||
priority=5,
|
priority=5,
|
||||||
block=True,
|
block=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_matcher.shortcut(
|
||||||
|
r"(?P<type>.+)?消息排行",
|
||||||
|
command="消息排行",
|
||||||
|
arguments=["type", "{type}"],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@_matcher.handle()
|
@_matcher.handle()
|
||||||
async def _(
|
async def _(
|
||||||
@ -53,11 +62,9 @@ async def _(
|
|||||||
session: EventSession,
|
session: EventSession,
|
||||||
arparma: Arparma,
|
arparma: Arparma,
|
||||||
type: Match[str],
|
type: Match[str],
|
||||||
count: Match[int],
|
count: Query[int] = Query("count", 10),
|
||||||
):
|
):
|
||||||
group_id = session.id3 or session.id2
|
group_id = session.id3 or session.id2
|
||||||
if not group_id:
|
|
||||||
await Text("群组id为空...").finish()
|
|
||||||
time_now = datetime.now()
|
time_now = datetime.now()
|
||||||
date_scope = None
|
date_scope = None
|
||||||
zero_today = time_now - timedelta(
|
zero_today = time_now - timedelta(
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class ChatHistory(Model):
|
|||||||
@classmethod
|
@classmethod
|
||||||
async def get_group_msg_rank(
|
async def get_group_msg_rank(
|
||||||
cls,
|
cls,
|
||||||
gid: str,
|
gid: str | None,
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
order: str = "DESC",
|
order: str = "DESC",
|
||||||
date_scope: tuple[datetime, datetime] | None = None,
|
date_scope: tuple[datetime, datetime] | None = None,
|
||||||
@ -48,7 +48,7 @@ class ChatHistory(Model):
|
|||||||
date_scope: 日期范围
|
date_scope: 日期范围
|
||||||
"""
|
"""
|
||||||
o = "-" if order == "DESC" else ""
|
o = "-" if order == "DESC" else ""
|
||||||
query = cls.filter(group_id=gid)
|
query = cls.filter(group_id=gid) if gid else cls
|
||||||
if date_scope:
|
if date_scope:
|
||||||
query = query.filter(create_time__range=date_scope)
|
query = query.filter(create_time__range=date_scope)
|
||||||
return list(
|
return list(
|
||||||
@ -60,18 +60,23 @@ class ChatHistory(Model):
|
|||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_group_first_msg_datetime(cls, group_id: str) -> datetime | None:
|
async def get_group_first_msg_datetime(
|
||||||
|
cls, group_id: str | None
|
||||||
|
) -> datetime | None:
|
||||||
"""获取群第一条记录消息时间
|
"""获取群第一条记录消息时间
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
group_id: 群组id
|
group_id: 群组id
|
||||||
"""
|
"""
|
||||||
if (
|
if group_id:
|
||||||
message := await cls.filter(group_id=group_id)
|
message = (
|
||||||
.order_by("create_time")
|
await cls.filter(group_id=group_id).order_by("create_time").first()
|
||||||
.first()
|
)
|
||||||
):
|
else:
|
||||||
|
message = await cls.all().order_by("create_time").first()
|
||||||
|
if message:
|
||||||
return message.create_time
|
return message.create_time
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_message(
|
async def get_message(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user