Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
添加定时任务配置项
修复定时任务导致其它处理器阻塞的问题 [@issue/30](#30) [@zx-issue/9](NumberSir/zhenxun_arktools#9)
修复猜干员无法判断重复猜的问题 [@zx-issue/10](NumberSir/zhenxun_arktools#10)
修复猜干员结果图不按顺序绘制的问题
  • Loading branch information
NumberSir committed Feb 19, 2023
1 parent 37fe9e1 commit d2457bd
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 128 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ nonebot_plugin_arktools
arknights_baidu_api_key="xxx" # 【必填】百度 OCR API KEY
arknights_baidu_secret_key="xxx" # 【必填】百度 OCR SECRET KEY

github_raw="xxx" # 默认为 https://raw.githubusercontent.com,如有镜像源可以替换
github_site="xxx" # 默认为 https://github.com,如有镜像源可以替换
github_raw="https://raw.githubusercontent.com" # 默认为 https://raw.githubusercontent.com,如有镜像源可以替换
github_site="https://github.com" # 默认为 https://github.com,如有镜像源可以替换

announce_push_switch=False # 是否自动推送舟舟最新公告,默认为 False; True 为开启自动检测
announce_push_interval=1 # 自动推送最新公告的检测间隔,上述开关开启时有效,默认为 1 分钟

sanity_notify_switch=False # 是否自动检测理智提醒,默认为 False; True 为开启自动检测
sanity_notify_interval=10 # 自动检测理智提醒的检测间隔,上述开关开启时有效,默认为 10 分钟
...
```
各配置项的含义如上。

## 指令
<details>
<summary>详细指令</summary>
<summary>点击展开</summary>

### 详细指令
使用以下指令触发,需加上指令前缀
Expand Down Expand Up @@ -149,7 +155,7 @@ xxx/yyy 代表 xxx 或 yyy

# 图片示例
<details>
<summary>图片们</summary>
<summary>点击展开</summary>

## 图片们
<div align="left">
Expand Down Expand Up @@ -203,6 +209,15 @@ xxx/yyy 代表 xxx 或 yyy


# 更新日志
<details>
<summary>点击展开</summary>

> 2023-02-19 v1.0.9
> - 添加定时任务配置项
> - 修复定时任务导致其它处理器阻塞的问题 [@issue/30](https://github.com/NumberSir/nonebot_plugin_arktools/issues/30) [@zx-issue/9](https://github.com/NumberSir/zhenxun_arktools/issues/9)
> - 修复猜干员无法判断重复猜的问题 [@zx-issue/10](https://github.com/NumberSir/zhenxun_arktools/issues/10)
> - 修复猜干员结果图不按顺序绘制的问题
>
> 2023-02-16 v1.0.8
> - 移除 `nb plugin install` 安装命令,无法识别最新版本号 [@issue/28](https://github.com/NumberSir/nonebot_plugin_arktools/issues/28)
> - 修改百度 OCR 配置项名称 [@issue/29](https://github.com/NumberSir/nonebot_plugin_arktools/issues/29)
Expand Down Expand Up @@ -281,3 +296,5 @@ xxx/yyy 代表 xxx 或 yyy
>
> 2022-05-24 v0.1.0
> - 添加了查询今日开放资源关卡的功能
</details>
1 change: 1 addition & 0 deletions nonebot_plugin_arktools/src/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .path_config import *
from .ocr_config import *
from .proxy_config import *
from .scheduler_config import *
1 change: 1 addition & 0 deletions nonebot_plugin_arktools/src/configs/ocr_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""百度ocr设置"""
from pydantic import BaseModel, Extra


Expand Down
2 changes: 2 additions & 0 deletions nonebot_plugin_arktools/src/configs/path_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""路径设置"""
from pydantic import BaseModel, Extra
from pathlib import Path

SRC_PATH = Path(__file__).absolute().parent.parent


class PathConfig(BaseModel, extra=Extra.ignore):
"""游戏资源 & 数据库路径设置"""
arknights_data_path: Path = SRC_PATH.parent / "data"
arknights_font_path: Path = arknights_data_path / "fonts"
arknights_gamedata_path: Path = arknights_data_path / "arknights" / "gamedata"
Expand Down
1 change: 1 addition & 0 deletions nonebot_plugin_arktools/src/configs/proxy_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""代理设置"""
from pydantic import BaseModel, Extra


Expand Down
16 changes: 16 additions & 0 deletions nonebot_plugin_arktools/src/configs/scheduler_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""定时任务设置"""
from pydantic import BaseModel, Extra


class SchedulerConfig(BaseModel, extra=Extra.ignore):
"""定时任务相关配置"""
announce_push_switch: bool = False # 自动获取 & 推送舟舟最新公告开关
announce_push_interval: int = 1 # 间隔多少分钟运行一次

sanity_notify_switch: bool = False # 检测理智提醒开关
sanity_notify_interval: int = 10 # 间隔多少分钟运行一次


__all__ = [
"SchedulerConfig"
]
1 change: 0 additions & 1 deletion nonebot_plugin_arktools/src/core/models_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ async def get_tags_for_open_recruitment(self) -> List[str]:
# 猜干员小游戏用



class Attributes:
"""面板"""
def __init__(self, cht: Character = None, data: Dict[str, Any] = None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GuessCharacter:
def __init__(self, cht: "Character"):
self._answer: "Character" = cht # 目标
self._times: int = 8 # 能猜的次数
self._guessed: Set["Character"] = set() # 猜过的
self._guessed: List["Character"] = [] # 猜过的

self._block_size = (40, 40) # 表情块尺寸
self._block_padding = (10, 10) # 表情块之间间距
Expand All @@ -55,9 +55,9 @@ async def guess(self, cht: Character) -> GuessResult:
"""每次猜完"""
if not await self.is_character_legal(cht.name):
return GuessResult.ILLEGAL
if cht in self._guessed:
if cht.name in {_.name for _ in self._guessed}:
return GuessResult.DUPLICATE
self._guessed.add(cht)
self._guessed.append(cht)

if cht.name == self._answer.name:
return GuessResult.WIN
Expand Down Expand Up @@ -175,7 +175,7 @@ def times(self) -> int:
return self._times

@property
def guessed(self) -> Set["Character"]:
def guessed(self) -> List["Character"]:
"""猜过的干员"""
return self._guessed

Expand Down
129 changes: 58 additions & 71 deletions nonebot_plugin_arktools/src/tool_announce_push/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""游戏公告推送"""
from io import BytesIO
from pathlib import Path

from aiofiles import open as aopen
from nonebot import logger, get_bot, on_command
from nonebot import logger, get_bot, on_command, get_driver
from nonebot.adapters.onebot.v11 import Bot, MessageSegment, Message
from nonebot.exception import ActionFailed
from nonebot.params import CommandArg
Expand All @@ -12,8 +11,11 @@
from nonebot_plugin_htmlrender import html_to_pic

from .data_source import get_news
from ..configs.scheduler_config import SchedulerConfig
from ..core.database import RSSNewsModel

scfg = SchedulerConfig.parse_obj(get_driver().config.dict())

latest_news = on_command("方舟最新公告")
add_group = on_command("添加方舟推送群", aliases={"ADDGROUP"})
del_group = on_command("删除方舟推送群", aliases={"DELGROUP"})
Expand All @@ -23,38 +25,33 @@
@latest_news.handle()
async def _():
news = await RSSNewsModel.all().order_by("time").first()
if not news:
await latest_news.finish("数据库里尚未有任何公告哦!", at_sender=True)
await latest_news.send("获取最新公告中 ...")
if not news:
try:
news_list = await get_news()
except:
logger.error("获取最新公告出错")
else:
news = news_list[0]

image = await html_to_pic(
html=news.content
)
try:
await latest_news.finish(
Message(
MessageSegment.image(image)
+ f"发布时间: {news.time.__str__()[:-6]}"
+ "舟舟发布了一条新公告"
f"\n发布时间: {news.time.__str__()[:10]}"
f"\n{news.link}"
)
)
except ActionFailed as e:
await latest_news.finish(
"公告截图失败..."
f"\n发布时间: {news.time.__str__()[:-6]}"
f"\n发布时间: {news.time.__str__()[:10]}"
f"\n{news.link}"
)
# text2image(
# f"[color=red]{new.title}[/color]"
# f"\n{new.content}"
# f"\n{new.time.__str__()[:-7]}",
# max_width=1024
# ).save(output, "png")
# await latest_news.finish(
# Message(
# MessageSegment.image(output)
# + new.link
# )
# )


@add_group.handle()
Expand Down Expand Up @@ -115,62 +112,52 @@ async def _():

@scheduler.scheduled_job(
"interval",
minutes=1,
minutes=scfg.announce_push_interval,
)
async def _():
logger.info("checking rss news...")
try:
bot: Bot = get_bot()
except ValueError:
return

try:
news_list = await get_news()
except: # TODO
logger.error("获取最新公告出错")
return

if not news_list:
return

if not (Path(__file__).parent / "groups.txt").exists():
async with aopen(Path(__file__).parent / "groups.txt", "w") as fp:
if scfg.announce_push_switch:
logger.info("checking rss news...")
try:
bot: Bot = get_bot()
except ValueError:
pass
async with aopen(Path(__file__).parent / "groups.txt", "r") as fp:
groups = (await fp.read()).split()
if not groups:
return

for news in news_list:
for group in groups:
output = BytesIO()
# text2image(
# f"[color=red]{new.title}[/color]"
# f"\n{new.content}"
# f"\n{new.time.__str__()[:-7]}",
# max_width=1024
# ).save(output, "png")
image = await html_to_pic(
html=news.content
)
try:
await bot.send_group_msg(
group_id=int(group),
message=Message(
MessageSegment.image(image)
+ f"发布时间: {news.time.__str__()[:-6]}"
f"\n{news.link}"
)
)
except ActionFailed as e:
await bot.send_group_msg(
group_id=int(group),
message=Message(
"公告截图失败..."
f"\n发布时间: {news.time.__str__()[:-6]}"
f"\n{news.link}"
)
)

try:
news_list = await get_news()
except: # TODO
logger.error("获取最新公告出错")
else:
if news_list:
if not (Path(__file__).parent / "groups.txt").exists():
async with aopen(Path(__file__).parent / "groups.txt", "w") as fp:
pass
async with aopen(Path(__file__).parent / "groups.txt", "r") as fp:
groups = (await fp.read()).split()
if groups:
for news in news_list:
for group in groups:
image = await html_to_pic(
html=news.content
)
try:
await bot.send_group_msg(
group_id=int(group),
message=Message(
MessageSegment.image(image)
+ "舟舟发布了一条新公告"
f"\n发布时间: {news.time.__str__()[:10]}"
f"\n{news.link}"
)
)
except ActionFailed as e:
await bot.send_group_msg(
group_id=int(group),
message=Message(
"公告截图失败..."
f"\n发布时间: {news.time.__str__()[:10]}"
f"\n{news.link}"
)
)


__plugin_meta__ = PluginMetadata(
Expand Down
8 changes: 0 additions & 8 deletions nonebot_plugin_arktools/src/tool_announce_push/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,3 @@ async def get_news() -> Optional[List["RSSNewsModel"]]:
async def get_bilibili_dynamics():
"""B站动态"""
...

# def get_plain_text(raw_text: str):
# """处理掉html标签"""
# raw_text = raw_text.replace("<br />", "\n").replace("<p>", "\n")
# tags = re.findall("<.*?>", raw_text)
# for _ in tags:
# raw_text = raw_text.replace(_, "")
# return unescape(raw_text)
Loading

0 comments on commit d2457bd

Please sign in to comment.