LatestVersion.py 869 B

12345678910111213141516171819202122232425262728
  1. from Core.Debug import LogWarning
  2. import requests
  3. import json
  4. LAUNCHER_MANIFSET_URL = 'https://piston-meta.mojang.com/mc/game/version_manifest.json'
  5. def fetch_mainfest():
  6. try:
  7. response = requests.get(LAUNCHER_MANIFSET_URL)
  8. return json.loads(response.content)
  9. except Exception as e:
  10. LogWarning(f'获取版本列表失败:{e.with_traceback()}')
  11. return {}
  12. MANIFSET = fetch_mainfest()
  13. LATEST_VERSIONS = {'snapshot':'','release':''}
  14. LATEST_VERSIONS.update(MANIFSET['latest'])
  15. FULL_VERSIONS = MANIFSET.get('versions')
  16. def script(card,arg,res):
  17. if len(arg) <= 2 or (count := int(arg[2])) <= 1:
  18. return f"{LATEST_VERSIONS[arg[1]]} | latest = true"
  19. for version in FULL_VERSIONS:
  20. if version['type'] == arg[1]:
  21. count -= 1
  22. if count == 0:
  23. return version['id']
  24. return ''