do

local makeOurDate = function(dateString)
  local pattern = "(%d+)%-(%d+)%-(%d+)"
  local year, month, day = dateString:match(pattern)
  return day..'.'..month..'.'..year
end

local function get_info(name)
  local url = 'http://myfigurecollection.net/api.php?type=json&mode=collection&username='..name
  local res,code  = http.request(url)
  local data = json:decode(res).collection.owned
  if code ~= 200 then return "HTTP-Fehler" end
  if not data then return "HTTP-Fehler" end
 
  local title = data.item[1].data.name
  local owned = data.num_items
  local user = 'http://de.myfigurecollection.net/collection/'..name
  local art = data.item[1].root.name
  local category = data.item[1].category.name
  local date = makeOurDate(data.item[1].data.release_date)
  local price = '¥'..data.item[1].data.price
  local url = 'http://de.myfigurecollection.net/item/'..data.item[1].data.id
  
  local text = 'Letzter Artikel von '..name.."'s Sammlung ("..owned..' Artikel)\n'..user..'\n\n'..title..'\nArt: '..art..' ('..category..')\nErschien am '..date..' für '..price..'\n'..url
 
    return text
end

local function run(msg, matches)
  local name = matches[1]
  local text = get_info(name)
  local receiver = get_receiver(msg)
  return text
end

return {
  description = "Zeigt den zuletzt hinzugefügten Artikel eines MyFigureCollection Users", 
  usage = "/mfc [Name]",
  patterns = {"^/[Mm][Ff][Cc] (.*)$",
			  "myfigurecollection.net/user/(.*)$",
			  "myfigurecollection.net/collection/(.*)$"
			  },
  run = run 
}

end