Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Aug 7, 2022
1 parent 0edf02b commit 589bf61
Show file tree
Hide file tree
Showing 12 changed files with 1,603 additions and 57 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ jobs:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@master
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea/
/.vscode/
/testnb2/
21 changes: 21 additions & 0 deletions LICENSE
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.
102 changes: 69 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
<!-- markdownlint-disable MD033 MD036 MD041 -->

<div align="center">
<a href="https://v2.nonebot.dev/store"><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
<br>
<p><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg" width="240" alt="NoneBotPluginText"></p>
<a href="https://v2.nonebot.dev/store"><img src="readme/nonebot-plugin-bawiki.png" width="200" height="200" alt="BAWiki"></a>
</div>

<div align="center">

# nonebot-plugin-example

_✨ NoneBot 插件简单描述 ✨_
# NoneBot-Plugin-BAWiki

_✨ 基于 NoneBot2 的碧蓝档案 Wiki 插件 ✨_

<a href="./LICENSE">
<img src="https://img.shields.io/github/license/owner/nonebot-plugin-example.svg" alt="license">
<img src="https://img.shields.io/github/license/lgc2333/nonebot-plugin-bawiki.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot-plugin-example">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-example.svg" alt="pypi">
<a href="https://pypi.python.org/pypi/nonebot-plugin-bawiki">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-bawiki.svg" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
<a href="https://pypi.python.org/pypi/nonebot-plugin-bawiki">
<img src="https://img.shields.io/pypi/dm/nonebot-plugin-bawiki" alt="pypi download">
</a>

</div>

这是一个 nonebot2 插件项目的模板库, 你可以直接使用本模板创建你的 nonebot2 插件项目的仓库

模板库使用方法:
1. 点击仓库中的 "Use this template" 按钮, 输入仓库名与描述, 点击 " Create repository from template" 创建仓库
2. 在创建好的新仓库中, 在 "Add file" 菜单中选择 "Create new file", 在新文件名处输入`LICENSE`, 此时在右侧会出现一个 "Choose a license template" 按钮, 点击此按钮选择开源协议模板, 然后在最下方提交新文件到主分支
3. 全局替换`owner`为仓库所有者ID; 全局替换`nonebot-plugin-example`为插件名; 全局替换`nonebot_plugin_example`为包名; 修改 python 徽标中的版本为你插件的运行所需版本
4. 修改 README 中的插件名和插件描述, 并在下方填充相应的内容

## 📖 介绍

这里是插件的详细介绍部分
一个碧蓝档案的 Wiki 插件,目前写了活动日程和学生图鉴,数据来源为 [GameKee](https://ba.gamekee.com/)

## 💿 安装

<details>
<summary>使用 nb-cli 安装</summary>
<details open>
<summary>【推荐】使用 nb-cli 安装</summary>
在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装

nb plugin install nonebot-plugin-example
nb plugin install nonebot-plugin-bawiki

</details>

Expand All @@ -50,56 +44,98 @@ _✨ NoneBot 插件简单描述 ✨_
<details>
<summary>pip</summary>

pip install nonebot-plugin-example
pip install nonebot-plugin-bawiki

</details>
<details>
<summary>pdm</summary>

pdm add nonebot-plugin-example
pdm add nonebot-plugin-bawiki

</details>
<details>
<summary>poetry</summary>

poetry add nonebot-plugin-example
poetry add nonebot-plugin-bawiki

</details>
<details>
<summary>conda</summary>

conda install nonebot-plugin-example
conda install nonebot-plugin-bawiki

</details>

打开 nonebot2 项目的 `bot.py` 文件, 在其中写入

nonebot.load_plugin('nonebot_plugin_example')
nonebot.load_plugin('nonebot_plugin_bawiki')

</details>

<details>
<summary>从 github 安装</summary>
在 nonebot2 项目的插件目录下, 打开命令行, 输入以下命令克隆此储存库

git clone https://github.com/owner/nonebot-plugin-example.git
git clone https://github.com/lgc2333/nonebot-plugin-bawiki.git

打开 nonebot2 项目的 `bot.py` 文件, 在其中写入

nonebot.load_plugin('src.plugins.nonebot_plugin_example')
nonebot.load_plugin('src.plugins.nonebot_plugin_bawiki')

</details>

## ⚙️ 配置

暂无配置

<!--
在 nonebot2 项目的`.env`文件中添加下表中的必填配置
| 配置项 | 必填 | 默认值 | 说明 |
|:-----:|:----:|:----:|:----:|
| 配置项1 | 是 | 无 | 配置说明 |
| 配置项2 | 否 | 无 | 配置说明 |
-->

## 🎉 使用

### 指令表
| 指令 | 权限 | 需要@ | 范围 | 说明 |
|:-----:|:----:|:----:|:----:|:----:|
| 指令1 | 主人 || 私聊 |配置说明 |
| 指令2 | 群员 || 群聊 |配置说明 |

| 指令 | 权限 | 需要@ | 范围 | 说明 |
| :----------: | :--: | :---: | :--: | :-------------------------------------------: |
| `ba日程表` ||| 均可 ||
| `ba学生图鉴` ||| 均可 | 需要在后面加上学生名字,比如`ba学生图鉴 白子` |

待更新

### 效果图
如果有效果图的话

<details>
<summary>长图,点击展开</summary>

![example](readme/example.png)

</details>

## 📞 联系

QQ:3076823485
Telegram:[@lgc2333](https://t.me/lgc2333)
吹水群:[1105946125](https://jq.qq.com/?_wv=1027&k=Z3n1MpEp)
邮箱:<lgc2333@126.com>

## 💰 赞助

感谢大家的赞助!你们的赞助将是我继续创作的动力!

- [爱发电](https://afdian.net/@lgc2333)
- <details>
<summary>赞助二维码(点击展开)</summary>

![讨饭](https://raw.githubusercontents.com/lgc2333/ShigureBotMenu/master/src/imgs/sponsor.png)

</details>

## 📝 更新日志

30 changes: 30 additions & 0 deletions nonebot_plugin_bawiki/__init__.py
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'
}
)
98 changes: 98 additions & 0 deletions nonebot_plugin_bawiki/__main__.py
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))
Loading

0 comments on commit 589bf61

Please sign in to comment.