From d65a1c8d27fbe5c32559f1e62208c9bcd1294182 Mon Sep 17 00:00:00 2001 From: AreiaAard Date: Wed, 28 Apr 2021 11:37:08 -0400 Subject: [PATCH] Add Update module --- areia_consider.xml | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/areia_consider.xml b/areia_consider.xml index ef4251d..277b0f9 100644 --- a/areia_consider.xml +++ b/areia_consider.xml @@ -669,6 +669,59 @@ end +-------------------------------------------------- +-- Update +-------------------------------------------------- + +Update = {} + +function Update.initialize() + AddAlias("alias_update", + "^ac\\s+update$", "", + alias_flag.Enabled + alias_flag.IgnoreAliasCase + alias_flag.RegularExpression + alias_flag.Temporary, + "Update.update" + ) + + Update.URL = "https://raw.githubusercontent.com/AreiaAard/Areia_Consider/main/areia_consider.xml" +end + +function Update.update() + async_ok, async = pcall (require, "async") + if async_ok then + plugin_page = async.doAsyncRemoteRequest(Update.URL, Update.raw_get, "HTTPS") + else + Utility.plugin_msg("Error. Update failed.") + end +end + +function Update.raw_get(retval, page, status, headers, full_status, request_url) + local PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1) + local PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19) + local raw_version = -1 + if (status == 200) then + raw_version = tonumber(string.match(page, '%s%s+version="([0-9%.]+)"')) + end + if (raw_version == PLUGIN_VERSION) then + Utility.plugin_msg(string.format("@Y%s @wis up-to-date with the current version.", PLUGIN_NAME)) + elseif (raw_version > PLUGIN_VERSION) then + Utility.plugin_msg(string.format("Updating @Y%s @wfrom v%s to v%s.", PLUGIN_NAME, PLUGIN_VERSION, raw_version)) + Utility.print(" Please do not touch anything.") + local file = io.open(GetPluginInfo(GetPluginID(), 6), "w") + file:write(page) + file:close() + end + if (GetAlphaOption("script_prefix") == "") then + SetAlphaOption("script_prefix", "\\\\\\") + end + Execute(string.format( + "%sDoAfterSpecial(1, \"ReloadPlugin('%s')\", sendto.script)", + GetAlphaOption("script_prefix"), GetPluginID() + )) + Utility.plugin_msg("Update completed.") +end + + + -------------------------------------------------- -- Utility --------------------------------------------------