Hi,
I'm developing a set of plugins for the MUD I play on, and sharing them to all the other players.
I'm also maintaining some online tables (made with Google Sheets) automatically updated by a form (made with Google Form) that any player can fill by copy/pasting the MUD output (for object identifications and such).
I'd like to develop a couple of new plugins for Mudlet in order to:
- trigger an HTTP/REST/ANYTHING request every time an object is identified by a player (to update the Google Sheets database)
- download data from an online database every now and then (possibly, my Google Sheet database converted in a LUA DB fashioned file or similar and published on Google Drive) to enrich the MUD output with data contained in that database (I.E. to show the player enemy immunities every time he faces it)
I looked at Mudlet's documentation, but I haven't found anything related to HTTP requests or files download/upload.
Any suggestion?
Thanks.
Sync with online DB
-
- Posts: 17
- Joined: Wed Aug 22, 2018 1:16 pm
Re: Sync with online DB
Thanks for the advice.
I was experimenting with it but I've just noticed that "downloadFile()" doesn't follow redirects (HTTP 302).
This is a problem with Google Drive, since every download is subject to one or more redirects, and the real download link is not reliable!
Any idea?
Thanks.
I was experimenting with it but I've just noticed that "downloadFile()" doesn't follow redirects (HTTP 302).
This is a problem with Google Drive, since every download is subject to one or more redirects, and the real download link is not reliable!
Any idea?
Thanks.
Re: Sync with online DB
Are you using a recent Mudlet version? I think we enabled it to follow redirects.
-
- Posts: 17
- Joined: Wed Aug 22, 2018 1:16 pm
Re: Sync with online DB
I'm on the latest 3.12.0 version.
I solved this way, even if I don't like it very much:
I solved this way, even if I don't like it very much:
Code: Select all
local handlerId = registerAnonymousEventHandler( "sysDownloadDone",
function(_, filename)
local f, s, result = io.open(filename)
if f then result = f:read("*a"); io.close(f) end
if result:find("The document has moved",1,true) ~= nil then
local redirectUrl = result:match([[The document has moved <A HREF="(.+)">here</A>]])
downloadFile( filename, redirectUrl )
else
killAnonymousEventHandler(handlerId)
end
end,
true
)
-
- Posts: 17
- Joined: Wed Aug 22, 2018 1:16 pm
Re: Sync with online DB
Anything about calling an HTTP service to upload data?
Re: Sync with online DB
With GET and parameters, yep. POST/PUT isn't supported out of the box.
-
- Posts: 17
- Joined: Wed Aug 22, 2018 1:16 pm
-
- Posts: 17
- Joined: Wed Aug 22, 2018 1:16 pm
Re: Sync with online DB
Hi,SoulSpirit wrote: ↑Fri Aug 24, 2018 10:21 amCode: Select all
local handlerId = registerAnonymousEventHandler( "sysDownloadDone", function(_, filename) local f, s, result = io.open(filename) if f then result = f:read("*a"); io.close(f) end if result:find("The document has moved",1,true) ~= nil then local redirectUrl = result:match([[The document has moved <A HREF="(.+)">here</A>]]) downloadFile( filename, redirectUrl ) else killAnonymousEventHandler(handlerId) end end, true )
the workaround I thought I found to follow HTTP 302 redirects isn't reliable and doesn't work very well...
I tried different things, like using the nested downloadFile within a tempTimer or registering a named event handler instead of an anonymous one, but in any case the inner downloadFile isn't executed and no error is generated (even registering a sysDownloadError event).
I'm now running Mudlet 3.13.0.
Any suggestion?
You can use this URL to test redirects:
https://script.google.com/macros/s/AKfy ... eocri/exec
Thanks