Skip to content

Commit

Permalink
Merge pull request #15 from Cypas/dev_cypas
Browse files Browse the repository at this point in the history
Dev cypas
  • Loading branch information
Cypas authored Feb 4, 2024
2 parents 412b3b9 + c7db0cf commit 719a206
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
14 changes: 7 additions & 7 deletions nonebot_plugin_splatoon3_schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
get_channel_info,
ChannelInfo,
cron_job,
push_job,
)

require("nonebot_plugin_apscheduler")
Expand Down Expand Up @@ -654,7 +655,7 @@ async def shutdown():
# 删除任务
bots = nonebot.get_bots()
for k in bots.keys():
job_id = f"sp3_push_cron_job_{k}"
job_id = f"sp3_schedule_push_job_{k}"
if scheduler.get_job(job_id):
scheduler.remove_job(job_id)
logger.info(f"remove job {job_id}!")
Expand All @@ -666,20 +667,19 @@ async def _(bot: Bot):
bot_adapter = bot.adapter.get_name()
bot_id = bot.self_id

logger.info(f" {bot_adapter} bot connect {bot_id} ".center(60, "-"))
# 防止bot重连时重复添加任务
job_id = f"sp3_push_cron_job_{bot_id}"
job_id = f"sp3_schedule_push_job_{bot_id}"
if scheduler.get_job(job_id):
scheduler.remove_job(job_id)
logger.info(f"remove job {job_id} first")

scheduler.add_job(
cron_job,
"interval",
minutes=1,
push_job,
trigger="cron",
hour="0,2,4,6,8,10,12,14,16,18,20,22",
id=job_id,
args=[bot, bot_adapter, bot_id],
misfire_grace_time=59,
misfire_grace_time=60,
coalesce=True,
max_instances=1,
)
Expand Down
1 change: 1 addition & 0 deletions nonebot_plugin_splatoon3_schedule/image/image_processer.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ def get_nso_help():
("m", "战绩将用户名打码"),
("e", "查询对战时各成员配装,徽章"),
("ss", "该战绩的nso页面截图"),
("i", "强制使用图片模式发送结果,而非qq平台默认的卡片"),
("多参数合并使用", "如/last c m 查询最近一场 打工 并 打码"),
]
text_card, card_h = drawer_nso_help_card(cmd_list, desc_list, text_width=text_width)
Expand Down
18 changes: 18 additions & 0 deletions nonebot_plugin_splatoon3_schedule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ async def cron_job(bot: Bot, bot_adapter: str, bot_id: str):
await send_push(bot, msg_source_id)


async def push_job(bot: Bot, bot_adapter: str, bot_id: str):
"""推送定时任务, 每两小时执行一次"""
push_jobs = db_control.get_all_push(bot_adapter, bot_id)

# 非kook,qqbot机器人不处理
if not isinstance(bot, (Kook_Bot, QQ_Bot)):
return

if len(push_jobs) > 0:
for push_job in push_jobs:
# active_push = push_job.get("active_push")
msg_source_type = push_job.get("msg_source_type")
msg_source_id = push_job.get("msg_source_id")
# 目前仅开启频道推送
if msg_source_type == "channel":
await send_push(bot, msg_source_id)


async def send_push(bot: Bot, source_id):
"""频道主动推送"""
logger.info(f"即将主动推送消息")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-splatoon3-schedule"
version = "1.5.3"
version = "1.5.4"
description = "一个基于nonebot2框架的splatoon3游戏日程查询插件"
authors = ["cypas <ayano05@outlook.com>"]
readme = "README.md"
Expand Down

0 comments on commit 719a206

Please sign in to comment.