mcbot/cmds/shortenurl.lua
changeset 65 2cefbe9f3ac6
parent 64 62248d5fbb24
child 66 d9c00a9fe9d5
equal deleted inserted replaced
64:62248d5fbb24 65:2cefbe9f3ac6
    40     local targeturl = json.encode( { longUrl = url }, encodeoptions )
    40     local targeturl = json.encode( { longUrl = url }, encodeoptions )
    41     local data = shcmd(curlcommand:format(shell_escape(targeturl)))
    41     local data = shcmd(curlcommand:format(shell_escape(targeturl)))
    42     if data then
    42     if data then
    43         local reply = json.decode ( data )
    43         local reply = json.decode ( data )
    44         if ( type ( reply ) == 'table' ) and reply.id then
    44         if ( type ( reply ) == 'table' ) and reply.id then
    45             return ('Full:  %s\nShort: %s'):format(url, reply.id)
    45             return ('Full: %s\nShort: %s'):format(url, reply.id)
    46         else
    46         else
    47             local errmsg
    47             local errmsg
    48             if type ( reply ) == 'table' and ( type ( reply.error ) == 'table' ) then
    48             if type ( reply ) == 'table' and ( type ( reply.error ) == 'table' ) then
    49                 errmsg = ('Failed to shorten url: %u %s'):format(reply.error.code,
    49                 errmsg = ('Failed to shorten url: %u %s'):format(reply.error.code,
    50                           reply.error.message)
    50                           reply.error.message)