This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
generated from A-kirami/nonebot-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,603 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.idea/ | ||
/.vscode/ | ||
/testnb2/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 student_2333 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from nonebot.plugin import PluginMetadata | ||
|
||
from .__main__ import * # type:ignore | ||
|
||
__version__ = '0.1.0' | ||
__plugin_meta__ = PluginMetadata( | ||
name='BAWiki', | ||
description='碧蓝档案Wiki插件', | ||
usage='', | ||
extra={ | ||
'menu_data': [ | ||
{ | ||
'func': '日程表', | ||
'trigger_method': '指令', | ||
'trigger_condition': 'ba日程表', | ||
'brief_des': '查看活动日程表', | ||
'detail_des': '查看当前未结束的卡池、活动以及起止时间' | ||
}, | ||
{ | ||
'func': '学生图鉴', | ||
'trigger_method': '指令', | ||
'trigger_condition': 'ba学生图鉴', | ||
'brief_des': '查询学生详情', | ||
'detail_des': '访问对应学生Wiki页面并截图\n' | ||
'指令示例:<ft color=(238,120,0)>ba学生图鉴 白子</ft>' | ||
}, | ||
], | ||
'menu_template': 'default' | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
from nonebot import on_command, logger | ||
from nonebot.adapters.onebot.v11 import Message, MessageSegment | ||
from nonebot.internal.matcher import Matcher | ||
from nonebot.params import CommandArg | ||
from nonebot_plugin_htmlrender import get_new_page | ||
from playwright.async_api import Page | ||
|
||
from .data_source import get_calender, get_stu_li | ||
from .util import format_timestamp | ||
|
||
handler_calender = on_command('ba日程表') | ||
|
||
|
||
@handler_calender.handle() | ||
async def _(matcher: Matcher): | ||
try: | ||
ret = await get_calender() | ||
except: | ||
logger.exception('获取日程表出错') | ||
return await matcher.finish('获取日程表出错,请检查后台输出') | ||
|
||
if not ret: | ||
return await matcher.finish('没有获取到数据') | ||
|
||
li = Message() | ||
for i in ret: | ||
des = i["title"] + (f"\n{x}" if (x := i["description"]) else "") | ||
des = des.replace('<br>', '') | ||
li += ( | ||
f'{format_timestamp(i["begin_at"])} - {format_timestamp(i["end_at"])}\n' | ||
f'{des}' | ||
) | ||
|
||
if pic := i['picture']: | ||
if (not pic.startswith('https:')) and (not pic.startswith('http:')): | ||
pic = 'https:' + pic | ||
li += MessageSegment.image(pic) | ||
|
||
li += '\n==============\n' | ||
|
||
li.pop(-1) | ||
|
||
await matcher.finish(li) | ||
|
||
|
||
stu_wiki = on_command('ba学生图鉴') | ||
|
||
|
||
@stu_wiki.handle() | ||
async def _(matcher: Matcher, arg: Message = CommandArg()): | ||
arg = arg.extract_plain_text().strip() | ||
if not arg: | ||
return await matcher.finish('请提供学生名称') | ||
|
||
try: | ||
ret = await get_stu_li() | ||
except: | ||
logger.exception('获取学生列表出错') | ||
return await matcher.finish('获取学生列表表出错,请检查后台输出') | ||
|
||
if not ret: | ||
return await matcher.finish('没有获取到学生列表数据') | ||
|
||
if not (sid := ret.get(arg)): | ||
return matcher.finish('未找到该学生') | ||
|
||
url = f'https://ba.gamekee.com/{sid}.html' | ||
await matcher.send(f'请稍等,正在截取Wiki页面……\n{url}') | ||
|
||
try: | ||
async with get_new_page() as page: # type:Page | ||
await page.goto(url) | ||
await page.wait_for_load_state('networkidle') | ||
|
||
# 删掉header | ||
await page.add_script_tag( | ||
content='document.getElementsByClassName("wiki-header")' | ||
'.forEach((v)=>{v.remove()})' | ||
) | ||
|
||
# 展开折叠的语音 | ||
folds = await page.query_selector_all( | ||
'xpath=//div[@class="fold-table-btn"]' | ||
) | ||
for i in folds: | ||
try: | ||
await i.click() | ||
except: | ||
pass | ||
|
||
img = await (await page.query_selector( | ||
'xpath=//div[@class="wiki-detail-body"]' | ||
)).screenshot() | ||
except: | ||
logger.exception(f'截取wiki页面出错 {url}') | ||
return await matcher.finish(f'截取页面出错,请检查后台输出') | ||
|
||
await matcher.finish(MessageSegment.image(img)) |
Oops, something went wrong.