Sync with online DB

Jor'Mox
Posts: 1089
Joined: Wed Apr 03, 2013 2:19 am

Re: Sync with online DB

Post by Jor'Mox » Wed Sep 05, 2018 3:27 pm

I recommend putting in some display type statements to help debug your function. Print out the first line of the file, so you can see if it has the text you are looking for. Then print something showing that you made it inside the if statement. Then print out the new URL you are trying to match to see if it looks correct. And then print something after the downloadFile call to make sure it happened.

Granted, you can also simplify that function a bit. Calling string.match with a pattern that doesn't match the text will return nil, so you can just try to match right away, rather than looking to see if you need to get perform a match. So you could make your function look something like this:
Code: [show] | [select all] lua
local handlerId = registerAnonymousEventHandler( "sysDownloadDone",
    function(_, filename)
        print(filename) -- debug
        local f, s, result = io.open(filename)
        if f then result = f:read("*a"); io.close(f) end
        print(result) -- debug
        local redirectUrl = result:match([[The document has moved <A HREF="(.+)">here</A>]])
        print(redirectUrl) -- debug
        if redirectUrl then
            downloadFile( filename, redirectUrl )
            print("Downloading") -- debug
        else
            killAnonymousEventHandler(handlerId)
            print("Done") -- debug
        end
    end,
    true
)
Note that I threw in a ton of debug messages, so you should know if your function gets called, and how far it is able to progress before something fails. Also note that I find using handlerId within the function, before it is declared to be suspicious, as you generally can't do things that way in Lua. Normally, you need to declare the variable first, then use it, but in this case the function is created before the variable is declared (right side goes first, and then is assigned to left side, so the function will reference the global handlerId, which I assume will be nil).

User avatar
keneanung
Site Admin
Posts: 93
Joined: Mon Mar 21, 2011 9:36 am
Discord: keneanung#2803

Re: Sync with online DB

Post by keneanung » Wed Sep 05, 2018 3:37 pm

If you are willing to wait a bit and require a recent Mudlet version, these posts inspired me to look into redirect support inside Mudlet. It looks fairly easy and should be done soon-ish.

User avatar
keneanung
Site Admin
Posts: 93
Joined: Mon Mar 21, 2011 9:36 am
Discord: keneanung#2803

Re: Sync with online DB

Post by keneanung » Thu Sep 06, 2018 10:41 am


SoulSpirit
Posts: 11
Joined: Wed Aug 22, 2018 1:16 pm

Re: Sync with online DB

Post by SoulSpirit » Thu Sep 06, 2018 1:19 pm

keneanung wrote:
Thu Sep 06, 2018 10:41 am
@SoulSpirit

The PR is ready. If you'd like to test this, here are testing builds:
https://transfer.sh/3TVR4/Mudlet-3.13.0 ... pImage.tar Linux
https://transfer.sh/8FKdk/Mudlet-3.13.0 ... e77b9d.dmg macOS
https://ci.appveyor.com/api/buildjobs/8 ... mudlet.zip Windwos
It works!
Hope it will be released soon.

Thank you

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests