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
5321c8d9c0
commit
91ca7b40b8
@ -31,16 +31,16 @@ usage:
|
|||||||
主播订阅相当于 直播间订阅 + UP订阅
|
主播订阅相当于 直播间订阅 + UP订阅
|
||||||
指令:[示例Id乱打的,仅做示例]
|
指令:[示例Id乱打的,仅做示例]
|
||||||
添加订阅 ['主播'/'UP'/'番剧'] [id/链接/番名]
|
添加订阅 ['主播'/'UP'/'番剧'] [id/链接/番名]
|
||||||
删除订阅 [id]
|
删除订阅 ['主播'/'UP'/'id'] [id]
|
||||||
查看订阅
|
查看订阅
|
||||||
示例:添加订阅主播 2345344 <-(直播房间id)
|
示例:添加订阅主播 2345344 <-(直播房间id)
|
||||||
示例:添加订阅UP 2355543 <-(个人主页id)
|
示例:添加订阅UP 2355543 <-(个人主页id)
|
||||||
示例:添加订阅番剧 史莱姆 <-(支持模糊搜索)
|
示例:添加订阅番剧 史莱姆 <-(支持模糊搜索)
|
||||||
示例:添加订阅番剧 125344 <-(番剧id)
|
示例:添加订阅番剧 125344 <-(番剧id)
|
||||||
示例:删除订阅 2324344 <-(任意id,通过查看订阅获取)
|
示例:删除订阅id 2324344 <-(任意id,通过查看订阅获取)
|
||||||
""".strip()
|
""".strip()
|
||||||
__plugin_des__ = "非常便利的B站订阅通知"
|
__plugin_des__ = "非常便利的B站订阅通知"
|
||||||
__plugin_cmd__ = ["添加订阅 [主播/UP/番剧] [id/链接/番名]", "删除订阅 [id]", "查看订阅"]
|
__plugin_cmd__ = ["添加订阅 [主播/UP/番剧] [id/链接/番名]", "删除订阅 ['主播'/'UP'/'id'] [id]", "查看订阅"]
|
||||||
__plugin_version__ = 0.1
|
__plugin_version__ = 0.1
|
||||||
__plugin_author__ = "HibiKier & NumberSir"
|
__plugin_author__ = "HibiKier & NumberSir"
|
||||||
__plugin_settings__ = {
|
__plugin_settings__ = {
|
||||||
@ -68,7 +68,7 @@ __plugin_configs__ = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_sub = on_command("添加订阅", priority=5, block=True)
|
add_sub = on_command("添加订阅", priority=5, block=True)
|
||||||
del_sub = on_regex(r"^删除订阅[\s\S]?(\d+)$", priority=5, block=True)
|
del_sub = on_command("删除订阅", priority=5, block=True)
|
||||||
show_sub_info = on_regex("^查看订阅$", priority=5, block=True)
|
show_sub_info = on_regex("^查看订阅$", priority=5, block=True)
|
||||||
|
|
||||||
driver: Driver = nonebot.get_driver()
|
driver: Driver = nonebot.get_driver()
|
||||||
@ -84,6 +84,7 @@ async def _():
|
|||||||
|
|
||||||
|
|
||||||
@add_sub.handle()
|
@add_sub.handle()
|
||||||
|
@del_sub.handle()
|
||||||
async def _(event: MessageEvent, state: T_State, arg: Message = CommandArg()):
|
async def _(event: MessageEvent, state: T_State, arg: Message = CommandArg()):
|
||||||
msg = arg.extract_plain_text().strip().split()
|
msg = arg.extract_plain_text().strip().split()
|
||||||
if len(msg) < 2:
|
if len(msg) < 2:
|
||||||
@ -157,23 +158,30 @@ async def _(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@del_sub.handle()
|
@del_sub.got("sub_type")
|
||||||
async def _(event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()):
|
@del_sub.got("sub_user")
|
||||||
msg = reg_group[0]
|
@del_sub.got("id")
|
||||||
id_ = (
|
async def _(
|
||||||
f"{event.group_id}"
|
event: MessageEvent,
|
||||||
if isinstance(event, GroupMessageEvent)
|
id_: str = ArgStr("id"),
|
||||||
else f"{event.user_id}"
|
sub_type: str = ArgStr("sub_type"),
|
||||||
)
|
sub_user: str = ArgStr("sub_user"),
|
||||||
if await BilibiliSub.delete_bilibili_sub(int(msg), id_):
|
):
|
||||||
await del_sub.send(f"删除订阅id:{msg} 成功...")
|
if sub_type in ["主播", "直播"]:
|
||||||
|
result = await BilibiliSub.delete_bilibili_sub(int(id_),sub_user,"live")
|
||||||
|
elif sub_type.lower() in ["up", "用户"]:
|
||||||
|
result = await BilibiliSub.delete_bilibili_sub(int(id_),sub_user,"up")
|
||||||
|
else: result = await BilibiliSub.delete_bilibili_sub(int(id_),sub_user)
|
||||||
|
if result:
|
||||||
|
await del_sub.send(f"删除订阅id:{id_} 成功...")
|
||||||
logger.info(
|
logger.info(
|
||||||
f"(USER {event.user_id}, GROUP "
|
f"(USER {event.user_id}, GROUP "
|
||||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||||
f" 删除订阅 {id_}"
|
f" 删除订阅 {id_}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await del_sub.send(f"删除订阅id:{msg} 失败...")
|
await del_sub.send(f"删除订阅id:{id_} 失败...")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@show_sub_info.handle()
|
@show_sub_info.handle()
|
||||||
|
|||||||
@ -107,7 +107,7 @@ class BilibiliSub(db.Model):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def delete_bilibili_sub(cls, sub_id: int, sub_user: str) -> bool:
|
async def delete_bilibili_sub(cls, sub_id: int, sub_user: str,sub_type: Optional[str] = None) -> bool:
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
删除订阅
|
删除订阅
|
||||||
@ -117,13 +117,22 @@ class BilibiliSub(db.Model):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
async with db.transaction():
|
async with db.transaction():
|
||||||
query = (
|
if sub_type:
|
||||||
await cls.query.where(
|
query = (
|
||||||
(cls.sub_id == sub_id) & (cls.sub_users.contains(sub_user))
|
await cls.query.where(
|
||||||
|
(cls.sub_id == sub_id) & (cls.sub_users.contains(sub_user) & (cls.sub_type == sub_type))
|
||||||
|
)
|
||||||
|
.with_for_update()
|
||||||
|
.gino.first()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
query = (
|
||||||
|
await cls.query.where(
|
||||||
|
(cls.sub_id == sub_id) & (cls.sub_users.contains(sub_user))
|
||||||
|
)
|
||||||
|
.with_for_update()
|
||||||
|
.gino.first()
|
||||||
)
|
)
|
||||||
.with_for_update()
|
|
||||||
.gino.first()
|
|
||||||
)
|
|
||||||
if not query:
|
if not query:
|
||||||
return False
|
return False
|
||||||
await query.update(
|
await query.update(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user