diff --git a/aard_inventory.xml b/aard_inventory.xml index f75ed29..d6a083e 100644 --- a/aard_inventory.xml +++ b/aard_inventory.xml @@ -83,7 +83,7 @@ dbot.callback : Module to help manage callback functions and parameters save_state="y" date_written="2017-08-12 08:45:15" requires="4.98" - version="1.4" + version="1.3" > dinv search [id | full] @@ -147,6 +147,7 @@ Usage dinv notify [none | light | standard | all] dinv cache [reset | size] [recent | frequent | all] <# entries> dinv tags [on | off] + dinv reload Using equipment items dinv consume [add | remove | display | buy | small | big] @@ -155,6 +156,7 @@ Usage Plugin info dinv version + dinv update confirm dinv help @@ -550,6 +552,26 @@ Feature Wishlist > + + + + + + @@ -1432,6 +1454,12 @@ end -- inv.config.new -- inv.cli.version.fn(name, line, wildcards) -- inv.cli.version.usage() -- inv.cli.version.examples() +-- inv.cli.update.fn(name, line, wildcards) +-- inv.cli.update.usage() +-- inv.cli.update.examples() +-- inv.cli.reload.fn(name, line, wildcards) +-- inv.cli.reload.usage() +-- inv.cli.reload.examples() -- inv.cli.help.fn(name, line, wildcards) -- inv.cli.help.usage() -- inv.cli.help.examples() @@ -1473,6 +1501,7 @@ function inv.cli.fullUsage() inv.cli.notify.usage() inv.cli.cache.usage() inv.cli.tags.usage() + inv.cli.reload.usage() dbot.print("\n@C Using equipment items@W") inv.cli.consume.usage() @@ -1481,6 +1510,7 @@ function inv.cli.fullUsage() dbot.print("\n@C Plugin info@w") inv.cli.version.usage() + inv.cli.update.usage() inv.cli.help.usage() end -- inv.cli.fullUsage @@ -1517,7 +1547,7 @@ end -- inv.cli.build.fn function inv.cli.build.usage() - dbot.print("@W " .. pluginNameCmd .. " build @Y[confirm]@w") + dbot.print("@W " .. pluginNameCmd .. " build confirm@w") end -- inv.cli.build.usage @@ -3850,6 +3880,32 @@ Examples: end -- inv.cli.tags.examples +inv.cli.reload = {} +function inv.cli.reload.fn(name, line, wildcards) + dbot.info("Reloading plugin") + + return dbot.reload() +end -- inv.cli.reload.fn + + +function inv.cli.reload.usage() + dbot.print("@W " .. pluginNameCmd .. " reload") +end -- inv.cli.reload.usage + + +function inv.cli.reload.examples() + dbot.print("@W\nUsage:\n") + inv.cli.reload.usage() + dbot.print( +[[@W +This will unload and then load the plugin. You should not need to do this but +it never hurts to have the ability if something goes wrong. This is equivalent +to opening the plugin menu and reinstalling the plugin. +]]) + +end -- inv.cli.reload.examples + + inv.cli.portal = {} function inv.cli.portal.fn(name, line, wildcards) local command = wildcards[1] or "" @@ -4342,6 +4398,32 @@ Come on peeps, just type "@Gdinv version@W". It's not that hard. :P end -- inv.cli.version.examples +inv.cli.update = {} +function inv.cli.update.fn(name, line, wildcards) + dbot.info("Updating plugin: Please do not enter anything until the update completes") + + return dbot.update() +end -- inv.cli.update.fn + + +function inv.cli.update.usage() + dbot.print("@W " .. pluginNameCmd .. " update confirm") +end -- inv.cli.update.usage + + +function inv.cli.update.examples() + dbot.print("@W\nUsage:\n") + inv.cli.update.usage() + dbot.print( +[[@W +This will compare your version of the plugin with the latest stable release. +If your plugin is out of date, the plugin will download the latest version of +itself and load it. +]]) + +end -- inv.cli.update.examples + + inv.cli.help = {} function inv.cli.help.fn(name, line, wildcards) local command = wildcards[1] or "" @@ -15917,6 +15999,89 @@ function dbot.getTime() end -- dbot.getTime +---------------------------------------------------------------------------------------------------- +-- dbot.reload: Reloads the current plugin +-- +-- Note: This code was derived from part of a plugin by Arcidayne. Thanks Arcidayne! +---------------------------------------------------------------------------------------------------- + +function dbot.reload() + local scriptPrefix = GetAlphaOption("script_prefix") + local retval + + -- If the user has not already specified the script prefix for this version of mush, pick a + -- reasonable default value + if (scriptPrefix == "") then + scriptPrefix = "\\\\\\" + SetAlphaOption("script_prefix", scriptPrefix) + end + + -- Tell mush to reload the plugin in one second. We can't do it directly here because a + -- plugin can't unload itself. Even if it could, how could it tell mush to load it again + -- if it weren't installed? + retval = Execute(scriptPrefix.."DoAfterSpecial(1, \"ReloadPlugin('"..GetPluginID().."')\", sendto.script)") + if (retval ~= 0) then + dbot.warn("dbot.reload: Failed to reload the plugin: mush error " .. retval) + retval = DRL_RET_INTERNAL_ERROR + end -- if + + return retval +end -- dbot.reload + + +---------------------------------------------------------------------------------------------------- +-- dbot.update: If the current plugin isn't the latest published version, update it, and reload it +-- +-- Note: This code is derived from a plugin written by Arcidayne. Thanks Arcidayne! +---------------------------------------------------------------------------------------------------- + +function dbot.update() + local retval = DRL_RET_SUCCESS + local url = "https://raw.githubusercontent.com/Aardurel/aard-plugins/master/aard_inventory.xml" + local asyncOk, async = pcall (require, "async") + + if asyncOk then + async.doAsyncRemoteRequest(url, dbot.updateRaw, "HTTPS") + else + dbot.warn("dbot.update: Failed to retrieve plugin update") + retval = DRL_RET_INTERNAL_ERROR + end + + return retval +end -- dbot.update + + +function dbot.updateRaw(retval, page, status, headers, fullStatus, requestUrl) + local currentVersion = GetPluginInfo(GetPluginID(), 19) or 0 + + if (status ~= 200) then + dbot.warn("dbot.updateRaw: Failed to retrieve remote plugin version") + + else + local remoteVersion = tonumber(string.match(page, '%s%s+version="([0-9%.]+)"')) or 0 + + if (remoteVersion == currentVersion) then + dbot.info("Your plugin is up-to-date at version \"" .. currentVersion .. "\"") + + elseif (remoteVersion < currentVersion) then + dbot.warn("Your current plugin (v" .. currentVersion .. ") is reporting that it " .. + "is newer than the latest official release (v" .. remoteVersion .. ")") + + else + dbot.info("Updating plugin from version " .. currentVersion .. " to version " .. remoteVersion) + + local pluginFile = GetPluginInfo(GetPluginID(), 6) + local file = io.open(pluginFile, "w") + file:write(page) + file:close() + dbot.reload() + end -- if + + end -- if + +end -- dbot.updateRaw + + ---------------------------------------------------------------------------------------------------- -- dbot.tonumber: version of tonumber that strips out commas from a number ----------------------------------------------------------------------------------------------------