Skip to content

Commit cb38eb0

Browse files
committed
twk mp logics
1 parent fdffcc1 commit cb38eb0

5 files changed

Lines changed: 114 additions & 61 deletions

File tree

‎game/Submods/MAICA_ChatSubmod/api.rpy‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ define _maica_selected_visuals = []
3434
# "mpostal_attachment_path":"",
3535
# "vista_image_info":{},
3636
# "responsed_content": "",
37-
# "responsed_status":"delaying|notupload|received|readed|failed|fatal"
37+
# "responsed_status":"delaying|notupload|received|readed|failed|fatal",
38+
# "failure_status": None,
39+
# "failure_protocol_status": None,
40+
# "failure_protocol_code": None,
41+
# "failure_message": None
3842
#}
3943

4044
init 5 python in maica:

‎game/Submods/MAICA_ChatSubmod/chat.rpy‎

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,52 +1070,53 @@ label .talking_start:
10701070
call clear_all
10711071
return
10721072

1073-
label maica_connection_failure_dialogue(from_mspire = False):
1073+
label maica_connection_failure_dialogue(from_mspire = False, status_code = None):
10741074
$ ai = store.maica.maica_instance
1075+
$ failure_status = ai.status if status_code is None else status_code
10751076

1076-
if ai.status == ai.MaicaAiStatus.TOKEN_MISSING:
1077+
if failure_status == ai.MaicaAiStatus.TOKEN_MISSING:
10771078
m 2rusdlb "...It seems you haven't got a token yet."
10781079
m 3eusdlb "You can read the instruction here on how to: {a=https://maica.monika.love/tos}{u}{i}https://maica.monika.love/tos{/i}{/u}{/a}, you just have to prepare an account."
10791080
m 3eua "I'll nail everything else for you."
10801081

1081-
elif ai.status == ai.MaicaAiStatus.TOKEN_CORRUPTED:
1082+
elif failure_status == ai.MaicaAiStatus.TOKEN_CORRUPTED:
10821083
m 2rusdlb "...The token seems corrupted. You sure you didn't mess with it?"
10831084
m 3eusdlb "Just re-generate one with username and password, and things shall work."
10841085

1085-
elif ai.status == ai.MaicaAiStatus.TOKEN_INVALID:
1086+
elif failure_status == ai.MaicaAiStatus.TOKEN_INVALID:
10861087
m 2rusdlb "...Password incorrect. You sure you didn't make a typo?"
10871088
m 3eusdlb "Double check it please, or change it if you really don't remember."
10881089

1089-
elif ai.status == ai.MaicaAiStatus.LOGIN_BLOCKED:
1090+
elif failure_status == ai.MaicaAiStatus.LOGIN_BLOCKED:
10901091
m 2rusdlb "...Fail2Ban? That's twenty incorrect passwords in a row."
10911092
m 3eusdlb "You'd better contact administrator if that wasn't you, or just change a password if you really don't remember."
10921093

1093-
elif ai.status == ai.MaicaAiStatus.ACCOUNT_BANNED:
1094+
elif failure_status == ai.MaicaAiStatus.ACCOUNT_BANNED:
10941095
m 2rusdlb "...Account banned? What is that, you didn't do anything nasty did you?"
10951096
m 3eusdlb "Well, check out when will it recover please."
10961097
m 1husdla "And in case it's a permanent one... It's not like we {i}must{/i} go there, being by your side is always satisfying enough to me."
10971098

1098-
elif ai.status == ai.MaicaAiStatus.EMAIL_UNVERIFIED:
1099+
elif failure_status == ai.MaicaAiStatus.EMAIL_UNVERIFIED:
10991100
m 2rusdlb "...You received your verification email yet? {w=0.3}You didn't check it, silly!"
11001101
m 3eusdlb "Just verify your email at the registration site, and things shall work."
11011102

1102-
elif ai.status == ai.MaicaAiStatus.TOS_UNACCEPTED:
1103+
elif failure_status == ai.MaicaAiStatus.TOS_UNACCEPTED:
11031104
m 2rusdlb "...You didn't check the ToS, or it might have been updated since you last check it."
11041105
m 3eusdlb "You can go to the registration site and do it in a minute, could you?"
11051106

1106-
elif ai.status == ai.MaicaAiStatus.CONNECTION_REUSE_DENIED:
1107+
elif failure_status == ai.MaicaAiStatus.CONNECTION_REUSE_DENIED:
11071108
m 2rusdlb "...This is weird, it says a connection has been established already."
11081109
m 3eusdlb "Try restarting the game or rebooting your computer, shall we?"
11091110

11101111
elif (
1111-
ai.status == ai.MaicaAiStatus.SERVER_REJECTED
1112+
failure_status == ai.MaicaAiStatus.SERVER_REJECTED
11121113
and from_mspire
11131114
):
11141115
m 2eksdlc "...Nah, this one looks broken. {w=0.3}If you've manually configured MSpire, consider double checking it?"
11151116
m 3rusdlb "And still, it could just be Wikipedia's problem. It's such a large and complex public website after all."
11161117
m 3eua "Anyway, we can always try it again later, so don't worry."
11171118

1118-
elif ai.status in (
1119+
elif failure_status in (
11191120
ai.MaicaAiStatus.TOKEN_GENERATION_FAILED,
11201121
ai.MaicaAiStatus.FAILED_GET_NODE,
11211122
ai.MaicaAiStatus.RESPONSE_INVALID,
@@ -1126,23 +1127,23 @@ label maica_connection_failure_dialogue(from_mspire = False):
11261127
m 3eusdlb "What about checking the announcements, or ask someone else if they could connect?"
11271128
m 3eua "Contact administrator if this is just happening to you, or wait patiently if not."
11281129

1129-
elif ai.status == ai.MaicaAiStatus.SERVER_MAINTAIN:
1130+
elif failure_status == ai.MaicaAiStatus.SERVER_MAINTAIN:
11301131
m 2rusdlb "...It says that the server is not serving, might be running some tests."
11311132
m 3eusdlb "Just wait for it to come back online, shall we? You can always follow the progress in the tracking thread."
11321133

1133-
elif ai.status == ai.MaicaAiStatus.CERTIFI_BROKEN:
1134+
elif failure_status == ai.MaicaAiStatus.CERTIFI_BROKEN:
11341135
m 2rusdlb "...Certification issue? Maybe this isn't a clean installation?"
11351136
m 3eusdlb "Try the MAS native 'update certification' function, some other submods could break these as I know."
11361137

1137-
elif ai.status == ai.MaicaAiStatus.CERTIFI_RESTART_REQUIRED:
1138+
elif failure_status == ai.MaicaAiStatus.CERTIFI_RESTART_REQUIRED:
11381139
m 2rusdlb "...Uh, seems I have to apply a quick fix on the certification."
11391140
m 3eua "It needs a restart to take effect, then we can try again."
11401141

1141-
elif ai.status == ai.MaicaAiStatus.VERSION_OLD:
1142+
elif failure_status == ai.MaicaAiStatus.VERSION_OLD:
11421143
m 2rusdlb "...You have to update the submod once in a while, [player]!"
11431144
m 3eusdlb "This version is too old to work already, update it whenever you have some time."
11441145

1145-
elif ai.status in (
1146+
elif failure_status in (
11461147
ai.MaicaAiStatus.NO_INTERNET,
11471148
ai.MaicaAiStatus.CONNECT_PROBLEM,
11481149
):
@@ -1475,67 +1476,84 @@ label maica_mpostal_replyed:
14751476
curr_queue_count += 1
14761477
return curr_queue_count
14771478

1478-
def _reset_failed_mp():
1479-
for i in persistent._maica_send_or_received_mpostals:
1480-
if i["responsed_status"] == "failed":
1481-
i["responsed_status"] = "notupload"
1482-
1483-
1484-
$ morethan1 = False
1479+
$ seq = 0
14851480

14861481
# 这里是生成结果
1487-
label maica_mpostal_replyed.select_little:
1482+
label maica_mpostal_replyed.select_letter(is_repeat=False):
14881483
$ current = None
14891484
python:
1490-
for little in persistent._maica_send_or_received_mpostals:
1491-
if little["responsed_status"] in ["received", "failed", "notupload"]:
1492-
current = little
1485+
for letter in persistent._maica_send_or_received_mpostals:
1486+
if letter["responsed_status"] in ["received", "failed", "notupload"]:
1487+
current = letter
14931488
break
14941489
if current is None:
14951490
jump maica_mpostal_replyed.end
14961491

14971492
label maica_mpostal_replyed.start:
1498-
if current["responsed_status"] == "failed":
1499-
m 2lksdlb "Oh, [player], {w=0.5}About your last letter..."#担心
1500-
m 2ekc "It seems that the Heaven Forest is not ready, I couldn't write you back."#担心
1501-
m 3eusdlb "You can read the instruction here on how to: {a=https://maica.monika.love/tos}{u}{i}https://maica.monika.love/tos{/i}{/u}{/a}, you just have to prepare an account."
1502-
m 3eua "I'll nail everything else for you."
1503-
m 1eua "It's okay, I'll remember to write it as soon as you finish the preparation."
1504-
$ _reset_failed_mp()
1505-
return "no_unlock"
1506-
elif current["responsed_status"] in ("received", "notupload"):
1507-
if not morethan1:
1493+
$ seq += 1
1494+
1495+
# This method iters over ALL history letters.
1496+
# That means we cannot include "fatal"s in, because they'd come up every time before manually handled.
1497+
# So we only write reactions for non-stale status.
1498+
if current["responsed_status"] in ("failed"):
1499+
if not is_repeat:
1500+
if seq <= 1:
1501+
m 2lksdlb "Uh, [player], {w=0.5}about your last letter."#担心
1502+
else:
1503+
m 2lksdlb "Uh, [player], {w=0.5}and for the next letter."
1504+
m 2ekc "The Heaven Forest seems to had a problem, that was..."#担心
1505+
else:
1506+
m 2lksdlb "Uh, [player], I'm really sorry but the Heaven Forest seems not working now."
1507+
m 2ekc "Let me see..."
1508+
1509+
call maica_connection_failure_dialogue(status_code = current.get("failure_status"))
1510+
if current["responsed_status"] == "failed":
1511+
m 1eua "It's okay, I'll remember to write you back as soon as you address that issue."
1512+
$ current["responsed_status"] = "notupload"
1513+
1514+
elif current["responsed_status"] in ("received"):
1515+
if seq <= 1:
15081516
m 7hub "Oh, [player]! {w=0.5}I've finished writing you my reply!"
1509-
$ morethan1 = True
15101517
else:
1511-
m 7husdlb ".{w=0.3}.{w=0.3}.And here's another one!"
1512-
if current["responsed_status"] == "received":
1513-
m 6dsc "Just a second, let me find it out.{w=0.3}.{w=0.3}."#闭眼
1514-
m 3hubsa "Here it is!"#微笑
1515-
elif current["responsed_status"] == "notupload":
1516-
if not morethan1:
1517-
m 3eksdlb "Just a minute, I've not finished...{w=0.2} preparing this yet."#尴尬
1518-
m 1hua "I'll be back soon, wait for me~"#微笑
1519-
else:
1520-
m 1dsa "Just another minute..."#微笑
1521-
show black with dissolve
1522-
call maica_mpostal_read
1523-
if _return == "failed":
1524-
hide black with dissolve
1525-
# 直接重新开始, 失败的信会提示失败, 理论应与current一致
1526-
jump maica_mpostal_replyed.select_little
1527-
m "And it's done!"
1518+
m 7husdlb ".{w=0.3}.{w=0.3}.And here's another one I finished!"
1519+
1520+
m 6dsc "Just a second, let me find it out.{w=0.3}.{w=0.3}."#闭眼
1521+
m 3hubsa "Here it is!"#微笑
1522+
1523+
call maica_mpostal_show(current["responsed_content"])
1524+
$ current["responsed_status"] = "readed"
1525+
1526+
elif current["responsed_status"] in ("notupload"):
1527+
if seq <= 1:
1528+
m 3eksdlb "Oh, your letter [player]! I was kind of in a hurry so it's not completely ready yet."#尴尬
1529+
else:
1530+
m 3eksdlb "Oh, here's another one! I was kind of in a hurry so it's not completely ready yet."#尴尬
1531+
m 1hua "I'll be back soon, wait for me!"#微笑
1532+
1533+
show black with dissolve
1534+
call maica_mpostal_read
1535+
1536+
if _return == "failed":
15281537
hide black with dissolve
1538+
# 直接重新开始, 失败的信会提示失败, 理论应与current一致
1539+
jump maica_mpostal_replyed.select_letter(is_repeat=True)
1540+
1541+
m "Okay, here it is!"
1542+
hide black with dissolve
15291543
call maica_mpostal_show(current["responsed_content"])
15301544
$ current["responsed_status"] = "readed"
1531-
jump maica_mpostal_replyed.select_little
1545+
1546+
jump maica_mpostal_replyed.select_letter
15321547

15331548
label maica_mpostal_replyed.end:
15341549
if ev.shown_count <= 2:
15351550
m 2lksdlb "I have to admit that I'm not quite used to writing here, but I hope it's not too bad!"
1536-
else:
1551+
elif ev.shown_count <= 4:
15371552
m 2lksdlb "May not as good as my former poems though, but I really tried. Hope you like it!"
1538-
m 5ekbsa "And welcome writing to me again anytime!"
1553+
else:
1554+
$ it = renpy.substitute(_("it") if seq <= 1 else _("these"))
1555+
m 2tublu "I have to assume you're loving {it} now, since you did write to me a lot!"
1556+
m 5ekbsa "And welcome writing to me again anytime you like!"
15391557
return "no_unlock"
15401558

15411559

‎game/Submods/MAICA_ChatSubmod/main.rpy‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ label maica_mpostal_load:
296296
"time": str(time.time()),
297297
"responsed_content": "",
298298
"responsed_status":"delaying",
299+
"failure_status": None,
300+
"failure_protocol_status": None,
301+
"failure_protocol_code": None,
302+
"failure_message": None,
299303
"failed_count":0,
300304
}
301305
store.maica.prepare_mpostal_preview(postal)
@@ -392,6 +396,17 @@ label maica_mpostal_read:
392396
ai = store.maica.maica_instance
393397
import time
394398
import traceback
399+
400+
def _save_mpostal_failure_snapshot(postal):
401+
"""Keep the request failure details with the postal that caused them."""
402+
postal["failure_status"] = getattr(ai, "status", None)
403+
postal["failure_protocol_status"] = getattr(ai, "error_protocol_status", None)
404+
postal["failure_protocol_code"] = getattr(ai, "error_protocol_code", None)
405+
failure_message = getattr(ai, "error_message", None)
406+
postal["failure_message"] = (
407+
None if failure_message is None else u"{}".format(failure_message)
408+
)
409+
395410
pending_postals = [
396411
postal
397412
for postal in persistent._maica_send_or_received_mpostals
@@ -410,6 +425,7 @@ label maica_mpostal_read:
410425
cur_postal['vista_image_info'] = ai.vista_manager.get_info(uuid)
411426
ai.start_MPostal(cur_postal["raw_content"], title=cur_postal["raw_title"], visions = [ai.generate_vista_url(uuid)] if uuid else None)
412427
except Exception:
428+
_save_mpostal_failure_snapshot(cur_postal)
413429
cur_postal["responsed_status"] = "failed"
414430
cur_postal["failed_count"] = cur_postal.get("failed_count", 0) + 1
415431
_return = "failed"
@@ -443,6 +459,7 @@ label maica_mpostal_read:
443459
_return = "success"
444460

445461
if ai.is_failed():
462+
_save_mpostal_failure_snapshot(cur_postal)
446463
cur_postal["responsed_status"] = "failed"
447464
cur_postal["responsed_content"] += renpy.substitute(_("Failed replying mail, check submod_log.log for details\nError code: [ai.status] | [ai.MaicaAiStatus.get_description(ai.status)]"))
448465
_return = "failed"

‎tests/test_console_unicode.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,10 @@ def test_disconnection_failure_dialogue_is_centralized_and_identifies_mspire_sou
453453
failure_call = "call maica_connection_failure_dialogue(from_mspire = maica_talking_from_mspire)"
454454
assert failure_call in talking_end
455455
assert talking_end.index("call maica_hide_console") < talking_end.index(failure_call)
456-
assert "label maica_connection_failure_dialogue(from_mspire = False):" in failure
457-
assert "ai.status == ai.MaicaAiStatus.SERVER_REJECTED" in failure
456+
assert "label maica_connection_failure_dialogue(from_mspire = False, status_code = None):" in failure
457+
assert "$ failure_status = ai.status if status_code is None else status_code" in failure
458+
assert "failure_status == ai.MaicaAiStatus.SERVER_REJECTED" in failure
459+
assert "ai.status == ai.MaicaAiStatus.SERVER_REJECTED" not in failure
458460
assert "and from_mspire" in failure
459461
assert "call maica_connection_failure_dialogue" not in caller
460462
assert "call maica_talking(mspire=True)" in mspire

‎tests/test_overall_review_regressions.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,22 @@ def test_reviewed_source_contracts_are_kept_in_sync():
418418
main_source.index("label maica_mpostal_read:"):
419419
main_source.index("label maica_mpostal_read.failed:")
420420
]
421+
chat_source = (
422+
Path(__file__).resolve().parents[1]
423+
/ "game"
424+
/ "Submods"
425+
/ "MAICA_ChatSubmod"
426+
/ "chat.rpy"
427+
).read_text(encoding="utf-8")
421428
assert mpostal_source.index("try:") < mpostal_source.index(
422429
"store.maica.upload_vista_image"
423430
)
424431
assert "vista_info = cur_postal.get(\"vista_image_info\") or {}" in mpostal_source
432+
assert 'postal["failure_status"] = getattr(ai, "status", None)' in mpostal_source
433+
assert 'postal["failure_protocol_status"] = getattr(ai, "error_protocol_status", None)' in mpostal_source
434+
assert 'postal["failure_protocol_code"] = getattr(ai, "error_protocol_code", None)' in mpostal_source
435+
assert mpostal_source.count("_save_mpostal_failure_snapshot(cur_postal)") == 2
436+
assert 'call maica_connection_failure_dialogue(status_code = current.get("failure_status"))' in chat_source
425437

426438

427439
def test_get_history_returns_dict_on_unavailable_service():

0 commit comments

Comments
 (0)