@lf_maple/koishi-plugin-phi-plugin-full 0.1.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (629) hide show
  1. package/LICENSE +22 -0
  2. package/core/.github/ISSUE_TEMPLATE/bug.yaml +133 -0
  3. package/core/.github/ISSUE_TEMPLATE/config.yml +1 -0
  4. package/core/.github/ISSUE_TEMPLATE/enhancement.yml +44 -0
  5. package/core/.vscode/c_cpp_properties.json +18 -0
  6. package/core/.vscode/launch.json +24 -0
  7. package/core/.vscode/settings.json +59 -0
  8. package/core/CHANGELOG.md +184 -0
  9. package/core/LICENSE +674 -0
  10. package/core/README.md +330 -0
  11. package/core/README_en.md +285 -0
  12. package/core/apps/Dan.js +129 -0
  13. package/core/apps/RankList.js +322 -0
  14. package/core/apps/aliasProposal.js +223 -0
  15. package/core/apps/apiSetting.js +592 -0
  16. package/core/apps/b19.js +1329 -0
  17. package/core/apps/botClient.js +64 -0
  18. package/core/apps/chart.js +692 -0
  19. package/core/apps/guessGame/guessIll.js +821 -0
  20. package/core/apps/guessGame/guessLetter.js +831 -0
  21. package/core/apps/guessGame/guessTips.js +254 -0
  22. package/core/apps/guessGame/letterGameUtils.js +74 -0
  23. package/core/apps/guessGame.js +214 -0
  24. package/core/apps/help.js +117 -0
  25. package/core/apps/manage.js +288 -0
  26. package/core/apps/market.js +243 -0
  27. package/core/apps/money.js +1064 -0
  28. package/core/apps/phisong.js +1418 -0
  29. package/core/apps/session.js +664 -0
  30. package/core/apps/setting.js +468 -0
  31. package/core/apps/update.js +541 -0
  32. package/core/apps/user.js +968 -0
  33. package/core/components/Config.js +249 -0
  34. package/core/components/Data.js +304 -0
  35. package/core/components/FileWatcherRegistry.js +102 -0
  36. package/core/components/Logger.js +11 -0
  37. package/core/components/ProcessCleanup.js +113 -0
  38. package/core/components/Version.js +56 -0
  39. package/core/components/YamlReader.js +157 -0
  40. package/core/components/baseClass.js +287 -0
  41. package/core/components/common.js +47 -0
  42. package/core/components/index.js +13 -0
  43. package/core/components/platform/index.js +79 -0
  44. package/core/components/platform/koishi.js +800 -0
  45. package/core/components/platform/koishiDatabaseRedis.js +391 -0
  46. package/core/components/platform/memoryRedis.js +209 -0
  47. package/core/components/platform/types.d.ts +272 -0
  48. package/core/components/platform/yunzai.js +604 -0
  49. package/core/components/segment.js +4 -0
  50. package/core/config/config//350/277/231/351/207/214/346/230/257/351/205/215/347/275/256/346/226/207/344/273/266/347/233/256/345/275/225.txt +0 -0
  51. package/core/config/default_config/banGroup.yaml +14 -0
  52. package/core/config/default_config/config.yaml +159 -0
  53. package/core/config/default_config/nickconfig.yaml +6 -0
  54. package/core/config/default_config/otherinfo.yaml +51 -0
  55. package/core/guoba.support.js +597 -0
  56. package/core/index.js +85 -0
  57. package/core/lib/AES.js +40 -0
  58. package/core/lib/Base64.js +22 -0
  59. package/core/lib/ByteReader.js +168 -0
  60. package/core/lib/GameProgress.js +37 -0
  61. package/core/lib/GameRecord.js +47 -0
  62. package/core/lib/GameSettings.js +24 -0
  63. package/core/lib/GameUser.js +19 -0
  64. package/core/lib/Level.js +6 -0
  65. package/core/lib/LevelRecord.js +9 -0
  66. package/core/lib/PhigrosUser.js +135 -0
  67. package/core/lib/SaveManager.js +117 -0
  68. package/core/lib/Summary.js +47 -0
  69. package/core/lib/TapTap/CompleteQRCodeData.js +27 -0
  70. package/core/lib/TapTap/LCHelper.js +81 -0
  71. package/core/lib/TapTap/TapTapHelper.js +170 -0
  72. package/core/lib/TapTap/getQRcode.js +61 -0
  73. package/core/lib/Util.js +30 -0
  74. package/core/lib/getQRcode.js +73 -0
  75. package/core/lib/http.js +105 -0
  76. package/core/model/README.md +3 -0
  77. package/core/model/api/aliasProposalService.js +151 -0
  78. package/core/model/api/apiVersion.js +67 -0
  79. package/core/model/api/autoSeekApi.js +165 -0
  80. package/core/model/api/botApiAuth.js +208 -0
  81. package/core/model/api/botSyncService.js +78 -0
  82. package/core/model/api/gameRecordPayload.js +24 -0
  83. package/core/model/api/makeRequest.js +1004 -0
  84. package/core/model/api/makeRequestFnc.js +17 -0
  85. package/core/model/api/phiApiClient.js +53 -0
  86. package/core/model/api/phiApiErrors.js +121 -0
  87. package/core/model/filesystem/getFile.js +256 -0
  88. package/core/model/filesystem/path.js +84 -0
  89. package/core/model/game/Chart.js +57 -0
  90. package/core/model/game/LevelRecordInfo.js +109 -0
  91. package/core/model/game/SongsInfo.js +46 -0
  92. package/core/model/game/b30Analysis.js +93 -0
  93. package/core/model/game/chartParser/Chart.js +23 -0
  94. package/core/model/game/chartParser/JudgeLine.js +38 -0
  95. package/core/model/game/chartParser/base/JudgeLineEvent.js +99 -0
  96. package/core/model/game/chartParser/base/Note.js +44 -0
  97. package/core/model/game/chartParser/base/SpeedEvent.js +25 -0
  98. package/core/model/game/chartParser/base/baseType.js +2 -0
  99. package/core/model/game/constNum.js +215 -0
  100. package/core/model/game/fCompute.js +711 -0
  101. package/core/model/game/getChartTag.js +140 -0
  102. package/core/model/game/getComment.js +132 -0
  103. package/core/model/game/getInfo.js +1069 -0
  104. package/core/model/game/getRksRank.js +77 -0
  105. package/core/model/game/markdown.js +77 -0
  106. package/core/model/integrations/Vika.js +103 -0
  107. package/core/model/integrations/getInfoFromTap.js +80 -0
  108. package/core/model/render/getPic.js +79 -0
  109. package/core/model/render/picmodle.js +496 -0
  110. package/core/model/render/progress-bar.js +44 -0
  111. package/core/model/render/puppeteer.js +431 -0
  112. package/core/model/render/renderPressureHistory.js +71 -0
  113. package/core/model/render/send.js +94 -0
  114. package/core/model/save/Save.js +953 -0
  115. package/core/model/save/analyzeSaveHistory.js +413 -0
  116. package/core/model/save/getBackup.js +328 -0
  117. package/core/model/save/getSave.js +90 -0
  118. package/core/model/save/getSaveFromApi.js +46 -0
  119. package/core/model/save/saveHistory.js +586 -0
  120. package/core/model/save/scoreHistory.js +101 -0
  121. package/core/model/theme/catalog.js +192 -0
  122. package/core/model/theme/installGuard.js +275 -0
  123. package/core/model/theme/installLock.js +174 -0
  124. package/core/model/theme/installer.js +398 -0
  125. package/core/model/theme/manager.js +408 -0
  126. package/core/model/theme/marketClient.js +294 -0
  127. package/core/model/theme/paths.js +42 -0
  128. package/core/model/theme/policy.js +54 -0
  129. package/core/model/theme/recovery.js +167 -0
  130. package/core/model/theme/useService.js +187 -0
  131. package/core/model/type/aliasProposal.d.ts +45 -0
  132. package/core/model/type/type.js +420 -0
  133. package/core/model/user/apiPermission.js +62 -0
  134. package/core/model/user/getBanGroup.js +120 -0
  135. package/core/model/user/getNotes.js +48 -0
  136. package/core/model/user/pluginData.js +101 -0
  137. package/core/model/user/userCredentialStore.js +154 -0
  138. package/core/model/user/userCredentials.js +860 -0
  139. package/core/package.json +60 -0
  140. package/core/resources/0608badSave/save.json +1 -0
  141. package/core/resources/LICENSE +201 -0
  142. package/core/resources/html/analyzeSaveHistory/analyzeSaveHistory.art +220 -0
  143. package/core/resources/html/analyzeSaveHistory/analyzeSaveHistory.css +345 -0
  144. package/core/resources/html/analyzeSaveHistory/analyzeSaveHistory.html +434 -0
  145. package/core/resources/html/arcgrosB19/arcgros.png +0 -0
  146. package/core/resources/html/arcgrosB19/arcgrosB19-orz.html +276 -0
  147. package/core/resources/html/arcgrosB19/arcgrosB19.art +168 -0
  148. package/core/resources/html/arcgrosB19/arcgrosB19.css +637 -0
  149. package/core/resources/html/atlas/atlas-orz.html +313 -0
  150. package/core/resources/html/atlas/atlas.art +194 -0
  151. package/core/resources/html/atlas/atlas.css +695 -0
  152. package/core/resources/html/avatar/-SURREALISM-.png +0 -0
  153. package/core/resources/html/avatar/Alkaid.png +0 -0
  154. package/core/resources/html/avatar/Aphasia.png +0 -0
  155. package/core/resources/html/avatar/Artificial Existence.png +0 -0
  156. package/core/resources/html/avatar/Bonus Time.png +0 -0
  157. package/core/resources/html/avatar/Burn.png +0 -0
  158. package/core/resources/html/avatar/Cereris1.png +0 -0
  159. package/core/resources/html/avatar/Cereris2.png +0 -0
  160. package/core/resources/html/avatar/Cereris3.png +0 -0
  161. package/core/resources/html/avatar/Christmas -2019.png +0 -0
  162. package/core/resources/html/avatar/Cipher1.png +0 -0
  163. package/core/resources/html/avatar/Class Memories.png +0 -0
  164. package/core/resources/html/avatar/Credits.png +0 -0
  165. package/core/resources/html/avatar/Dash.png +0 -0
  166. package/core/resources/html/avatar/Dlyrotz.png +0 -0
  167. package/core/resources/html/avatar/Doppelganger1.png +0 -0
  168. package/core/resources/html/avatar/Doppelganger2.png +0 -0
  169. package/core/resources/html/avatar/Drop it.png +0 -0
  170. package/core/resources/html/avatar/Energy Synergy Matrix1.png +0 -0
  171. package/core/resources/html/avatar/Energy Synergy Matrix2.png +0 -0
  172. package/core/resources/html/avatar/Energy Synergy Matrix3.png +0 -0
  173. package/core/resources/html/avatar/Engine x Start!! (melody mix).png +0 -0
  174. package/core/resources/html/avatar/Engine x Start!! extra 1 -by cycats.png +0 -0
  175. package/core/resources/html/avatar/Eradication Catastrophe.png +0 -0
  176. package/core/resources/html/avatar/FULi AUTO SHOOTER extra 1 -by cycats.png +0 -0
  177. package/core/resources/html/avatar/FULi AUTO SHOOTER.png +0 -0
  178. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/264-Special1.png +0 -0
  179. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/264-Special2.png +0 -0
  180. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2641.png +0 -0
  181. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2642.png +0 -0
  182. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2643.png +0 -0
  183. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2644.png +0 -0
  184. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2645.png +0 -0
  185. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2646.png +0 -0
  186. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2647.png +0 -0
  187. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2648.png +0 -0
  188. package/core/resources/html/avatar/Feast/350/277/234/344/270/234/344/271/213/345/256/2649.png +0 -0
  189. package/core/resources/html/avatar/Find_Me.png +0 -0
  190. package/core/resources/html/avatar/Geopelia 1 -by cycats.png +0 -0
  191. package/core/resources/html/avatar/Geopelia 2 -by cycats.png +0 -0
  192. package/core/resources/html/avatar/Geopelia 3 -by /344/275/225/345/221/265.png +0 -0
  193. package/core/resources/html/avatar/Geopelia in WEPLAY -by /346/265/267/344/272/247.png +0 -0
  194. package/core/resources/html/avatar/Gino-AprilFool.png +0 -0
  195. package/core/resources/html/avatar/Glaciaxion.png +0 -0
  196. package/core/resources/html/avatar/HumaN.png +0 -0
  197. package/core/resources/html/avatar/Indelible Scar.png +0 -0
  198. package/core/resources/html/avatar/Introduction.png +0 -0
  199. package/core/resources/html/avatar/Khronostasis Katharsis.png +0 -0
  200. package/core/resources/html/avatar/MARENOL.png +0 -0
  201. package/core/resources/html/avatar/Marenol extra 1 -by /345/226/265n/350/221/265.png +0 -0
  202. package/core/resources/html/avatar/Non-Melodic Ragez (MUG Edit).png +0 -0
  203. package/core/resources/html/avatar/Non-Melodic Ragez extra 1 -by cycats.png +0 -0
  204. package/core/resources/html/avatar/Oblivion +0 -0
  205. package/core/resources/html/avatar/OblivionPHIN.png +0 -0
  206. package/core/resources/html/avatar/Para.png +0 -0
  207. package/core/resources/html/avatar/Pixel Rebelz1.png +0 -0
  208. package/core/resources/html/avatar/Pixel Rebelz2.png +0 -0
  209. package/core/resources/html/avatar/Pixel Rebelz3.png +0 -0
  210. package/core/resources/html/avatar/RIPPER extra 1 -by cycats.png +0 -0
  211. package/core/resources/html/avatar/RIPPER extra 2 -by /344/275/225/345/221/265.png +0 -0
  212. package/core/resources/html/avatar/Sein.png +0 -0
  213. package/core/resources/html/avatar/ShineAfter-/346/260/264/351/235/222-Special.png +0 -0
  214. package/core/resources/html/avatar/ShineAfter-/346/260/264/351/235/222-Special2.png +0 -0
  215. package/core/resources/html/avatar/ShineAfter-/346/260/264/351/235/222-/346/231/256/351/200/232.png +0 -0
  216. package/core/resources/html/avatar/ShineAfter-/346/260/264/351/235/222-/346/233/262/347/273/230Ver.png +0 -0
  217. package/core/resources/html/avatar/ShineAfter-/351/270/240-Special.png +0 -0
  218. package/core/resources/html/avatar/ShineAfter-/351/270/240-/346/231/256/351/200/232.png +0 -0
  219. package/core/resources/html/avatar/ShineAfter-/351/270/240-/346/233/262/347/273/230Ver.png +0 -0
  220. package/core/resources/html/avatar/ShineAfter-/351/270/240/345/222/214/346/260/264/351/235/222-Special.png +0 -0
  221. package/core/resources/html/avatar/Snow Desert.png +0 -0
  222. package/core/resources/html/avatar/Sparkle New Life.png +0 -0
  223. package/core/resources/html/avatar/Sultan Rage.png +0 -0
  224. package/core/resources/html/avatar/Winter /342/206/221cube/342/206/223.png +0 -0
  225. package/core/resources/html/avatar/Xenolith.png +0 -0
  226. package/core/resources/html/avatar/[PRAW].png +0 -0
  227. package/core/resources/html/avatar/dB doll.png +0 -0
  228. package/core/resources/html/avatar/ripper.png +0 -0
  229. package/core/resources/html/avatar//343/202/202/343/201/272/343/202/202/343/201/2721.png +0 -0
  230. package/core/resources/html/avatar//343/202/202/343/201/272/343/202/202/343/201/2722.png +0 -0
  231. package/core/resources/html/avatar//344/270/207/345/220/250/345/214/277/345/220/215/344/277/241.png +0 -0
  232. package/core/resources/html/avatar//344/272/221/345/245/263/345/255/251 extra 1 -by /345/276/241/345/235/202/346/236/234/345/255/220.png +0 -0
  233. package/core/resources/html/avatar//344/272/221/345/245/263/345/255/251.png +0 -0
  234. package/core/resources/html/avatar//345/205/211.png +0 -0
  235. package/core/resources/html/avatar//345/274/200/345/277/203/347/227/2051.png +0 -0
  236. package/core/resources/html/avatar//345/274/200/345/277/203/347/227/2052.png +0 -0
  237. package/core/resources/html/avatar//346/260/264/351/235/222-/344/270/200/345/221/250/345/271/264/347/233/270/350/201/232.png +0 -0
  238. package/core/resources/html/avatar//346/267/267/344/271/261-Confusion.png +0 -0
  239. package/core/resources/html/avatar//347/213/202/345/226/234/350/230/255/350/210/2361.png +0 -0
  240. package/core/resources/html/avatar//347/213/202/345/226/234/350/230/255/350/210/2362.png +0 -0
  241. package/core/resources/html/avatar//347/223/267/345/262/201-Special.png +0 -0
  242. package/core/resources/html/avatar//347/223/267/345/262/2011.png +0 -0
  243. package/core/resources/html/avatar//347/223/267/345/262/2012.png +0 -0
  244. package/core/resources/html/avatar//347/223/267/345/262/2013.png +0 -0
  245. package/core/resources/html/avatar//347/223/267/345/262/2014.png +0 -0
  246. package/core/resources/html/avatar//347/223/267/345/262/2015.png +0 -0
  247. package/core/resources/html/avatar//347/223/267/345/262/2016.png +0 -0
  248. package/core/resources/html/avatar//347/223/267/345/262/2017.png +0 -0
  249. package/core/resources/html/avatar//347/233/217/350/214/227-Special.png +0 -0
  250. package/core/resources/html/avatar//347/233/217/350/214/2271.png +0 -0
  251. package/core/resources/html/avatar//347/233/217/350/214/2272.png +0 -0
  252. package/core/resources/html/avatar//347/233/217/350/214/2273.png +0 -0
  253. package/core/resources/html/avatar//350/217/257/347/201/257/347/210/2611.png +0 -0
  254. package/core/resources/html/avatar//350/217/257/347/201/257/347/210/2612.png +0 -0
  255. package/core/resources/html/avatar//350/220/244/347/201/253/350/231/253/343/201/256/346/200/2501.png +0 -0
  256. package/core/resources/html/avatar//350/220/244/347/201/253/350/231/253/343/201/256/346/200/2502.png +0 -0
  257. package/core/resources/html/avatar//351/235/222/350/212/275-Special.png +0 -0
  258. package/core/resources/html/avatar//351/235/222/350/212/275.png +0 -0
  259. package/core/resources/html/avatar//351/243/216/345/261/277.png +0 -0
  260. package/core/resources/html/avatar//351/270/240-AprilFool.png +0 -0
  261. package/core/resources/html/avatar//351/270/240-/344/270/200/345/221/250/345/271/264/347/233/270/350/201/232.png +0 -0
  262. package/core/resources/html/b19/b19.art +490 -0
  263. package/core/resources/html/b19/b19.css +1261 -0
  264. package/core/resources/html/b19/b19666.art +350 -0
  265. package/core/resources/html/b19/b19666.css +1409 -0
  266. package/core/resources/html/b19/b19666.html +481 -0
  267. package/core/resources/html/b19/b19title.css +120 -0
  268. package/core/resources/html/b19/best19.html +853 -0
  269. package/core/resources/html/b19/dss2-orz.html +428 -0
  270. package/core/resources/html/b19/dss2.art +298 -0
  271. package/core/resources/html/b19/dss2.css +776 -0
  272. package/core/resources/html/b19/res/666.jpeg +0 -0
  273. package/core/resources/html/chap/chap-orz.html +93 -0
  274. package/core/resources/html/chap/chap.art +87 -0
  275. package/core/resources/html/chap/chap.css +365 -0
  276. package/core/resources/html/chartImg/chartImg.art +169 -0
  277. package/core/resources/html/chartImg/chartImg.css +439 -0
  278. package/core/resources/html/chartImg/echarts-wordcloud.min.js +3 -0
  279. package/core/resources/html/chartImg/echarts.js +85796 -0
  280. package/core/resources/html/chartImg/img/Drag.png +0 -0
  281. package/core/resources/html/chartImg/img/DragHL.png +0 -0
  282. package/core/resources/html/chartImg/img/Flick.png +0 -0
  283. package/core/resources/html/chartImg/img/FlickHL.png +0 -0
  284. package/core/resources/html/chartImg/img/Hold.png +0 -0
  285. package/core/resources/html/chartImg/img/HoldHL.png +0 -0
  286. package/core/resources/html/chartImg/img/Hold_End.png +0 -0
  287. package/core/resources/html/chartImg/img/Hold_Head.png +0 -0
  288. package/core/resources/html/chartImg/img/Hold_HeadHL.png +0 -0
  289. package/core/resources/html/chartImg/img/Tap.png +0 -0
  290. package/core/resources/html/chartImg/img/TapHL.png +0 -0
  291. package/core/resources/html/chartInfo/chartInfo-orz.html +250 -0
  292. package/core/resources/html/chartInfo/chartInfo.art +222 -0
  293. package/core/resources/html/chartInfo/chartInfo.css +265 -0
  294. package/core/resources/html/chartInfo/echarts-wordcloud.min.js +3 -0
  295. package/core/resources/html/chartInfo/echarts.js +85796 -0
  296. package/core/resources/html/clg/clg-orz.html +218 -0
  297. package/core/resources/html/clg/clg.art +88 -0
  298. package/core/resources/html/clg/clg.css +230 -0
  299. package/core/resources/html/clg/demo.jpg +0 -0
  300. package/core/resources/html/common/common.css +319 -0
  301. package/core/resources/html/common/css/playerInfo.css +136 -0
  302. package/core/resources/html/common/font/Aldrich-Regular.ttf +0 -0
  303. package/core/resources/html/common/font/HIMALAYA.TTF +0 -0
  304. package/core/resources/html/common/font/NotoColorEmoji-Regular.ttf +0 -0
  305. package/core/resources/html/common/font/NotoSans-Regular.ttf +0 -0
  306. package/core/resources/html/common/font/NotoSansArabic.ttf +0 -0
  307. package/core/resources/html/common/font/NotoSansCanadianAboriginal.ttf +0 -0
  308. package/core/resources/html/common/font/NotoSansJP.ttf +0 -0
  309. package/core/resources/html/common/font/NotoSansKannada.ttf +0 -0
  310. package/core/resources/html/common/font/NotoSansMath-Regular.ttf +0 -0
  311. package/core/resources/html/common/font/NotoSansSymbols2.ttf +0 -0
  312. package/core/resources/html/common/font/phi.ttf +0 -0
  313. package/core/resources/html/common/font//345/220/236/345/274/245/346/201/260/344/277/212.ttf +0 -0
  314. package/core/resources/html/common/layout/default.art +324 -0
  315. package/core/resources/html/common/layout/elem.art +21 -0
  316. package/core/resources/html/common/theme/snow/snow.css +17 -0
  317. package/core/resources/html/common/theme/snow/snow.js +19 -0
  318. package/core/resources/html/common/theme/star/star.js +201 -0
  319. package/core/resources/html/common/theme/topText/topText.css +15 -0
  320. package/core/resources/html/common/theme/topText/topText.js +30 -0
  321. package/core/resources/html/difficultyHistory/difficultyHistory-orz.html +361 -0
  322. package/core/resources/html/difficultyHistory/difficultyHistory.art +102 -0
  323. package/core/resources/html/difficultyHistory/difficultyHistory.css +205 -0
  324. package/core/resources/html/guess/guess-orz.html +50 -0
  325. package/core/resources/html/guess/guess.art +51 -0
  326. package/core/resources/html/guess/guess.css +33 -0
  327. package/core/resources/html/help/help-orz.html +73 -0
  328. package/core/resources/html/help/help.art +84 -0
  329. package/core/resources/html/help/help.css +266 -0
  330. package/core/resources/html/historyB30/historyB30-orz.html +168 -0
  331. package/core/resources/html/historyB30/historyB30.art +143 -0
  332. package/core/resources/html/historyB30/historyB30.css +270 -0
  333. package/core/resources/html/ill/ill-orz.html +21 -0
  334. package/core/resources/html/ill/ill.art +23 -0
  335. package/core/resources/html/ill/ill.css +79 -0
  336. package/core/resources/html/jrrp/ShineAfter.removebg.png +0 -0
  337. package/core/resources/html/jrrp/jrrp-orz.html +68 -0
  338. package/core/resources/html/jrrp/jrrp.art +58 -0
  339. package/core/resources/html/jrrp/jrrp.css +251 -0
  340. package/core/resources/html/list/list-orz.html +35 -0
  341. package/core/resources/html/list/list.art +67 -0
  342. package/core/resources/html/list/list.css +259 -0
  343. package/core/resources/html/lvsco/demo.jpg +0 -0
  344. package/core/resources/html/lvsco/lvsco-orz.html +334 -0
  345. package/core/resources/html/lvsco/lvsco.art +314 -0
  346. package/core/resources/html/lvsco/lvsco.css +706 -0
  347. package/core/resources/html/market/detail.art +44 -0
  348. package/core/resources/html/market/market.art +86 -0
  349. package/core/resources/html/market/market.css +64 -0
  350. package/core/resources/html/newSong/newSong.art +34 -0
  351. package/core/resources/html/newSong/newSong.css +48 -0
  352. package/core/resources/html/newSong/newSong.html +23 -0
  353. package/core/resources/html/newnotice/newnotice.art +47 -0
  354. package/core/resources/html/newnotice/newnotice.css +83 -0
  355. package/core/resources/html/otherimg/0.png +0 -0
  356. package/core/resources/html/otherimg/1.png +0 -0
  357. package/core/resources/html/otherimg/2.png +0 -0
  358. package/core/resources/html/otherimg/3.png +0 -0
  359. package/core/resources/html/otherimg/4.png +0 -0
  360. package/core/resources/html/otherimg/5.png +0 -0
  361. package/core/resources/html/otherimg/A.png +0 -0
  362. package/core/resources/html/otherimg/B.png +0 -0
  363. package/core/resources/html/otherimg/C.png +0 -0
  364. package/core/resources/html/otherimg/F.png +0 -0
  365. package/core/resources/html/otherimg/FC.png +0 -0
  366. package/core/resources/html/otherimg/NEW.png +0 -0
  367. package/core/resources/html/otherimg/Phigros_Icon_3.0.0.png +0 -0
  368. package/core/resources/html/otherimg/S.png +0 -0
  369. package/core/resources/html/otherimg/Star1.png +0 -0
  370. package/core/resources/html/otherimg/Star2.png +0 -0
  371. package/core/resources/html/otherimg/V.png +0 -0
  372. package/core/resources/html/otherimg/callback.png +0 -0
  373. package/core/resources/html/otherimg/chapHelp.png +0 -0
  374. package/core/resources/html/otherimg/dan_code.png +0 -0
  375. package/core/resources/html/otherimg/data.png +0 -0
  376. package/core/resources/html/otherimg/helpDoc.png +0 -0
  377. package/core/resources/html/otherimg/nickSuggest.png +0 -0
  378. package/core/resources/html/otherimg/phi.png +0 -0
  379. package/core/resources/html/otherimg/phigros.png +0 -0
  380. package/core/resources/html/otherimg/snow1.png +0 -0
  381. package/core/resources/html/otherimg/snow2.png +0 -0
  382. package/core/resources/html/otherimg/snow3.png +0 -0
  383. package/core/resources/html/otherimg/snow4.png +0 -0
  384. package/core/resources/html/otherimg/title.png +0 -0
  385. package/core/resources/html/rand/rand-orz.html +62 -0
  386. package/core/resources/html/rand/rand.art +59 -0
  387. package/core/resources/html/rand/rand.css +257 -0
  388. package/core/resources/html/rankingList/rankingList-orz.html +456 -0
  389. package/core/resources/html/rankingList/rankingList.art +171 -0
  390. package/core/resources/html/rankingList/rankingList.css +570 -0
  391. package/core/resources/html/rankingList-old/rankingList-orz.html +300 -0
  392. package/core/resources/html/rankingList-old/rankingList.art +89 -0
  393. package/core/resources/html/rankingList-old/rankingList.css +265 -0
  394. package/core/resources/html/score/score-orz.html +625 -0
  395. package/core/resources/html/score/score.art +249 -0
  396. package/core/resources/html/score/score.css +435 -0
  397. package/core/resources/html/score/scoreOld-orz.html +128 -0
  398. package/core/resources/html/score/scoreOld.art +230 -0
  399. package/core/resources/html/score/scoreOld.css +475 -0
  400. package/core/resources/html/score/scoreRankList-orz.html +613 -0
  401. package/core/resources/html/score/scoreRankList.art +231 -0
  402. package/core/resources/html/score/scoreRankList.css +197 -0
  403. package/core/resources/html/setting/setting-orz.html +123 -0
  404. package/core/resources/html/setting/setting.art +72 -0
  405. package/core/resources/html/setting/setting.css +170 -0
  406. package/core/resources/html/setting/userSetting-orz.html +132 -0
  407. package/core/resources/html/setting/userSetting.art +48 -0
  408. package/core/resources/html/setting/userSetting.css +160 -0
  409. package/core/resources/html/sign/sign-orz.html +262 -0
  410. package/core/resources/html/sign/sign.art +163 -0
  411. package/core/resources/html/sign/sign.css +706 -0
  412. package/core/resources/html/suggest/suggest.art +271 -0
  413. package/core/resources/html/suggest/suggest.css +300 -0
  414. package/core/resources/html/table/table-orz.html +228 -0
  415. package/core/resources/html/table/table.art +163 -0
  416. package/core/resources/html/table/table.css +401 -0
  417. package/core/resources/html/tasks/tasks-orz.html +83 -0
  418. package/core/resources/html/tasks/tasks.art +118 -0
  419. package/core/resources/html/tasks/tasks.css +334 -0
  420. package/core/resources/html/update/update-orz.html +735 -0
  421. package/core/resources/html/update/update.art +259 -0
  422. package/core/resources/html/update/update.css +676 -0
  423. package/core/resources/html/userinfo/userinfo-old-orz.html +408 -0
  424. package/core/resources/html/userinfo/userinfo-old.art +233 -0
  425. package/core/resources/html/userinfo/userinfo-old.css +466 -0
  426. package/core/resources/html/userinfo/userinfo-orz.html +543 -0
  427. package/core/resources/html/userinfo/userinfo.art +288 -0
  428. package/core/resources/html/userinfo/userinfo.css +757 -0
  429. package/core/resources/info/DLC/arc.json +412 -0
  430. package/core/resources/info/DLC/chunithm.json +1172 -0
  431. package/core/resources/info/DLC/dynamix.json +455 -0
  432. package/core/resources/info/DLC/fanshi.json +132 -0
  433. package/core/resources/info/DLC/lanota.json +412 -0
  434. package/core/resources/info/DLC/maimai.json +1110 -0
  435. package/core/resources/info/DLC/orz.json +158 -0
  436. package/core/resources/info/DLC/rizline.json +40 -0
  437. package/core/resources/info/DLC/rotaeno.json +159 -0
  438. package/core/resources/info/DLC/ryceam.json +53 -0
  439. package/core/resources/info/avatar.txt +109 -0
  440. package/core/resources/info/chaplist.yaml +102 -0
  441. package/core/resources/info/help/api.json +83 -0
  442. package/core/resources/info/help.json +436 -0
  443. package/core/resources/info/info.csv +315 -0
  444. package/core/resources/info/infolist.json +1758 -0
  445. package/core/resources/info/jrrp.json +92 -0
  446. package/core/resources/info/nicklist.yaml +2373 -0
  447. package/core/resources/info/notesInfo.json +1 -0
  448. package/core/resources/info/notice.json +11 -0
  449. package/core/resources/info/oldInfo/100/change.csv +218 -0
  450. package/core/resources/info/oldInfo/100/info.json +7 -0
  451. package/core/resources/info/oldInfo/101/change.csv +218 -0
  452. package/core/resources/info/oldInfo/101/info.json +7 -0
  453. package/core/resources/info/oldInfo/102/change.csv +223 -0
  454. package/core/resources/info/oldInfo/102/info.json +7 -0
  455. package/core/resources/info/oldInfo/103/change.csv +224 -0
  456. package/core/resources/info/oldInfo/103/info.json +7 -0
  457. package/core/resources/info/oldInfo/104/change.csv +225 -0
  458. package/core/resources/info/oldInfo/104/info.json +7 -0
  459. package/core/resources/info/oldInfo/105/change.csv +228 -0
  460. package/core/resources/info/oldInfo/105/info.json +7 -0
  461. package/core/resources/info/oldInfo/106/change.csv +229 -0
  462. package/core/resources/info/oldInfo/106/info.json +7 -0
  463. package/core/resources/info/oldInfo/108/change.csv +233 -0
  464. package/core/resources/info/oldInfo/108/info.json +7 -0
  465. package/core/resources/info/oldInfo/109/change.csv +235 -0
  466. package/core/resources/info/oldInfo/109/info.json +7 -0
  467. package/core/resources/info/oldInfo/110/change.csv +235 -0
  468. package/core/resources/info/oldInfo/110/info.json +7 -0
  469. package/core/resources/info/oldInfo/111/change.csv +242 -0
  470. package/core/resources/info/oldInfo/111/info.json +7 -0
  471. package/core/resources/info/oldInfo/112/change.csv +242 -0
  472. package/core/resources/info/oldInfo/112/info.json +7 -0
  473. package/core/resources/info/oldInfo/113/change.csv +244 -0
  474. package/core/resources/info/oldInfo/113/info.json +7 -0
  475. package/core/resources/info/oldInfo/115/change.csv +247 -0
  476. package/core/resources/info/oldInfo/115/info.json +7 -0
  477. package/core/resources/info/oldInfo/116/change.csv +249 -0
  478. package/core/resources/info/oldInfo/116/info.json +7 -0
  479. package/core/resources/info/oldInfo/118/change.csv +252 -0
  480. package/core/resources/info/oldInfo/118/info.json +7 -0
  481. package/core/resources/info/oldInfo/119/change.csv +255 -0
  482. package/core/resources/info/oldInfo/119/info.json +7 -0
  483. package/core/resources/info/oldInfo/120/change.csv +255 -0
  484. package/core/resources/info/oldInfo/120/info.json +7 -0
  485. package/core/resources/info/oldInfo/121/change.csv +257 -0
  486. package/core/resources/info/oldInfo/121/info.json +7 -0
  487. package/core/resources/info/oldInfo/122/change.csv +260 -0
  488. package/core/resources/info/oldInfo/122/info.json +7 -0
  489. package/core/resources/info/oldInfo/123/change.csv +260 -0
  490. package/core/resources/info/oldInfo/123/info.json +7 -0
  491. package/core/resources/info/oldInfo/124/change.csv +262 -0
  492. package/core/resources/info/oldInfo/124/info.json +7 -0
  493. package/core/resources/info/oldInfo/125/change.csv +266 -0
  494. package/core/resources/info/oldInfo/125/info.json +7 -0
  495. package/core/resources/info/oldInfo/126/change.csv +269 -0
  496. package/core/resources/info/oldInfo/126/info.json +7 -0
  497. package/core/resources/info/oldInfo/127/change.csv +270 -0
  498. package/core/resources/info/oldInfo/127/info.json +7 -0
  499. package/core/resources/info/oldInfo/128/change.csv +273 -0
  500. package/core/resources/info/oldInfo/128/info.json +7 -0
  501. package/core/resources/info/oldInfo/129/change.csv +274 -0
  502. package/core/resources/info/oldInfo/129/info.json +7 -0
  503. package/core/resources/info/oldInfo/130/change.csv +275 -0
  504. package/core/resources/info/oldInfo/130/info.json +7 -0
  505. package/core/resources/info/oldInfo/131/change.csv +278 -0
  506. package/core/resources/info/oldInfo/131/info.json +7 -0
  507. package/core/resources/info/oldInfo/132/change.csv +280 -0
  508. package/core/resources/info/oldInfo/132/info.json +7 -0
  509. package/core/resources/info/oldInfo/133/change.csv +284 -0
  510. package/core/resources/info/oldInfo/133/info.json +7 -0
  511. package/core/resources/info/oldInfo/134/change.csv +286 -0
  512. package/core/resources/info/oldInfo/134/info.json +7 -0
  513. package/core/resources/info/oldInfo/135/change.csv +290 -0
  514. package/core/resources/info/oldInfo/135/info.json +7 -0
  515. package/core/resources/info/oldInfo/136/change.csv +290 -0
  516. package/core/resources/info/oldInfo/136/info.json +7 -0
  517. package/core/resources/info/oldInfo/137/change.csv +293 -0
  518. package/core/resources/info/oldInfo/137/info.json +7 -0
  519. package/core/resources/info/oldInfo/138/change.csv +295 -0
  520. package/core/resources/info/oldInfo/138/info.json +7 -0
  521. package/core/resources/info/oldInfo/139/change.csv +295 -0
  522. package/core/resources/info/oldInfo/139/info.json +7 -0
  523. package/core/resources/info/oldInfo/140/change.csv +298 -0
  524. package/core/resources/info/oldInfo/140/info.json +7 -0
  525. package/core/resources/info/oldInfo/141/change.csv +300 -0
  526. package/core/resources/info/oldInfo/141/info.json +7 -0
  527. package/core/resources/info/oldInfo/142/change.csv +302 -0
  528. package/core/resources/info/oldInfo/142/info.json +7 -0
  529. package/core/resources/info/oldInfo/143/change.csv +303 -0
  530. package/core/resources/info/oldInfo/143/info.json +7 -0
  531. package/core/resources/info/oldInfo/144/change.csv +303 -0
  532. package/core/resources/info/oldInfo/144/info.json +7 -0
  533. package/core/resources/info/oldInfo/145/change.csv +305 -0
  534. package/core/resources/info/oldInfo/145/info.json +7 -0
  535. package/core/resources/info/oldInfo/146/change.csv +305 -0
  536. package/core/resources/info/oldInfo/146/info.json +7 -0
  537. package/core/resources/info/oldInfo/148/change.csv +307 -0
  538. package/core/resources/info/oldInfo/148/info.json +7 -0
  539. package/core/resources/info/oldInfo/149/change.csv +307 -0
  540. package/core/resources/info/oldInfo/149/info.json +7 -0
  541. package/core/resources/info/oldInfo/151/change.csv +309 -0
  542. package/core/resources/info/oldInfo/151/info.json +7 -0
  543. package/core/resources/info/oldInfo/152/change.csv +312 -0
  544. package/core/resources/info/oldInfo/152/info.json +7 -0
  545. package/core/resources/info/oldInfo/153/change.csv +313 -0
  546. package/core/resources/info/oldInfo/153/info.json +7 -0
  547. package/core/resources/info/oldInfo/154/change.csv +315 -0
  548. package/core/resources/info/oldInfo/154/info.json +7 -0
  549. package/core/resources/info/oldInfo/92/change.csv +204 -0
  550. package/core/resources/info/oldInfo/92/info.json +7 -0
  551. package/core/resources/info/oldInfo/93/change.csv +206 -0
  552. package/core/resources/info/oldInfo/93/info.json +7 -0
  553. package/core/resources/info/oldInfo/94/change.csv +209 -0
  554. package/core/resources/info/oldInfo/94/info.json +7 -0
  555. package/core/resources/info/oldInfo/95/change.csv +211 -0
  556. package/core/resources/info/oldInfo/95/info.json +7 -0
  557. package/core/resources/info/oldInfo/96/change.csv +216 -0
  558. package/core/resources/info/oldInfo/96/info.json +7 -0
  559. package/core/resources/info/oldInfo/98/change.csv +216 -0
  560. package/core/resources/info/oldInfo/98/info.json +7 -0
  561. package/core/resources/info/oldInfo/99/change.csv +217 -0
  562. package/core/resources/info/oldInfo/99/info.json +7 -0
  563. package/core/resources/info/oldNotesInfo.json +1 -0
  564. package/core/resources/info/sentences.json +1 -0
  565. package/core/resources/info/spinfo.json +362 -0
  566. package/core/resources/info/tips.txt +278 -0
  567. package/core/resources/otherill//351/233/252/351/231/215SP.png +0 -0
  568. package/core/resources/song-select.html +535 -0
  569. package/core/resources/themes/README.md +24 -0
  570. package/core/resources/themes/milthm/A.png +0 -0
  571. package/core/resources/themes/milthm/B.png +0 -0
  572. package/core/resources/themes/milthm/C.png +0 -0
  573. package/core/resources/themes/milthm/F.png +0 -0
  574. package/core/resources/themes/milthm/FC.png +0 -0
  575. package/core/resources/themes/milthm/S.png +0 -0
  576. package/core/resources/themes/milthm/V.png +0 -0
  577. package/core/resources/themes/milthm/arcgrosB19.css +36 -0
  578. package/core/resources/themes/milthm/b19.art +464 -0
  579. package/core/resources/themes/milthm/b19.css +1314 -0
  580. package/core/resources/themes/milthm/bg.png +0 -0
  581. package/core/resources/themes/milthm/clg.css +37 -0
  582. package/core/resources/themes/milthm/difficultyHistory.css +42 -0
  583. package/core/resources/themes/milthm/font.ttf +0 -0
  584. package/core/resources/themes/milthm/help.css +36 -0
  585. package/core/resources/themes/milthm/historyB30.css +48 -0
  586. package/core/resources/themes/milthm/info.yaml +45 -0
  587. package/core/resources/themes/milthm/list.css +39 -0
  588. package/core/resources/themes/milthm/phi.png +0 -0
  589. package/core/resources/themes/milthm/setting.css +37 -0
  590. package/core/resources/themes/milthm/sign.css +81 -0
  591. package/core/resources/themes/milthm/suggest.css +40 -0
  592. package/core/resources/themes/milthm/table.css +54 -0
  593. package/core/resources/themes/milthm/update.css +68 -0
  594. package/core/tests/aliasProposalService.test.js +82 -0
  595. package/core/tests/apiAccountDeletion.test.js +125 -0
  596. package/core/tests/apiPermission.test.js +44 -0
  597. package/core/tests/apiVersion.test.js +55 -0
  598. package/core/tests/b30Analysis.test.js +38 -0
  599. package/core/tests/backgroundIllustration.test.js +21 -0
  600. package/core/tests/botApiAuthRecovery.test.js +148 -0
  601. package/core/tests/botSyncService.test.js +42 -0
  602. package/core/tests/fileWatcherRegistry.test.js +44 -0
  603. package/core/tests/gameRecordPayload.test.js +34 -0
  604. package/core/tests/guessLetter.test.js +79 -0
  605. package/core/tests/makeRequestHandling.test.js +118 -0
  606. package/core/tests/marketOverflow.test.js +31 -0
  607. package/core/tests/platformTemplateCache.test.js +92 -0
  608. package/core/tests/pluginDataThemePreference.test.js +36 -0
  609. package/core/tests/processCleanup.test.js +58 -0
  610. package/core/tests/puppeteerShutdown.test.js +17 -0
  611. package/core/tests/renderPressureHistory.test.js +59 -0
  612. package/core/tests/saveStats.test.js +26 -0
  613. package/core/tests/themeInstallGuard.test.js +289 -0
  614. package/core/tests/themeManager.test.js +625 -0
  615. package/core/tests/themeManagerInit.test.js +11 -0
  616. package/core/tests/themeMarket.test.js +855 -0
  617. package/core/tests/themePageRouting.test.js +431 -0
  618. package/core/tests/themePolicy.test.js +28 -0
  619. package/core/tests/themeStorageRecovery.test.js +192 -0
  620. package/core/tests/userCredentialModuleBoundaries.test.js +41 -0
  621. package/core/tests/userCredentials.test.js +285 -0
  622. package/core/tsconfig.json +32 -0
  623. package/core/types/vendor.d.ts +14 -0
  624. package/lib/index.cjs +358 -0
  625. package/lib/index.d.cts +182 -0
  626. package/lib/index.d.ts +182 -0
  627. package/lib/index.js +320 -0
  628. package/package.json +74 -0
  629. package/readme.md +3 -0
@@ -0,0 +1,151 @@
1
+ import crypto from 'node:crypto'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import YAML from 'yaml'
5
+ import { redisPath } from '../game/constNum.js'
6
+ import { dataPath } from '../filesystem/path.js'
7
+ import { UserCredentials } from '../user/userCredentials.js'
8
+ import getInfo from '../game/getInfo.js'
9
+ import { redis } from '../../components/platform/index.js'
10
+ import logger from '../../components/Logger.js'
11
+ import Config from '../../components/Config.js'
12
+ import makeRequest from './makeRequest.js'
13
+ import { isApiVersionBlocked } from './apiVersion.js'
14
+
15
+ /** @import {AliasBotEvent, AliasProposalCreateInput, AliasProposalRecord, AliasVoteValue} from '../type/aliasProposal.js' */
16
+
17
+ const snapshotPath = path.join(dataPath, 'alias', 'approved-nicklist.yaml')
18
+ const lastApprovedSyncKey = `${redisPath}:aliasApproved:lastSync`
19
+
20
+ /**
21
+ * 严格校验公开 YAML 快照,拒绝非对象、非数组和空别名。
22
+ * @param {unknown} value YAML 解析结果
23
+ * @returns {Record<string, string[]>} 可安全合并的正式别名快照
24
+ */
25
+ export function validateApprovedAliasSnapshot(value) {
26
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid alias snapshot')
27
+ /** @type {Record<string, string[]>} */
28
+ const result = {}
29
+ for (const [songId, aliases] of Object.entries(value)) {
30
+ if (!songId.trim() || !Array.isArray(aliases)) throw new Error('Invalid alias snapshot')
31
+ result[songId] = aliases.map(alias => {
32
+ if (typeof alias !== 'string' || !alias.trim()) throw new Error('Invalid alias snapshot')
33
+ return alias.trim()
34
+ })
35
+ }
36
+ return result
37
+ }
38
+
39
+ class AliasProposalService {
40
+ /** 初始化任务状态;不会在构造阶段写入用户数据。 */
41
+ constructor() {
42
+ this.runningTask = false
43
+ this.initialized = false
44
+ }
45
+
46
+ /**
47
+ * 取得事件用户本地保存的 sessionToken。
48
+ * @param {AliasBotEvent} e 当前 Bot 事件
49
+ * @returns {Promise<phigrosToken>} 当前用户的 sessionToken
50
+ */
51
+ async tokenForEvent(e) {
52
+ const token = await UserCredentials.fromEvent(e).getSessionToken()
53
+ if (!token) throw new Error('请先绑定 sessionToken。')
54
+ return token
55
+ }
56
+
57
+ /**
58
+ * 创建别名提案;API 失败时不写本地待处理记录。
59
+ * @param {AliasBotEvent} e 当前 Bot 事件
60
+ * @param {AliasProposalCreateInput} input 提案内容
61
+ * @returns {Promise<AliasProposalRecord | null>} 新提案
62
+ */
63
+ async create(e, input) {
64
+ return UserCredentials.fromEvent(e).createAliasProposal(input)
65
+ }
66
+
67
+ /**
68
+ * @param {AliasBotEvent} e 当前 Bot 事件
69
+ * @returns {Promise<AliasProposalRecord[]>} 当前用户的提案
70
+ */
71
+ async mine(e) {
72
+ const token = await this.tokenForEvent(e)
73
+ return makeRequest.getAliasProposalsMine({ token, limit: 50 })
74
+ }
75
+
76
+ /**
77
+ * @param {AliasBotEvent} e 当前 Bot 事件
78
+ * @returns {Promise<AliasProposalRecord[]>} 正在公投的提案
79
+ */
80
+ async publicList(e) {
81
+ const token = await this.tokenForEvent(e)
82
+ return makeRequest.getAliasPublicProposals({ token, limit: 50 })
83
+ }
84
+
85
+ /**
86
+ * @param {AliasBotEvent} e 当前 Bot 事件
87
+ * @param {string} proposalId 提案 UUID
88
+ * @param {string} reason 10-500 字公审理由
89
+ * @returns {Promise<AliasProposalRecord | null>} 更新后的提案
90
+ */
91
+ async requestPublicReview(e, proposalId, reason) {
92
+ const token = await this.tokenForEvent(e)
93
+ return makeRequest.requestAliasPublicReview(proposalId, { token, reason })
94
+ }
95
+
96
+ /**
97
+ * 设置、修改或撤回公开投票。
98
+ * @param {AliasBotEvent} e 当前 Bot 事件
99
+ * @param {string} proposalId 提案 UUID
100
+ * @param {AliasVoteValue} value 1 赞成、-1 反对、0 撤票
101
+ * @returns {Promise<AliasProposalRecord | null>} 更新后的提案
102
+ */
103
+ async vote(e, proposalId, value) {
104
+ const token = await this.tokenForEvent(e)
105
+ return makeRequest.voteAliasProposal(proposalId, { token, value })
106
+ }
107
+
108
+ /**
109
+ * 下载并原子替换 Approved 快照,然后重建运行时别名索引。
110
+ * @param {boolean} [force=false] 是否忽略六小时成功间隔
111
+ * @returns {Promise<boolean>} 是否实际替换了快照
112
+ */
113
+ async syncApprovedSnapshot(force = false) {
114
+ const last = Number(await redis.get(lastApprovedSyncKey) || 0)
115
+ if (!force && Date.now() - last < 6 * 60 * 60 * 1000) return false
116
+ const parsed = validateApprovedAliasSnapshot(await makeRequest.getApprovedAliasSnapshot())
117
+ fs.mkdirSync(path.dirname(snapshotPath), { recursive: true })
118
+ const tempPath = `${snapshotPath}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`
119
+ try {
120
+ fs.writeFileSync(tempPath, YAML.stringify(parsed), 'utf8')
121
+ fs.renameSync(tempPath, snapshotPath)
122
+ } finally {
123
+ if (fs.existsSync(tempPath)) fs.unlinkSync(tempPath)
124
+ }
125
+ getInfo.setApprovedAliasSnapshot(parsed)
126
+ await redis.set(lastApprovedSyncKey, String(Date.now()))
127
+ return true
128
+ }
129
+
130
+ /** @returns {Promise<void>} 完成一次正式别名快照同步任务 */
131
+ async scheduledTask() {
132
+ if (!Config.getUserCfg('config', 'openPhiPluginApi') || isApiVersionBlocked()) return
133
+ if (this.runningTask) return
134
+ this.runningTask = true
135
+ try {
136
+ await this.syncApprovedSnapshot(false).catch(() => logger.warn('[phi-plugin] approved alias sync failed'))
137
+ } finally {
138
+ this.runningTask = false
139
+ }
140
+ }
141
+
142
+ /** @returns {Promise<void>} 启动时尝试拉取一次正式别名快照 */
143
+ async initialize() {
144
+ if (!Config.getUserCfg('config', 'openPhiPluginApi') || isApiVersionBlocked()) return
145
+ if (this.initialized) return
146
+ this.initialized = true
147
+ await this.syncApprovedSnapshot(true).catch(() => logger.warn('[phi-plugin] initial approved alias sync failed'))
148
+ }
149
+ }
150
+
151
+ export default new AliasProposalService()
@@ -0,0 +1,67 @@
1
+ /** 插件当前支持的 phi-plugin-api 协议版本。 */
2
+ export const SUPPORTED_API_VERSION = '1.1.0'
3
+
4
+ let versionBlocked = false
5
+
6
+ /**
7
+ * @typedef {'compatible'|'minor_mismatch'|'major_mismatch'|'invalid'} ApiVersionCompatibility
8
+ */
9
+
10
+ /**
11
+ * 解析严格的三段式语义版本号,可接受可选的 `v` 前缀。
12
+ * @param {unknown} value 待解析的版本号
13
+ * @returns {{major: number, minor: number, patch: number, normalized: string} | null} 解析结果
14
+ */
15
+ export function parseApiVersion(value) {
16
+ if (typeof value !== 'string') return null
17
+ const match = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.exec(value.trim())
18
+ if (!match) return null
19
+ const major = Number(match[1])
20
+ const minor = Number(match[2])
21
+ const patch = Number(match[3])
22
+ return { major, minor, patch, normalized: `${major}.${minor}.${patch}` }
23
+ }
24
+
25
+ /**
26
+ * 主版本不同视为不兼容;主版本外的任一版本差异仅提示更新。
27
+ * @param {unknown} apiVersion API 返回的协议版本
28
+ * @param {string} [supportedVersion] 插件支持的协议版本
29
+ * @returns {{status: ApiVersionCompatibility, apiVersion: string, supportedVersion: string}}
30
+ */
31
+ export function compareApiVersion(apiVersion, supportedVersion = SUPPORTED_API_VERSION) {
32
+ const actual = parseApiVersion(apiVersion)
33
+ const supported = parseApiVersion(supportedVersion)
34
+ if (!actual || !supported) {
35
+ return {
36
+ status: 'invalid',
37
+ apiVersion: typeof apiVersion === 'string' ? apiVersion.trim() : '',
38
+ supportedVersion,
39
+ }
40
+ }
41
+ const status = actual.major !== supported.major
42
+ ? 'major_mismatch'
43
+ : actual.minor !== supported.minor || actual.patch !== supported.patch
44
+ ? 'minor_mismatch'
45
+ : 'compatible'
46
+ return {
47
+ status,
48
+ apiVersion: actual.normalized,
49
+ supportedVersion: supported.normalized,
50
+ }
51
+ }
52
+
53
+ /**
54
+ * 更新当前运行周期的 API 协议阻断状态。
55
+ * @param {boolean} blocked 是否阻止所有 API 请求
56
+ */
57
+ export function setApiVersionBlocked(blocked) {
58
+ versionBlocked = blocked
59
+ }
60
+
61
+ /**
62
+ * 查询当前运行周期是否已因协议版本不兼容而关闭 API。
63
+ * @returns {boolean}
64
+ */
65
+ export function isApiVersionBlocked() {
66
+ return versionBlocked
67
+ }
@@ -0,0 +1,165 @@
1
+ import chalk from "chalk"
2
+ import logger from "../../components/Logger.js"
3
+ import { APIBASEURL } from "../game/constNum.js"
4
+ import https from 'node:https';
5
+ import axios from "axios";
6
+ import { Config } from "../../components/index.js";
7
+ import Version from "../../components/Version.js";
8
+ import botApiAuth from "./botApiAuth.js";
9
+ import { classifyApiConnectionError, getPhiApiUserMessage, isFatalBotIdentityError } from "./phiApiErrors.js";
10
+ import {
11
+ compareApiVersion,
12
+ isApiVersionBlocked,
13
+ setApiVersionBlocked,
14
+ SUPPORTED_API_VERSION,
15
+ } from './apiVersion.js';
16
+
17
+
18
+
19
+ export class AutoSeekApi {
20
+
21
+ constructor() {
22
+ //是否在等待API状态测试结果
23
+ this.waitApi = false;
24
+ //是否在轮询检测API状态
25
+ this.seekingApi = false;
26
+
27
+ this.openPhiPluginApi = false;
28
+ // 主版本不兼容或版本响应无效时阻止所有 API 业务请求。
29
+ this.remoteApiVersion = '';
30
+ }
31
+
32
+ /**
33
+ * 判断当前运行周期是否因 API 协议版本不兼容而被关闭。
34
+ * @returns {boolean}
35
+ */
36
+ isVersionBlocked() {
37
+ return isApiVersionBlocked()
38
+ }
39
+
40
+ /**
41
+ * 校验状态接口返回的 API 协议版本并更新运行时开关。
42
+ * @param {unknown} version API 返回的版本号
43
+ * @returns {boolean} 是否允许继续初始化 API 客户端
44
+ */
45
+ validateApiVersion(version) {
46
+ const result = compareApiVersion(version)
47
+ this.remoteApiVersion = result.apiVersion
48
+
49
+ if (result.status === 'major_mismatch') {
50
+ setApiVersionBlocked(true)
51
+ this.openPhiPluginApi = false
52
+ this.seekingApi = false
53
+ logger.error(
54
+ `[phi-plugin] API大版本不兼容:API ${result.apiVersion},插件支持 ${result.supportedVersion}。` +
55
+ '已自动关闭 API 功能,请更新 phi-plugin 后重启。'
56
+ )
57
+ return false
58
+ }
59
+
60
+ if (result.status === 'invalid') {
61
+ setApiVersionBlocked(true)
62
+ this.openPhiPluginApi = false
63
+ this.seekingApi = false
64
+ logger.error(
65
+ `[phi-plugin] API未返回有效的协议版本,插件支持 ${SUPPORTED_API_VERSION}。` +
66
+ '已自动关闭 API 功能,请更新 phi-plugin 后重启。'
67
+ )
68
+ return false
69
+ }
70
+
71
+ setApiVersionBlocked(false)
72
+ if (result.status === 'minor_mismatch') {
73
+ logger.warn(
74
+ `[phi-plugin] API小版本不一致:API ${result.apiVersion},插件支持 ${result.supportedVersion}。` +
75
+ '当前仍可继续使用,建议尽快更新 phi-plugin。'
76
+ )
77
+ }
78
+ return true
79
+ }
80
+
81
+ async testStatus() {
82
+ if (!Config.getUserCfg('config', 'openPhiPluginApi')) {
83
+ this.openPhiPluginApi = false
84
+ this.waitApi = false
85
+ this.seekingApi = false
86
+ return
87
+ }
88
+ if (this.waitApi) {
89
+ return
90
+ }
91
+
92
+ this.waitApi = true
93
+
94
+ logger.mark(chalk.yellow(`正在测试API链接...`))
95
+ let url = `${APIBASEURL}/status`
96
+ try {
97
+ const agent = new https.Agent({ rejectUnauthorized: false })
98
+ const res = await axios.get(url, { httpsAgent: agent, timeout: 5000 })
99
+ if (res.status != 200) {
100
+ logger.error(`[phi-plugin] API状态接口返回 HTTP ${res.status}`)
101
+ logger.mark(chalk.red(`API状态接口异常(HTTP ${res.status}),插件将在30秒后重试`))
102
+ this.openPhiPluginApi = false
103
+ this.seekApi()
104
+ } else {
105
+ // 当前接口使用 data 包装;保留对早期扁平响应的读取兼容。
106
+ const resdata = res.data?.data ?? res.data
107
+ if (!this.validateApiVersion(resdata?.version)) {
108
+ this.waitApi = false
109
+ return
110
+ }
111
+ logger.mark(chalk.green(`API地址测试成功!${resdata?.id || 'phi-plugin-api'} ${resdata.version}`))
112
+ this.openPhiPluginApi = true
113
+ try {
114
+ const identity = await botApiAuth.recoverAfterReconnect(Version.ver)
115
+ logger.mark(chalk.green(`API Bot身份已就绪:${identity.clientId}`))
116
+ const { default: botSyncService } = await import('./botSyncService.js')
117
+ await botSyncService.recoverAfterReconnect()
118
+ const { default: aliasProposalService } = await import('./aliasProposalService.js')
119
+ await aliasProposalService.initialize()
120
+ this.seekingApi = false
121
+ } catch (/** @type {any} */ error) {
122
+ logger[isFatalBotIdentityError(error) ? 'error' : 'warn'](
123
+ `[phi-plugin] API已恢复,但Bot身份恢复失败:${error?.code || getPhiApiUserMessage(error)}`
124
+ )
125
+ if (isFatalBotIdentityError(error)) {
126
+ this.seekingApi = false
127
+ } else {
128
+ this.seekApi()
129
+ }
130
+ }
131
+ }
132
+ } catch (e) {
133
+ const error = classifyApiConnectionError(e)
134
+ logger.error(`[phi-plugin] API连接检测失败:${error.code}`)
135
+ logger.mark(chalk.red(`${getPhiApiUserMessage(error)} 插件将在30秒后重试`))
136
+ this.openPhiPluginApi = false
137
+ this.seekApi()
138
+ }
139
+ this.waitApi = false
140
+ }
141
+
142
+ async seekApi() {
143
+ if (!Config.getUserCfg('config', 'openPhiPluginApi')) {
144
+ this.openPhiPluginApi = false
145
+ this.waitApi = false
146
+ this.seekingApi = false
147
+ return
148
+ }
149
+ if (isApiVersionBlocked()) {
150
+ this.openPhiPluginApi = false
151
+ this.seekingApi = false
152
+ return
153
+ }
154
+ if (this.seekingApi) {
155
+ return
156
+ }
157
+ this.seekingApi = true
158
+ while (this.seekingApi) {
159
+ await new Promise(resolve => setTimeout(resolve, 1000 * 30));
160
+ await this.testStatus()
161
+ }
162
+ }
163
+ }
164
+
165
+ export default new AutoSeekApi();
@@ -0,0 +1,208 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import axios from 'axios';
5
+ import YAML from 'yaml';
6
+ import Config from '../../components/Config.js';
7
+ import logger from '../../components/Logger.js';
8
+ import { configPath } from '../filesystem/path.js';
9
+ import { APIBASEURL } from '../game/constNum.js';
10
+ import { classifyApiConnectionError, isFatalBotIdentityError, PhiApiError } from './phiApiErrors.js';
11
+ import { isApiVersionBlocked } from './apiVersion.js';
12
+ import { SUPPORTED_API_VERSION } from './apiVersion.js';
13
+
14
+ const TIMEOUT = 5000;
15
+
16
+ function configIdentity() {
17
+ return {
18
+ clientId: String(Config.getUserCfg('config', 'apiBotClientId') || '').trim(),
19
+ secret: String(Config.getUserCfg('config', 'apiBotClientSecret') || '').trim(),
20
+ secretVersion: Number(Config.getUserCfg('config', 'apiBotSecretVersion') || 0),
21
+ };
22
+ }
23
+
24
+ /** @param {{clientId: string, secret: string, secretVersion: number}} identity */
25
+ function writeIdentityAtomic(identity) {
26
+ const target = path.join(configPath, 'config.yaml');
27
+ const current = YAML.parse(fs.readFileSync(target, 'utf8')) || {};
28
+ current.apiBotClientId = identity.clientId;
29
+ current.apiBotClientSecret = identity.secret;
30
+ current.apiBotSecretVersion = identity.secretVersion;
31
+ const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
32
+ fs.writeFileSync(temp, YAML.stringify(current), { encoding: 'utf8', mode: 0o600 });
33
+ fs.renameSync(temp, target);
34
+ delete Config.config['config.config'];
35
+ }
36
+
37
+ /** @param {any} response */
38
+ function parseResponse(response) {
39
+ const data = response.data;
40
+ const nestedError = data?.error && typeof data.error === 'object' ? data.error : null;
41
+ if (response.status < 200 || response.status >= 300 || data?.error) {
42
+ throw new PhiApiError(
43
+ nestedError?.message || data?.message || (typeof data?.error === 'string' ? data.error : '') || `API request failed (${response.status})`,
44
+ response.status,
45
+ nestedError?.code || data?.code || data?.errorCode || 'api_request_failed',
46
+ { body: data, retryAfter: response.headers?.['retry-after'] },
47
+ );
48
+ }
49
+ return data;
50
+ }
51
+
52
+ export class BotApiAuth {
53
+ constructor() {
54
+ this.ready = false;
55
+ this.initializing = null;
56
+ this.fatalError = null;
57
+ this.fatalIdentity = '';
58
+ }
59
+
60
+ /** @returns {string} 本地配置中的 API 签发 Bot clientId,不发起网络请求 */
61
+ getClientId() {
62
+ return configIdentity().clientId;
63
+ }
64
+
65
+ async initialize(pluginVersion = SUPPORTED_API_VERSION) {
66
+ if (isApiVersionBlocked()) {
67
+ throw new PhiApiError(
68
+ 'API协议大版本不兼容,请更新 phi-plugin 后重启',
69
+ 0,
70
+ 'api_version_incompatible',
71
+ );
72
+ }
73
+ if (this.ready) return configIdentity();
74
+ const current = configIdentity();
75
+ const fingerprint = `${current.clientId}:${current.secretVersion}:${crypto.createHash('sha256').update(current.secret).digest('hex')}`;
76
+ if (this.fatalError && this.fatalIdentity === fingerprint) throw this.fatalError;
77
+ if (this.fatalIdentity !== fingerprint) {
78
+ this.fatalError = null;
79
+ this.fatalIdentity = '';
80
+ }
81
+ if (this.initializing) return this.initializing;
82
+ this.initializing = this.initializeOnce(pluginVersion).finally(() => { this.initializing = null; });
83
+ return this.initializing;
84
+ }
85
+
86
+ /** @param {string} pluginVersion */
87
+ async initializeOnce(pluginVersion) {
88
+ const identity = configIdentity();
89
+ if (!identity.clientId || !identity.secret || !Number.isSafeInteger(identity.secretVersion) || identity.secretVersion < 1) {
90
+ return this.register(pluginVersion);
91
+ }
92
+ try {
93
+ await this.signedRequest('/bot-clients/self', undefined, 'GET', identity);
94
+ this.ready = true;
95
+ this.fatalError = null;
96
+ return identity;
97
+ } catch (/** @type {any} */ error) {
98
+ this.ready = false;
99
+ if (isFatalBotIdentityError(error)) {
100
+ this.fatalError = error;
101
+ this.fatalIdentity = `${identity.clientId}:${identity.secretVersion}:${crypto.createHash('sha256').update(identity.secret).digest('hex')}`;
102
+ logger.error(`[phi-plugin] API Bot凭证不可用,新平台API操作已停止:${error.code || error.message}`);
103
+ } else {
104
+ this.fatalError = null;
105
+ this.fatalIdentity = '';
106
+ logger.warn(`[phi-plugin] API Bot身份暂时无法验证,将在API恢复后重试:${error.code || error.message}`);
107
+ }
108
+ throw error;
109
+ }
110
+ }
111
+
112
+ async register(pluginVersion = SUPPORTED_API_VERSION) {
113
+ let response;
114
+ try {
115
+ response = await axios.post(`${APIBASEURL}/bot-clients/register`, JSON.stringify({
116
+ pluginName: 'phi-plugin',
117
+ pluginVersion,
118
+ }), {
119
+ headers: { 'Content-Type': 'application/json' },
120
+ timeout: TIMEOUT,
121
+ validateStatus: () => true,
122
+ });
123
+ } catch (error) {
124
+ throw classifyApiConnectionError(error);
125
+ }
126
+ const data = parseResponse(response);
127
+ const identity = {
128
+ clientId: String(data.clientId || ''),
129
+ secret: String(data.secret || ''),
130
+ secretVersion: Number(data.secretVersion || 0),
131
+ };
132
+ if (!identity.clientId || !identity.secret || identity.secretVersion < 1) {
133
+ throw new PhiApiError('API returned an invalid Bot credential', 502, 'invalid_registration_response');
134
+ }
135
+ writeIdentityAtomic(identity);
136
+ this.ready = true;
137
+ this.fatalError = null;
138
+ this.fatalIdentity = '';
139
+ logger.mark(`[phi-plugin] API Bot身份已签发:${identity.clientId}`);
140
+ if (data.claimUrl) logger.mark(`[phi-plugin] Bot认领链接(15分钟有效):${data.claimUrl}`);
141
+ return { ...identity, claimUrl: data.claimUrl, claimExpiresAt: data.claimExpiresAt };
142
+ }
143
+
144
+ async recoverAfterReconnect(pluginVersion = SUPPORTED_API_VERSION) {
145
+ return this.initialize(pluginVersion);
146
+ }
147
+
148
+ async reset(pluginVersion = SUPPORTED_API_VERSION) {
149
+ this.ready = false;
150
+ return this.register(pluginVersion);
151
+ }
152
+
153
+ async getClaimLink() {
154
+ await this.initialize();
155
+ return this.signedRequest('/bot-clients/self/claim-code', {}, 'POST');
156
+ }
157
+
158
+ /** @param {string} method @param {string} originalPath @param {string} rawBody @param {{clientId:string, secret:string, secretVersion:number}} [identity] @returns {Record<string, string>} */
159
+ sign(method, originalPath, rawBody, identity = configIdentity()) {
160
+ if (!identity.clientId || !identity.secret || identity.secretVersion < 1) {
161
+ throw new PhiApiError('API Bot身份尚未初始化', 0, 'bot_identity_missing');
162
+ }
163
+ const timestamp = Math.floor(Date.now() / 1000).toString();
164
+ const nonce = crypto.randomBytes(18).toString('base64url');
165
+ const bodyHash = crypto.createHash('sha256').update(rawBody || '').digest('hex');
166
+ const canonical = [method.toUpperCase(), originalPath, timestamp, nonce, bodyHash].join('\n');
167
+ const signature = crypto.createHmac('sha256', identity.secret).update(canonical).digest('base64url');
168
+ return {
169
+ 'X-Phi-Bot-Client-Id': identity.clientId,
170
+ 'X-Phi-Bot-Key-Version': String(identity.secretVersion),
171
+ 'X-Phi-Bot-Timestamp': timestamp,
172
+ 'X-Phi-Bot-Nonce': nonce,
173
+ 'X-Phi-Bot-Signature': signature,
174
+ };
175
+ }
176
+
177
+ /** @param {string} originalPath @param {any} body @param {string} [method] @param {{clientId:string, secret:string, secretVersion:number}} [identity] @param {Record<string,string>} [extraHeaders] @param {{timeout?:number}} [requestOptions] */
178
+ async signedRequest(originalPath, body, method = 'POST', identity = configIdentity(), extraHeaders = {}, requestOptions = {}) {
179
+ if (isApiVersionBlocked()) {
180
+ throw new PhiApiError(
181
+ 'API协议大版本不兼容,请更新 phi-plugin 后重启',
182
+ 0,
183
+ 'api_version_incompatible',
184
+ );
185
+ }
186
+ const upperMethod = method.toUpperCase();
187
+ const rawBody = upperMethod === 'GET' ? '' : JSON.stringify(body ?? {});
188
+ const headers = { ...this.sign(upperMethod, originalPath, rawBody, identity), ...extraHeaders };
189
+ if (upperMethod !== 'GET') headers['Content-Type'] = 'application/json';
190
+ let response;
191
+ try {
192
+ response = await axios.request({
193
+ url: `${APIBASEURL}${originalPath}`,
194
+ method: upperMethod,
195
+ headers,
196
+ data: upperMethod === 'GET' ? undefined : rawBody,
197
+ timeout: requestOptions.timeout ?? TIMEOUT,
198
+ validateStatus: () => true,
199
+ });
200
+ } catch (error) {
201
+ throw classifyApiConnectionError(error);
202
+ }
203
+ return parseResponse(response);
204
+ }
205
+
206
+ }
207
+
208
+ export default new BotApiAuth();
@@ -0,0 +1,78 @@
1
+ import logger from '../../components/Logger.js'
2
+ import Version from '../../components/Version.js'
3
+ import Config from '../../components/Config.js'
4
+ import platform from '../../components/platform/index.js'
5
+ import makeRequest from './makeRequest.js'
6
+ import { isApiVersionBlocked } from './apiVersion.js'
7
+ import themePolicy from '../theme/policy.js'
8
+
9
+ export class BotSyncService {
10
+ constructor() {
11
+ this.running = false
12
+ this.initialized = false
13
+ this.reportRenderPressure = false
14
+ /** @type {Set<string>} */
15
+ this.pendingAcknowledgements = new Set()
16
+ }
17
+
18
+ /**
19
+ * 执行一次 Bot 状态同步;成功送达的消息在下一次请求中确认。
20
+ * @returns {Promise<void>}
21
+ */
22
+ async sync() {
23
+ if (this.running) return
24
+ this.running = true
25
+ const acknowledgedMessageIds = [...this.pendingAcknowledgements]
26
+ try {
27
+ // 始终在本地滚动采样;服务端许可只决定是否把匿名压力历史放入请求。
28
+ const renderPressure = (await import('../render/picmodle.js')).default.takeRenderPressureSnapshot()
29
+ const response = await makeRequest.syncBot({
30
+ pluginVersion: Version.ver,
31
+ acknowledgedMessageIds,
32
+ ...(this.reportRenderPressure ? { renderPressure } : {}),
33
+ })
34
+ for (const id of acknowledgedMessageIds) this.pendingAcknowledgements.delete(id)
35
+ this.reportRenderPressure = response?.reporting?.renderPressure === true
36
+ if (response?.themePolicy) themePolicy.apply(response.themePolicy)
37
+
38
+ for (const message of response?.messages || []) {
39
+ try {
40
+ const sent = await platform.relpyPrivate(message.target.platformId, message.text)
41
+ if (sent !== false && sent != null) this.pendingAcknowledgements.add(message.id)
42
+ } catch (error) {
43
+ logger.warn(`[phi-plugin] Bot消息私聊失败,将在下次同步重试:${message.id}`, error)
44
+ }
45
+ }
46
+ } finally {
47
+ this.running = false
48
+ }
49
+ }
50
+
51
+ /** 启动时立即同步一次;失败由一分钟周期和 API 重连流程继续恢复。 */
52
+ async initialize() {
53
+ if (!Config.getUserCfg('config', 'openPhiPluginApi') || isApiVersionBlocked()) return
54
+ if (this.initialized) return
55
+ this.initialized = true
56
+ await this.sync().catch(error => {
57
+ logger.warn('[phi-plugin] 初始 Bot状态同步失败,将稍后重试', error)
58
+ })
59
+ }
60
+
61
+ /** API 恢复连接后立即补发心跳并拉取消息。 */
62
+ async recoverAfterReconnect() {
63
+ this.initialized = true
64
+ await this.sync().catch(error => {
65
+ logger.warn('[phi-plugin] API恢复后的 Bot状态同步失败', error)
66
+ })
67
+ }
68
+
69
+ /** @returns {Promise<void>} 一分钟平台任务入口 */
70
+ async scheduledTask() {
71
+ if (!Config.getUserCfg('config', 'openPhiPluginApi') || isApiVersionBlocked()) return
72
+ await this.sync().catch(error => {
73
+ logger.warn('[phi-plugin] Bot状态同步失败', error)
74
+ })
75
+ }
76
+ }
77
+
78
+ export default new BotSyncService()