Skip to content

Commit

Permalink
Merge Dev (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fllesser authored Jan 9, 2025
1 parent e84f3ce commit f8f3b1e
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 130 deletions.
78 changes: 21 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,36 @@

<div align="center">

# nonebot-plugin-PPPPP
# nonebot-plugin-fortnite

_✨ NoneBot 插件简单描述 ✨_
_✨ NoneBot Fortnite Plguin ✨_


<a href="./LICENSE">
<img src="https://img.shields.io/github/license/owner/nonebot-plugin-PPPPP.svg" alt="license">
<img src="https://img.shields.io/github/license/fllesser/nonebot-plugin-fortnite.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot-plugin-PPPPP">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-PPPPP.svg" alt="pypi">
<a href="https://pypi.python.org/pypi/nonebot-plugin-fortnite">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-fortnite.svg" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="python">

</div>

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

<details open>
<summary>模板库使用方法</summary>

1. 点击 [![start-course](https://user-images.githubusercontent.com/1221423/235727646-4a590299-ffe5-480d-8cd5-8194ea184546.svg)](https://github.com/new?template_owner=fllesser&template_name=nonebot-plugin-template&owner=%40me&name=nonebot-plugin-&visibility=public) 创建仓库
2. 在创建好的新仓库中, 在 "Add file" 菜单中选择 "Create new file", 在新文件名处输入`LICENSE`, 此时在右侧会出现一个 "Choose a license template" 按钮, 点击此按钮选择开源协议模板, 然后在最下方提交新文件到主分支
3. 全局替换`owner`为仓库所有者ID; 全局替换`PPPPP`为插件名; 全局替换`ppppp`为包名; 修改 python 徽标中的版本为你插件的运行所需版本
4. 修改 README 中的插件名和插件描述, 并在下方填充相应的内容

</details>

> [!NOTE]
> 模板库中自带了一个发布工作流, 你可以使用此工作流自动发布你的插件到 pypi
<details>
<summary>配置发布工作流</summary>

1. 前往 https://pypi.org/manage/account/#api-tokens 并创建一个新的 API 令牌。创建成功后不要关闭页面,不然你将无法再次查看此令牌。
2. 在单独的浏览器选项卡或窗口中,打开 [Actions secrets and variables](./settings/secrets/actions) 页面。你也可以在 Settings - Secrets and variables - Actions 中找到此页面。
3. 点击 New repository secret 按钮,创建一个名为 `PYPI_API_TOKEN` 的新令牌,并从第一步复制粘贴令牌。

</details>

> [!IMPORTANT]
> 这个发布工作流需要 pyproject.toml 文件, 并且只支持 [PEP 621](https://peps.python.org/pep-0621/) 标准的 pyproject.toml 文件
<details>
<summary>触发发布工作流</summary>
从本地推送任意 tag 即可触发。

创建 tag:

git tag <tag_name>

推送本地所有 tag:

git push origin --tags

</details>

## 📖 介绍

这里是插件的详细介绍部分
堡垒之夜战绩/季卡/商城/vb图查询插件

自用插件,发来凑个数(万一玩nb的也有人玩堡垒的呢

## 💿 安装

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

nb plugin install nonebot-plugin-PPPPP
nb plugin install nonebot-plugin-fortnite --upgrade

</details>

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

pip install nonebot-plugin-PPPPP
pip install nonebot-plugin-fortnite
</details>
<details>
<summary>pdm</summary>

pdm add nonebot-plugin-PPPPP
pdm add nonebot-plugin-fortnite
</details>
<details>
<summary>poetry</summary>

poetry add nonebot-plugin-PPPPP
poetry add nonebot-plugin-fortnite
</details>
<details>
<summary>conda</summary>

conda install nonebot-plugin-PPPPP
conda install nonebot-plugin-fortnite
</details>

打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分追加写入

plugins = ["nonebot_plugin_ppppp"]
plugins = ["nonebot_plugin_fortnite"]

</details>

Expand All @@ -111,14 +74,15 @@ _✨ NoneBot 插件简单描述 ✨_

| 配置项 | 必填 | 默认值 | 说明 |
|:-----:|:----:|:----:|:----:|
| 配置项1 ||| 配置说明 |
| 配置项2 ||| 配置说明 |
| fortnite_api_key || '' | api-key |

## 🎉 使用
### 指令表
| 指令 | 权限 | 需要@ | 范围 | 说明 |
|:-----:|:----:|:----:|:----:|:----:|
| 指令1 | 主人 || 私聊 | 指令说明 |
| 指令2 | 群员 || 群聊 | 指令说明 |
### 效果图
如果有效果图的话
| [生涯]战绩 | - || - | 顾名思义 |
| [生涯]季卡 | - || - | 顾名思义 |
| 商城 | - || - | 顾名思义 |
| vb图 | - || - | 顾名思义 |
| 更新商城 | 主人 || - | 顾名思义 |
| 更新vb图 | 主人 || - | 顾名思义 |
18 changes: 15 additions & 3 deletions nonebot_plugin_fortnite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@
from nonebot.log import logger
from nonebot.plugin import PluginMetadata


require("nonebot_plugin_apscheduler")
from nonebot_plugin_apscheduler import scheduler

from .config import Config
from .matcher import *
from .pve import screenshot_vb_img
from .shop import screenshot_shop_img

__plugin_meta__ = PluginMetadata(
name="堡垒之夜游戏插件",
description="堡垒之夜战绩,季卡,商城,vb图查询",
usage="",
usage="季卡/生涯季卡/战绩/生涯战绩/商城/vb图",
type="application",
config=Config,
homepage="https://github.com/fllesser/nonebot-plugin-fortnite",
supported_adapters={ "~onebot.v11" }
supported_adapters=None
)



@scheduler.scheduled_job(
"cron",
id = 'fortnite',
hour = 8,
minute = 5,
)
async def _():
await screenshot_shop_img()
await screenshot_vb_img()
11 changes: 6 additions & 5 deletions nonebot_plugin_fortnite/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from pydantic import BaseModel
from typing import Optional
from nonebot import get_plugin_config
from nonebot import get_plugin_config, require

# from pathlib import Path
# require("nonebot_plugin_localstore")
# import nonebot_plugin_localstore as store
from pathlib import Path
require("nonebot_plugin_localstore")
import nonebot_plugin_localstore as store


class Config(BaseModel):
fortnite_api_key: Optional[str] = ""

fconfig: Config = get_plugin_config(Config)

# cache_dir: Path = store.get_plugin_cache_dir()
cache_dir: Path = store.get_plugin_cache_dir()
data_dir: Path = store.get_plugin_data_dir()
65 changes: 53 additions & 12 deletions nonebot_plugin_fortnite/matcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import re

from pathlib import Path
from nonebot import require
from nonebot.plugin.on import on_command
from nonebot.permission import SUPERUSER

require("nonebot_plugin_uninfo")
from nonebot_plugin_uninfo import (
Expand All @@ -23,13 +25,16 @@
)
from nonebot_plugin_alconna.uniseg import (
UniMessage,
Image
Image,
Text
)

from .stats import (
get_level,
get_stats_image
)
from .pve import screenshot_vb_img, vb_file
from .shop import screenshot_shop_img, shop_file

timewindow_prefix = ["生涯", ""]
name_args = Args["name?", str]
Expand Down Expand Up @@ -65,25 +70,61 @@ async def _(
matcher.set_path_arg('name', match.group(1))


name_prompt = UniMessage.template("{:At(user, $event.get_user_id())} 请发送游戏名称(群昵称设置为id:name/ID name可快速查询)")
name_prompt = UniMessage.template("{:At(user, $event.get_user_id())} 请发送游戏名称\n群昵称设置如下可快速查询:\n id:name\n ID name")

@battle_pass.got_path('name', prompt=name_prompt)
async def _(arp: Arparma, name: str):
level_info = await get_level(name, arp.header_match.result)
await battle_pass.finish(level_info)
header = arp.header_match.result
receipt = await UniMessage.text(f'正在查询 {name}{header},请稍后...').send()
level_info = await get_level(name, header)
await battle_pass.send(level_info)
await receipt.recall(delay=1)

@stats.got_path('name', prompt=name_prompt)
async def _(arp: Arparma, name: str):
stats_img = await get_stats_image(name, arp.header_match.result)
if stats_img.startswith('http'):
res = await UniMessage(Image(url=stats_img)).export()
else:
res = stats_img
await stats.finish(res)

header = arp.header_match.result
receipt = await UniMessage.text(f'正在查询 {name}{header},请稍后...').send()
res = await get_stats_image(name, header)
if isinstance(res, Path):
res = await UniMessage(Image(path=res)).export()
await stats.send(res)
await receipt.recall(delay=1)

shop = on_command('商城')

@shop.handle()
async def _():
await shop.finish('https://www.fortnite.com/item-shop?lang=zh-Hans')
await shop.send(await UniMessage(Image(path=shop_file) + Text('https://www.fortnite.com/item-shop?lang=zh-Hans')).export())
# await shop.finish('https://www.fortnite.com/item-shop?lang=zh-Hans' + "\n\n" + 'https://fortnite.gg/shop')

update_shop = on_command('更新商城', permission=SUPERUSER)

@update_shop.handle()
async def _():
try:
receipt = await UniMessage.text("正在更新商城,请稍后...").send()
file = await screenshot_shop_img()
await update_vb.send(await UniMessage(Text('手动更新商城成功') + Image(path=file)).export())
except Exception as e:
await update_vb.send(f'手动更新商城失败 | {e}')
finally:
await receipt.recall(delay=1)

vb = on_command('vb图', aliases={"VB图"})

@vb.handle()
async def _():
await vb.finish(await UniMessage(Image(path=vb_file)).export())

update_vb = on_command('更新vb图', permission=SUPERUSER)

@update_vb.handle()
async def _():
try:
receipt = await UniMessage.text("正在更新vb图,请稍后...").send()
file = await screenshot_vb_img()
await update_vb.send(await UniMessage(Text('手动更新vb图成功') + Image(path=file)).export())
except Exception as e:
await update_vb.send(f'手动更新vb图失败 | {e}')
finally:
await receipt.recall(delay=1)
19 changes: 15 additions & 4 deletions nonebot_plugin_fortnite/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
def exception_handler():
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
async def wrapper(*args, **kwargs):
res = None
try:
res = func(*args, **kwargs)
res = await func(*args, **kwargs)
except Exception as e:
res = e.message
e = str(e)
if "public" in e:
res = "战绩未公开"
elif "exist" in e:
res = "用户不存在"
elif "match" in e:
res = "该玩家当前赛季没有进行过任何对局"
elif "timed out" in e:
res = "请求超时, 请稍后再试"
elif "failed to fetch" in e:
res = "拉取账户信息失败, 稍后再试"
else:
res = f"未知错误: {e}"
finally:
return res
return wrapper
return decorator

Loading

0 comments on commit f8f3b1e

Please sign in to comment.