Skip to content

Commit

Permalink
fix(daily_quests): 补上缺少的调用与测试
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Feb 27, 2024
1 parent 1f3aaab commit 8a84631
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/plugins/ff14/plugins/ff14_daily_quests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def daily_quests_handle(session: UserSession, args: Message = CommandArg()
content = args.extract_plain_text().strip()

if not content:
reply = get_daily_quests(session.user_id)
reply = await get_daily_quests(session.user_id)
await daily_quests_cmd.finish(reply)

if content == "配对":
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/ff14/plugins/ff14_daily_quests/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from nonebot_plugin_datastore import get_plugin_data
from nonebot_plugin_user import get_user_by_id

from .mogu import add_mogu_info

plugin_data = get_plugin_data()

type QUEST_DATA = dict[str, list[str]]
Expand All @@ -28,10 +30,11 @@ def save_quests_data(data: QUEST_DATA):
plugin_data.dump_json(data, filename)


def get_daily_quests(user_id: int) -> str:
async def get_daily_quests(user_id: int) -> str:
"""获取每日委托"""
data = get_quests_data()
quests = data.get(str(user_id), [])
quests = [await add_mogu_info(quest) for quest in quests]
return (
f"你的每日委托为:{', '.join(quests)}" if quests else "你还没有设置每日委托。"
)
Expand Down Expand Up @@ -71,6 +74,7 @@ async def get_daily_quests_pair(user_id: int) -> str:

msg = "与你每日委托相同的群友:\n"
for quest, users in pair.items():
quest = await add_mogu_info(quest)
if users:
msg += f"{quest}{await get_usernames(users)}\n"
else:
Expand Down
41 changes: 41 additions & 0 deletions tests/plugins/ff14/mogu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"喜悦神域欧芙洛绪涅": "7",
"希望之炮台:“塔”": "7",
"乐欲之所瓯博讷修道院": "7",
"影之国": "7",
"最终决战天幕魔导城": "7",
"灿烂神域阿格莱亚": "6",
"人偶军事基地": "6",
"封闭圣塔黎铎拉纳大灯塔": "6",
"复制工厂废墟": "5",
"失落之都拉巴纳斯塔": "5",
"禁忌城邦玛哈": "5",
"烈羽争锋:隐塞(机动战)": "3/5",
"纷争前线:昂萨哈凯尔(竞争战)": "3/5",
"纷争前线:荣誉野(碎冰战)": "3/5",
"纷争前线:尘封秘岩(争夺战)": "3/5",
"最终幻想末世终迹": "4",
"星海深幽寻因星晶镜": "4",
"创造环境极北造物院": "4",
"末日树海万相森国": "4",
"魔导神门巴别塔": "4",
"异形楼阁佐特塔": "4",
"神兵要塞帝国南方堡": "4",
"魔航船虚无方舟": "3",
"水晶塔 暗之世界": "3",
"水晶塔 希尔科斯塔": "3",
"水晶塔 古代人迷宫": "3",
"究极神兵破坏作战": "3",
"万魔殿 荒天之狱4": "2",
"万魔殿 荒天之狱3": "2",
"万魔殿 荒天之狱2": "2",
"万魔殿 荒天之狱1": "2",
"万魔殿 炼净之狱4": "2",
"万魔殿 炼净之狱3": "2",
"万魔殿 炼净之狱2": "2",
"万魔殿 炼净之狱1": "2",
"万魔殿 边境之狱4": "2",
"万魔殿 边境之狱3": "2",
"万魔殿 边境之狱2": "2",
"万魔殿 边境之狱1": "2"
}
24 changes: 21 additions & 3 deletions tests/plugins/ff14/test_daily_quests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import json
from pathlib import Path

import pytest
from nonebot.adapters.onebot.v11 import Bot, Message
from nonebug import App
from respx import MockRouter

from tests.fake import fake_group_message_event_v11


@pytest.fixture()
async def app(app: App, respx_mock: MockRouter):
path = Path(__file__).parent / "mogu.json"
with path.open("r", encoding="utf-8") as f:
data = json.load(f)

respx_mock.get(
"https://raw.githubusercontent.com/he0119/CoolQBot/master/src/plugins/ff14/plugins/ff14_daily_quests/mogu.json"
).respond(json=data)

return app


async def test_get_daily_quests(app: App):
"""获取每日委托"""
from src.plugins.ff14.plugins.ff14_daily_quests import daily_quests_cmd
Expand All @@ -24,7 +42,7 @@ async def test_set_daily_quests(app: App):
async with app.test_matcher(daily_quests_cmd) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event_v11(
message=Message("/每日委托 乐园都市笑笑镇,伊弗利特歼灭战, 神龙歼灭战")
message=Message("/每日委托 乐园都市笑笑镇,伊弗利特歼灭战, 影之国")
)

ctx.receive_event(bot, event)
Expand All @@ -33,7 +51,7 @@ async def test_set_daily_quests(app: App):
"与你每日委托相同的群友:\n"
"乐园都市笑笑镇:无\n"
"伊弗利特歼灭战:无\n"
"神龙歼灭战:无",
"影之国(7):无",
True,
)
ctx.should_finished(daily_quests_cmd)
Expand All @@ -44,7 +62,7 @@ async def test_set_daily_quests(app: App):

ctx.receive_event(bot, event)
ctx.should_call_send(
event, "你的每日委托为:乐园都市笑笑镇, 伊弗利特歼灭战, 神龙歼灭战", True
event, "你的每日委托为:乐园都市笑笑镇, 伊弗利特歼灭战, 影之国(7)", True
)
ctx.should_finished(daily_quests_cmd)

Expand Down

0 comments on commit 8a84631

Please sign in to comment.