This commit is contained in:
Firepup Sixfifty 2024-09-18 16:57:57 -05:00
parent 4f0ddb9492
commit 1e28015e78
Signed by: Firepup650
SSH key fingerprint: SHA256:cb8sEJwc0kQJ6/nMUhscWRe35itf0NFMdSKl3v4qt48

View file

@ -8,49 +8,90 @@ print("[[ Info ]] Trying to load installed versions from cache...")
knownVersions = {} knownVersions = {}
try: try:
from cache import knownVersions from cache import knownVersions
print(f"[[ Info ]] Loaded {len(knownVersions)} installed versions from cache...") print(f"[[ Info ]] Loaded {len(knownVersions)} installed versions from cache...")
except ImportError: except ImportError:
# Fallback to just a warning # Fallback to just a warning
print("""[[ Warn ]] Failed to load versions from cache print(
[[ Warn ]] If this is not your first time running this script, it's recommended you investigate why.""") """|| 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() load_dotenv()
hangarPlugins = { hangarPlugins: dict[str, dict[str, str]] = {
# "slug-of-plugin": {"Channel": "channel-to-pull", "Version": 'version-to-pull or "latest"'} # "slug-of-plugin": {"Channel": "channel-to-pull", "Version": 'version-to-pull or "latest"'}
} }
spigotPlugins = { spigotPlugins: dict[str, dict[str, str]] = {
# "resource-id-of-plugin": {"Version": 'version-id-to-pull or "latest"', "Name": "Friendly name used for local downloads of the plugin"} # "resource-id-of-plugin": {"Version": 'version-id-to-pull or "latest"', "Name": "Friendly name used for local downloads of the plugin"}
} }
geyser = True geyser = True
floodgate = True floodgate = True
HANGAR_KEY = env.get("HANGAR_KEY", "")
if hangarPlugins and not env.get("HANGAR_KEY", ""): if hangarPlugins and not HANGAR_KEY:
print( print(
"""!! Notice !! This script cannot download hangar plugins without a hangar api key! """!! Notice !! This script cannot/will not download hangar plugins without a hangar api key!
!! Notice !! Please signup for an account at https://hangar.papermc.io/auth/signup !! 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 !! Then generate an api key with the "view_public_info" permission at https://hangar.papermc.io/auth/settings/api-keys
!! Notice !! While I'm not 100% sure if they *enforce* the requirement, the API docs very clearly state that an API key is required.
!! Notice !! So even if it's not required *now* it could become enforced later.
!! Notice !! Since there's no hangar api key, the defined list of hangar plugins will be COMPLETELY IGNORED on this run.""" !! Notice !! Since there's no hangar api key, the defined list of hangar plugins will be COMPLETELY IGNORED on this run."""
) )
hangarPlugins = {} hangarPlugins = {}
if hangarPlugins: if hangarPlugins:
print("[[ Info ]] Checking for updates in plugins from hangar")
for plugin in hangarPlugins: for plugin in hangarPlugins:
print(f"[[ Info ]] Checking for updates for plugin {plugin}")
version = hangarPlugins[plugin]["Version"] version = hangarPlugins[plugin]["Version"]
if version == "latest": if version == "latest":
version = request("GET", f"https://hangar.papermc.io/api/v1/projects/{plugin}/latest?channel={channel}").text version = request(
"GET",
f"https://hangar.papermc.io/api/v1/projects/{plugin}/latest?channel={hangarPlugins[plugin]['Channel']}",
headers = {"Authorization": f"Bearer ${HANGAR_KEY}"}
).text
print(
"?? DBUG ?? Latest version of {plugin} detected to be {version}, currently installed is {knownVersions[plugin] if knownPlugins.get(plugin, False) else 'N/A'}"
)
if not knownVersions.get(plugin, "") or knownVersions[plugin] != version: if not knownVersions.get(plugin, "") or knownVersions[plugin] != version:
# download update # download update
print(
f"[[ Info ]] Updating plugin {plugin}"
)
with open(f"plugins/hangar-{plugin}-{version}", "wb") as f:
f.write(request("GET", f"https://https://hangar.papermc.io/api/v1/projects/{plugin}/versions/{version}/PAPER/download").content)
print(
f"[[ Info ]] Updated plugin {plugin} from {knownVersions[plugin] if knownVersions.get(plugin, False) else 'N/A'} to {version}"
)
knownVersions[plugin] = version knownVersions[plugin] = version
else:
print(f"[[ Info ]] No updates available for {plugin}.")
if spigotPlugins: if spigotPlugins:
print("[[ Info ]] Checking for updates in plugins from spigot")
for plugin in spigotPlugins: for plugin in spigotPlugins:
pluginName = spigotPlugins[plugin]["Name"]
print(f"[[ Info ]] Checking for updates for plugin {pluginName}")
version = spigotPlugins[plugin]["Version"] version = spigotPlugins[plugin]["Version"]
if version == "latest": if version == "latest":
version = litEval(request("GET", f"https://api.spiget.org/v2/resources/{plugin}/versions/latest").text)["id"] version = litEval(
request(
"GET",
f"https://api.spiget.org/v2/resources/{plugin}/versions/latest",
).text
)["id"]
print(
f"?? DBUG ?? Latest version of {pluginName}({plugin}) detected to be {version}, currently installed is {knownVersions[plugin] if knownVersions.get(plugin, False) else 'N/A'}"
)
if not knownVersions.get(plugin, "") or knownVersions[plugin] != version: if not knownVersions.get(plugin, "") or knownVersions[plugin] != version:
# download update # download update
with open(f"plugins/spigot-{pluginName}-{version}", "wb") as f:
f.write(request("GET", f"https://api.spiget.org/v2/resources/{plugin}/versions/{version}/download").content)
print(
f"[[ Info ]] Updated plugin {pluginName} from {knownVersions[plugin] if knownVersions.get(plugin, False) else 'N/A'} to {version}"
)
knownVersions[plugin] = version knownVersions[plugin] = version
if geyser: if geyser: