update-paper-plugins/update-plugins.py

65 lines
2.5 KiB
Python
Raw Normal View History

2024-09-18 02:31:30 +00:00
from dotenv import load_dotenv
from os import environ as env
from requests import request
2024-09-18 04:01:58 +00:00
from ast import literal_eval as litEval
2024-09-18 02:31:30 +00:00
# Try to load cache
print("[[ Info ]] Trying to load installed versions from cache...")
knownVersions = {}
try:
from cache import knownVersions
print(f"[[ Info ]] Loaded {len(knownVersions)} installed versions from cache...")
except ImportError:
# Fallback to just a warning
print("""[[ Warn ]] Failed to load versions from cache
[[ Warn ]] If this is not your first time running this script, it's recommended you investigate why.""")
load_dotenv()
hangarPlugins = {
# "slug-of-plugin": {"Channel": "channel-to-pull", "Version": 'version-to-pull or "latest"'}
}
spigotPlugins = {
2024-09-18 04:01:58 +00:00
# "resource-id-of-plugin": {"Version": 'version-id-to-pull or "latest"', "Name": "Friendly name used for local downloads of the plugin"}
2024-09-18 02:31:30 +00:00
}
geyser = True
floodgate = True
if hangarPlugins and not env.get("HANGAR_KEY", ""):
print(
"""!! Notice !! This script cannot download hangar plugins without a hangar api key!
!! Notice !! Please signup for an account at https://hangar.papermc.io/auth/signup
!! Notice !! Then generate an api key with the "view_public_info" permission at https://hangar.papermc.io/auth/settings/api-keys
!! Notice !! Since there's no hangar api key, the defined list of hangar plugins will be COMPLETELY IGNORED on this run."""
)
hangarPlugins = {}
if hangarPlugins:
for plugin in hangarPlugins:
2024-09-18 04:01:58 +00:00
version = hangarPlugins[plugin]["Version"]
if version == "latest":
version = request("GET", f"https://hangar.papermc.io/api/v1/projects/{plugin}/latest?channel={channel}").text
if not knownVersions.get(plugin, "") or knownVersions[plugin] != version:
# download update
knownVersions[plugin] = version
2024-09-18 02:31:30 +00:00
if spigotPlugins:
for plugin in spigotPlugins:
version = spigotPlugins[plugin]["Version"]
2024-09-18 04:01:58 +00:00
if version == "latest":
version = litEval(request("GET", f"https://api.spiget.org/v2/resources/{plugin}/versions/latest").text)["id"]
2024-09-18 02:31:30 +00:00
if not knownVersions.get(plugin, "") or knownVersions[plugin] != version:
# download update
knownVersions[plugin] = version
if geyser:
# download https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot
...
if floodgate:
# download https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot
...
# write cache file