From 3c3b97a0096bdd99189297905ec84afac9b9d294 Mon Sep 17 00:00:00 2001 From: Sena <851183156@qq.com> Date: Tue, 30 Aug 2022 17:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsuperuser=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8Cmagiadice=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot-plugin-magiadice/README.md | 6 ++ .../nonebot-plugin-magiadice/__init__.py | 8 ++- .../nonebot-plugin-magiadice/dice.py | 23 ++++--- .../nonebot-plugin-magiadice/log.py | 54 +++++++++++----- .../nonebot-plugin-magiadice/logger.py | 64 ++++++++++--------- nonebot-plugin-magiadice/setup.py | 2 +- .../nonebot-plugin-send/__init__.py | 13 ++-- nonebot-plugin-send/setup.py | 2 +- .../nonebot-plugin-ykt/__init__.py | 13 ++-- nonebot-plugin-ykt/setup.py | 2 +- 10 files changed, 119 insertions(+), 68 deletions(-) diff --git a/nonebot-plugin-magiadice/README.md b/nonebot-plugin-magiadice/README.md index 60e1aeb..05f962c 100644 --- a/nonebot-plugin-magiadice/README.md +++ b/nonebot-plugin-magiadice/README.md @@ -37,6 +37,12 @@ LOG部分使用了notion作为服务器,支持实时在线更新和围观, 4. .log name [title] 设置记录的标题(默认为日期) 5. .log intro [data] 添加介绍(添加在LOG开始的模组介绍中) 6. .log change [x] [data] 修改第x条模组介绍(不传data为删除)""" +### LOG处理 +1. 括号括起来的文字会设为灰色 +2. KP发的图片会插入到log中 +3. 被中括号括起来的文字会设置为线索文本 +4. 引号括起来的文字会设为斜体 +5. 指令不会记录,BOT的返回会记录 ### LOG记录流程 1. logon初始化LOG页面,输入该指令的人会自动登陆为KP 2. login玩家加入(必须,否则LOG无法判断玩家是谁从而自动筛选) diff --git a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/__init__.py b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/__init__.py index 37c6da8..1ff0ad0 100644 --- a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/__init__.py +++ b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/__init__.py @@ -1 +1,7 @@ -from . import dice, log \ No newline at end of file +from . import dice, log +from nonebot.plugin import PluginMetadata +__plugin_meta__= PluginMetadata( + name='magiadice', + description='魔法崩坏跑团骰娘及跑团记录', + usage='' +) \ No newline at end of file diff --git a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/dice.py b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/dice.py index 64b8952..39e21cb 100644 --- a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/dice.py +++ b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/dice.py @@ -2,6 +2,7 @@ from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message,MessageSegment from nonebot.params import CommandArg from numpy import random + import json from .log import botlog import os @@ -10,10 +11,8 @@ sc = on_command(".msc", priority=5) rd = on_command(".rd", priority=5) ra = on_command(".ra", priority=5) - datapath = 'data\magia\dailycd.json' - def rd_for(dice, num): sum = 0 for i in range(dice): @@ -136,23 +135,31 @@ async def rd_receive(event: GroupMessageEvent, args: Message = CommandArg()): tmp = rd_(args) name = event.get_user_id() str = f"的掷骰结果为{tmp}" - await botlog(event.group_id, name+str)#TODO QQ号改为昵称 + await botlog(event.group_id, event.sender.nickname,str)#TODO QQ号改为昵称 await rd.finish(MessageSegment.at(name)+str) @ra.handle() async def ra_receive(event: GroupMessageEvent, args: Message = CommandArg()): if args: - args = args.extract_plain_text() + args = args.extract_plain_text().strip().split() else: await rd.finish(f"只有知道主人的技能值,月月才能计算出来喵!") - _, result = ra_(args) name = event.get_user_id() - message = f'的检定结果是:'+result - await botlog(event.group_id, name+message) + if len(args)==1: + args=args[0] + _, result = ra_(args) + message = f'的检定结果是:'+result + elif len(args)==2: + attr,args=args[:2] + _, result = ra_(args) + message = f'的{attr}检定结果是:'+result + await botlog(event.group_id, event.sender.nickname,message) await ra.finish(MessageSegment.at(name)+message) + #TODO 彻底重写dice模块 #TODO 加入coc基本指令支持 #TODO 加入dnd基本指令支持 #TODO 加入st基本指令支持 -#TODO 加入属性值支持 \ No newline at end of file +#TODO 保存属性值支持 +#TODO Help重构 \ No newline at end of file diff --git a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/log.py b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/log.py index 02429f0..3d2e9c0 100644 --- a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/log.py +++ b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/log.py @@ -1,10 +1,11 @@ +import asyncio from nonebot import on_command, on_message from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message from nonebot.params import CommandArg from .logger import Logger from nonebot import get_driver import time -superuser = get_driver().config.superusers[0] +superusers = get_driver().config.superusers sendtomaster = get_driver().config.trpgsendtomaster loglist = {} # FIXME 配置文件化+启动时自动载入 @@ -14,6 +15,9 @@ async def loghelp(): await log.finish( """魔法崩坏跑团log工具 喵 +魔法崩坏规则地址:https://sena-nana.github.io + +KP发送.log on指令开始记录 .log on 开始记录(不传id)/使用id继续记录 .log in 加入游戏(不传名字则使用昵称) .log off 结束记录(记录十小时后自动停止) @@ -25,7 +29,7 @@ async def loghelp(): ) # TODO 通过图片生成配置 # TODO 完善使用说明 - +# TODO 支持删除记录 @log.handle() async def log_(bot: Bot, event: GroupMessageEvent, args: Message = CommandArg()): list_str = args.extract_plain_text().strip().split() @@ -46,10 +50,14 @@ async def log_(bot: Bot, event: GroupMessageEvent, args: Message = CommandArg()) if event.group_id in loglist: await log.finish(f'请先结束当前群正在记录的游戏喵') else: + await log.send('Log初始化中,在此期间发送其他指令可能产生错误。初始化后请玩家使用.log in指令登陆游戏') loglist[event.group_id] = Logger() - await loglist[event.group_id].init(event.sender.nickname) + error=await loglist[event.group_id].init(event.sender.nickname) + if error: + loglist.pop(event.group_id) + log.finish(error) await masteron(bot, event) - await log.finish(f'命运之书的文字逐渐浮现(开始记录)\n实时更新链接:https://www.notion.so/'+loglist[event.group_id].page.id.replace("-", '')+"\n- 只有玩家、KP的发言和BOT的掷骰结果会被记录喵\n- [.]开头的发言会被LOG忽略\n- (括号括起来的发言会被标记为灰色)\n- “角色说话请使用引号喵!”\n-KP发的图片会作为线索图被记录(表情包打咩)") + await log.finish(f'命运之书的文字逐渐浮现(开始记录)\n实时更新链接:https://www.notion.so/'+loglist[event.group_id].page.id.replace("-", '')+"\n- 只有玩家、KP的发言和BOT的掷骰结果会被记录喵\n- [.]开头的发言会被LOG忽略\n- (括号括起来的发言会被标记为灰色)\n- “角色说话请使用引号喵!”\n- [使用中括号的话将会作为线索记录]\n- KP发的图片会作为线索图插入,如果一定要发表情包请用括号括起来(不会上传)") case 'in': if event.group_id in loglist: error = await loglist[event.group_id].login(event.sender.nickname, event.sender.nickname) @@ -57,6 +65,9 @@ async def log_(bot: Bot, event: GroupMessageEvent, args: Message = CommandArg()) await log.finish(error) else: await log.finish(f'当前群没有正在记录的游戏喵') + case 'debug': + for child in loglist.values(): + print(child.__dict__) case _: await loghelp() case 2: @@ -73,7 +84,10 @@ async def log_(bot: Bot, event: GroupMessageEvent, args: Message = CommandArg()) await log.finish(f'请先结束当前群正在记录的游戏喵') else: loglist[event.group_id] = Logger() - await loglist[event.group_id].init(list_str[1]) + error = await loglist[event.group_id].init(list_str[1]) + if error: + loglist.pop(event.group_id) + log.finish(error) await masteron(bot, event) await log.finish(f'{loglist[event.group_id].page.title}记录恢复完成!\n实时更新链接:https://www.notion.so/'+loglist[event.group_id].page.id.replace("-", '')) case 'intro': @@ -119,29 +133,35 @@ async def islogging(bot: Bot, event: GroupMessageEvent): await masteroff(bot, event, id) await logger.finish(f'持续记录时间过久自动停止了喵!\n查看链接:https://www.notion.so/'+id+f'\n链接后缀为记录id,使用[.log on id]指令可以继续记录\n可自行保存为离线网页或打印为pdf') text = event.get_plaintext() + if loglist[event.group_id].player[event.sender.nickname][0] == 'KP': + if text[0] not in ['(','(']: + for seg in event.message['image']: + await loglist[event.group_id].logup_image(seg.data['url']) if text: await loglist[event.group_id].logup_text(event.sender.nickname, text) - if loglist[event.group_id].player[event.sender.nickname][0] == 'KP': - for seg in event.message['image']: - await loglist[event.group_id].logup_image(seg.data['url']) -async def botlog(groupid, message): +async def botlog(groupid, sender,message): if groupid in loglist: + message='「'+loglist[groupid].player[sender][0]+'」'+message await loglist[groupid].logup_text(False, message) async def masteron(bot, event): if sendtomaster: - await bot.call_api('send_msg', **{ - 'message': f'{event.group_id}开始记录数据:'+loglist[event.group_id].page.id.replace("-", ''), - 'user_id': superuser, - }) + for superuser in superusers: + await bot.call_api('send_msg', **{ + 'message': f'{event.group_id}开始记录数据:'+loglist[event.group_id].page.id.replace("-", ''), + 'user_id': superuser, + }) + asyncio.sleep(5) async def masteroff(bot, event, id): if sendtomaster: - await bot.call_api('send_msg', **{ - 'message': f'{event.group_id}结束记录数据:{id}', - 'user_id': superuser, - }) + for superuser in superusers: + await bot.call_api('send_msg', **{ + 'message': f'{event.group_id}结束记录数据:{id}', + 'user_id': superuser, + }) + asyncio.sleep(5) \ No newline at end of file diff --git a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/logger.py b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/logger.py index ecaad76..2b563d8 100644 --- a/nonebot-plugin-magiadice/nonebot-plugin-magiadice/logger.py +++ b/nonebot-plugin-magiadice/nonebot-plugin-magiadice/logger.py @@ -1,5 +1,5 @@ import time -from notion.block import TextBlock, PageBlock, DividerBlock, NumberedListBlock, ImageBlock +from notion.block import TextBlock, PageBlock, DividerBlock, NumberedListBlock, ImageBlock,QuoteBlock from datetime import datetime import asyncio from notion.client import NotionClient @@ -7,6 +7,7 @@ import urllib.request import os import imghdr +from wcwidth import wcswidth token = get_driver().config.token client = NotionClient(token) @@ -30,6 +31,21 @@ async def init(self, sender) -> None: await self.login(sender, 'KP') else: await self.logdown(sender) + + async def logdown(self, id): + basepage.children + try: + self.page = await asyncio.to_thread(client.get_block, id) + except: + return '记录恢复失败' + self.player = {} + for child in self.page.children[0].children: + name, sender = child.title.split(':') + color = child.color + width=wcswidth(sender)+2 + self.player[sender] = [name, color,width] + self.createtime = time.time() + print(self.player) async def logon(self): await asyncio.to_thread(self.page.children.add_new, TextBlock, title='玩家信息:') @@ -44,32 +60,31 @@ async def login(self, sender, name): color = self.colorlist.pop() else: return '玩家人数超出最大值了喵!' - self.player[sender] = [name, color] + width=wcswidth(sender)+2 + self.player[sender] = [name, color,width] await asyncio.to_thread(self.page.children[0].children.add_new, TextBlock, title=f'{name}:{sender}', color=color) return f'{name}({sender})已加入游戏!' async def logup_text(self, sender, message): - match message[0]: - case '(': - ot = True - case '(': - ot = True - case '.': - return False - case _: - ot = False - if sender: - text = '<'+self.player[sender][0]+'>'+message - if ot: - await asyncio.to_thread(self.page.children.add_new, TextBlock, title=text, color='gray') - else: - await asyncio.to_thread(self.page.children.add_new, TextBlock, title=text, color=self.player[sender][1]) - else: - text = f''+message + if sender in self.player: + text = self.player[sender][0]+': '+message.replace(r'\n',r'\n'+r' '*self.player[sender][2]) + match message[0]: + case '('|'(': + await asyncio.to_thread(self.page.children.add_new, TextBlock, title=text, color='gray') + case '"'|'“': + await asyncio.to_thread(self.page.children.add_new, TextBlock, title=text, italic='True') + case '['|'【': + await asyncio.to_thread(self.page.children.add_new, QuoteBlock, title=message[1:-1]) + case '.'|'。': + return False + case _: + await asyncio.to_thread(self.page.children.add_new, TextBlock, title=text, color=self.player[sender][1]) + elif not sender: + text = f'BOT: '+message await asyncio.to_thread(self.page.children.add_new, TextBlock, title=text, color='brown') - async def logup_image(self, url): + async def logup_image(self, url,text): filepath = dirs+str(time.time()) await asyncio.to_thread(urllib.request.urlretrieve, url, filepath) type = imghdr.what(filepath) @@ -79,15 +94,6 @@ async def logup_image(self, url): await asyncio.to_thread(image.upload_file, newpath) os.remove(newpath) - async def logdown(self, id): - self.page = await asyncio.to_thread(client.get_block, id) - self.player = {} - for child in self.page.children[0].children: - sender, name = child.title.split(':') - color = child.color - self.player[sender] = [name, color] - self.createtime = time.time() - async def intronew(self, data): await asyncio.to_thread(self.page.children[1].children.add_new, NumberedListBlock, title=data) diff --git a/nonebot-plugin-magiadice/setup.py b/nonebot-plugin-magiadice/setup.py index 1f8f0d7..8bfa324 100644 --- a/nonebot-plugin-magiadice/setup.py +++ b/nonebot-plugin-magiadice/setup.py @@ -3,7 +3,7 @@ setup( name='nonebot_plugin_magiadice', packages=['nonebot-plugin-magiadice'], - version='0.1.2', + version='0.2.0', description=( '一个基于nonebot的跑团LOG插件' ), diff --git a/nonebot-plugin-send/nonebot-plugin-send/__init__.py b/nonebot-plugin-send/nonebot-plugin-send/__init__.py index c1e4db3..3827bf4 100644 --- a/nonebot-plugin-send/nonebot-plugin-send/__init__.py +++ b/nonebot-plugin-send/nonebot-plugin-send/__init__.py @@ -4,6 +4,7 @@ from nonebot.adapters.onebot.v11 import Bot, Message, GroupMessageEvent, PrivateMessageEvent from nonebot.params import CommandArg import asyncio + from nonebot import get_driver send = on_command('.send', priority=5) notice = on_command('.notice', priority=5, permission=SUPERUSER) @@ -17,13 +18,15 @@ async def send_receive(bot: Bot, event: GroupMessageEvent, args: Message = Comma 'group_id': event.group_id, }) group_name = group['group_name'] - superuser = get_driver().config.superusers[0] + timenow = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) sendmsg = timenow+'\n群聊:'+group_name+'\n发送者:'+name+'\n'+args_in - await bot.call_api('send_msg', **{ - 'message': sendmsg, - 'user_id': superuser, - }) + for superuser in get_driver().config.superusers: + await bot.call_api('send_msg', **{ + 'message': sendmsg, + 'user_id': superuser, + }) + asyncio.sleep(5) await send.finish(f'已经把意见传达给Master了喵!') diff --git a/nonebot-plugin-send/setup.py b/nonebot-plugin-send/setup.py index 4683ec2..5cf823c 100644 --- a/nonebot-plugin-send/setup.py +++ b/nonebot-plugin-send/setup.py @@ -3,7 +3,7 @@ setup( name='nonebot_plugin_send', packages=['nonebot-plugin-send'], - version='0.1.2', + version='0.1.3', description=( '一个基于nonebot的反馈通知插件' ), diff --git a/nonebot-plugin-ykt/nonebot-plugin-ykt/__init__.py b/nonebot-plugin-ykt/nonebot-plugin-ykt/__init__.py index 222f18a..8b95130 100644 --- a/nonebot-plugin-ykt/nonebot-plugin-ykt/__init__.py +++ b/nonebot-plugin-ykt/nonebot-plugin-ykt/__init__.py @@ -4,11 +4,12 @@ from nonebot import on_command from nonebot import get_driver from nonebot.adapters.onebot.v11 import Bot +import asyncio username = get_driver().config.username password = get_driver().config.password url = 'https://changjiang.yuketang.cn/v2/web/index' scheduler = require("nonebot_plugin_apscheduler").scheduler -superuser = get_driver().config.superusers[0] +superusers = get_driver().config.superusers async def send_success(lesson,meeting,video): for bot in nonebot.get_bots().values(): if meeting: @@ -17,10 +18,12 @@ async def send_success(lesson,meeting,video): message = lesson[0]+" 签到完成了喵!当前课程有视频直播喵!" else: message = lesson[0]+" 签到完成了喵!" - await bot.call_api('send_msg', **{ - 'message': message, - 'user_id': superuser - }) + for superuser in superusers: + await bot.call_api('send_msg', **{ + 'message': message, + 'user_id': superuser + }) + asyncio.sleep(5) diff --git a/nonebot-plugin-ykt/setup.py b/nonebot-plugin-ykt/setup.py index 3ec2285..ee0c91c 100644 --- a/nonebot-plugin-ykt/setup.py +++ b/nonebot-plugin-ykt/setup.py @@ -3,7 +3,7 @@ setup( name='nonebot_plugin_ykt', packages=['nonebot-plugin-ykt'], - version='0.1.2', + version='0.1.3', description=( '一个基于nonebot的雨课堂自动签到插件' ),