mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
update query and del
This commit is contained in:
parent
5e08c305da
commit
6118eaa9b4
@ -1,9 +1,10 @@
|
|||||||
from nonebot.rule import to_me
|
from nonebot.rule import to_me
|
||||||
from nonebot.typing import T_State
|
from nonebot.typing import T_State
|
||||||
from nonebot.adapters.cqhttp import Bot, Event, GroupMessageEvent
|
from nonebot.adapters.cqhttp import Bot, Event, GroupMessageEvent
|
||||||
|
from nonebot.adapters.cqhttp.message import Message
|
||||||
from nonebot.permission import Permission, SUPERUSER
|
from nonebot.permission import Permission, SUPERUSER
|
||||||
from nonebot.adapters.cqhttp.permission import GROUP_ADMIN, GROUP_MEMBER, GROUP_OWNER
|
from nonebot.adapters.cqhttp.permission import GROUP_ADMIN, GROUP_MEMBER, GROUP_OWNER
|
||||||
from nonebot import on_command
|
from nonebot import on_command, logger
|
||||||
|
|
||||||
from .platform.utils import check_sub_target
|
from .platform.utils import check_sub_target
|
||||||
from .platform import platform_manager
|
from .platform import platform_manager
|
||||||
@ -83,45 +84,50 @@ async def add_sub_process(bot: Bot, event: Event, state: T_State):
|
|||||||
target_name=state['name'], target_type=state['platform'],
|
target_name=state['name'], target_type=state['platform'],
|
||||||
cats=state.get('cats', []), tags=state.get('tags', []))
|
cats=state.get('cats', []), tags=state.get('tags', []))
|
||||||
await add_sub.finish('添加 {} 成功'.format(state['name']))
|
await add_sub.finish('添加 {} 成功'.format(state['name']))
|
||||||
|
|
||||||
|
|
||||||
# @add_sub.handle()
|
|
||||||
# async def _(bot: Bot, event: Event, state: T_State):
|
|
||||||
# args = str(event.get_message()).strip().split()
|
|
||||||
# if len(args) != 2:
|
|
||||||
# await add_sub.finish("使用方法为: 添加订阅 平台 id")
|
|
||||||
# return
|
|
||||||
# target_type, target = args
|
|
||||||
# if name := await check_sub_target(target_type, target):
|
|
||||||
# config: Config = Config()
|
|
||||||
# config.add_subscribe(event.group_id, "group", target, name, target_type)
|
|
||||||
# await add_sub.finish("成功添加 {}".format(name))
|
|
||||||
# else:
|
|
||||||
# await add_sub.finish("平台或者id不存在")
|
|
||||||
|
|
||||||
query_sub = on_command("查询订阅", rule=to_me(), priority=5)
|
query_sub = on_command("查询订阅", rule=to_me(), priority=5)
|
||||||
@query_sub.handle()
|
@query_sub.handle()
|
||||||
async def _(bot: Bot, event: Event, state: T_State):
|
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||||
config: Config = Config()
|
config: Config = Config()
|
||||||
sub_list = config.list_subscribe(event.group_id, "group")
|
sub_list = config.list_subscribe(event.group_id, "group")
|
||||||
res = '订阅的帐号为:\n'
|
res = '订阅的帐号为:\n'
|
||||||
for sub in sub_list:
|
for sub in sub_list:
|
||||||
res += '{} {} {}\n'.format(sub['target_type'], sub['target_name'], sub['target'])
|
res += '{} {} {}'.format(sub['target_type'], sub['target_name'], sub['target'])
|
||||||
send_msgs(bot, event.group_id, 'group', [await parse_text(res)])
|
platform = platform_manager[sub['target_type']]
|
||||||
await query_sub.finish()
|
if platform.categories:
|
||||||
|
res += ' [{}]'.format(', '.join(map(lambda x: platform.categories[x], sub['cats'])))
|
||||||
|
if platform.enable_tag:
|
||||||
|
res += ' {}'.format(', '.join(sub['tags']))
|
||||||
|
res += '\n'
|
||||||
|
# send_msgs(bot, event.group_id, 'group', [await parse_text(res)])
|
||||||
|
await query_sub.finish(Message(await parse_text(res)))
|
||||||
|
|
||||||
del_sub = on_command("删除订阅", rule=to_me(), permission=GROUP_ADMIN | GROUP_OWNER, priority=5)
|
del_sub = on_command("删除订阅", rule=to_me(), permission=GROUP_ADMIN | GROUP_OWNER, priority=5)
|
||||||
@del_sub.handle()
|
@del_sub.handle()
|
||||||
async def _(bot: Bot, event: Event, state: T_State):
|
async def send_list(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||||
args = str(event.get_message()).strip().split()
|
config: Config = Config()
|
||||||
if len(args) != 2:
|
sub_list = config.list_subscribe(event.group_id, "group")
|
||||||
await del_sub.finish("使用方法为: 删除订阅 平台 id")
|
res = '订阅的帐号为:\n'
|
||||||
return
|
state['sub_table'] = {}
|
||||||
target_type, target = args
|
for index, sub in enumerate(sub_list, 1):
|
||||||
config = Config()
|
state['sub_table'][index] = {'target_type': sub['target_type'], 'target': sub['target']}
|
||||||
try:
|
res += '{} {} {} {}\n'.format(index, sub['target_type'], sub['target_name'], sub['target'])
|
||||||
config.del_subscribe(event.group_id, "group", target, target_type)
|
platform = platform_manager[sub['target_type']]
|
||||||
except NoSuchSubscribeException:
|
if platform.categories:
|
||||||
await del_sub.finish('平台或id不存在')
|
res += ' [{}]'.format(', '.join(map(lambda x: platform.categories[x], sub['cats'])))
|
||||||
await del_sub.finish('删除成功')
|
if platform.enable_tag:
|
||||||
|
res += ' {}'.format(', '.join(sub['tags']))
|
||||||
|
res += '\n'
|
||||||
|
await bot.send(event=event, message=Message(await parse_text(res)))
|
||||||
|
|
||||||
|
@del_sub.receive()
|
||||||
|
async def do_del(bot, event: GroupMessageEvent, state: T_State):
|
||||||
|
try:
|
||||||
|
index = int(str(event.get_message()).strip())
|
||||||
|
config = Config()
|
||||||
|
config.del_subscribe(event.group_id, 'group', **state['sub_table'][index])
|
||||||
|
except Exception as e:
|
||||||
|
await del_sub.reject('删除错误')
|
||||||
|
logger.warning(e)
|
||||||
|
else:
|
||||||
|
await del_sub.finish('删除成功')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user