mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +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.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, Event, GroupMessageEvent
|
||||
from nonebot.adapters.cqhttp.message import Message
|
||||
from nonebot.permission import Permission, SUPERUSER
|
||||
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 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'],
|
||||
cats=state.get('cats', []), tags=state.get('tags', []))
|
||||
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.handle()
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
config: Config = Config()
|
||||
sub_list = config.list_subscribe(event.group_id, "group")
|
||||
res = '订阅的帐号为:\n'
|
||||
for sub in sub_list:
|
||||
res += '{} {} {}\n'.format(sub['target_type'], sub['target_name'], sub['target'])
|
||||
send_msgs(bot, event.group_id, 'group', [await parse_text(res)])
|
||||
await query_sub.finish()
|
||||
res += '{} {} {}'.format(sub['target_type'], sub['target_name'], sub['target'])
|
||||
platform = platform_manager[sub['target_type']]
|
||||
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.handle()
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
args = str(event.get_message()).strip().split()
|
||||
if len(args) != 2:
|
||||
await del_sub.finish("使用方法为: 删除订阅 平台 id")
|
||||
return
|
||||
target_type, target = args
|
||||
config = Config()
|
||||
try:
|
||||
config.del_subscribe(event.group_id, "group", target, target_type)
|
||||
except NoSuchSubscribeException:
|
||||
await del_sub.finish('平台或id不存在')
|
||||
await del_sub.finish('删除成功')
|
||||
async def send_list(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
config: Config = Config()
|
||||
sub_list = config.list_subscribe(event.group_id, "group")
|
||||
res = '订阅的帐号为:\n'
|
||||
state['sub_table'] = {}
|
||||
for index, sub in enumerate(sub_list, 1):
|
||||
state['sub_table'][index] = {'target_type': sub['target_type'], 'target': sub['target']}
|
||||
res += '{} {} {} {}\n'.format(index, sub['target_type'], sub['target_name'], sub['target'])
|
||||
platform = platform_manager[sub['target_type']]
|
||||
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'
|
||||
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